AudioPipeline.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "AudioPipeline.h"
  2. #include <iostream>
  3. #include "BellLogger.h"
  4. using namespace bell;
  5. AudioPipeline::AudioPipeline() {
  6. // this->headroomGainTransform = std::make_shared<Gain>(Channels::LEFT_RIGHT);
  7. // this->transforms.push_back(this->headroomGainTransform);
  8. };
  9. void AudioPipeline::addTransform(std::shared_ptr<AudioTransform> transform) {
  10. transforms.push_back(transform);
  11. recalculateHeadroom();
  12. }
  13. void AudioPipeline::recalculateHeadroom() {
  14. float headroom = 0.0f;
  15. // Find largest headroom required by any transform down the chain, and apply it
  16. for (auto transform : transforms) {
  17. if (headroom < transform->calculateHeadroom()) {
  18. headroom = transform->calculateHeadroom();
  19. }
  20. }
  21. // headroomGainTransform->configure(-headroom);
  22. }
  23. void AudioPipeline::volumeUpdated(int volume) {
  24. BELL_LOG(debug, "AudioPipeline", "Requested");
  25. std::scoped_lock lock(this->accessMutex);
  26. for (auto transform : transforms) {
  27. transform->config->currentVolume = volume;
  28. transform->reconfigure();
  29. }
  30. BELL_LOG(debug, "AudioPipeline", "Volume applied, DSP reconfigured");
  31. }
  32. std::unique_ptr<StreamInfo> AudioPipeline::process(std::unique_ptr<StreamInfo> data) {
  33. std::scoped_lock lock(this->accessMutex);
  34. for (auto &transform : transforms) {
  35. data = transform->process(std::move(data));
  36. }
  37. return data;
  38. }