AudioPipeline.cpp 1.5 KB

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