2
0

Gain.cpp 685 B

1234567891011121314151617181920212223242526272829
  1. #include "Gain.h"
  2. #include <cmath> // for pow
  3. #include <string> // for string
  4. using namespace bell;
  5. Gain::Gain() : AudioTransform() {
  6. this->gainFactor = 1.0f;
  7. this->filterType = "gain";
  8. }
  9. void Gain::configure(std::vector<int> channels, float gainDB) {
  10. this->channels = channels;
  11. this->gainDb = gainDB;
  12. this->gainFactor = std::pow(10.0f, gainDB / 20.0f);
  13. }
  14. std::unique_ptr<StreamInfo> Gain::process(std::unique_ptr<StreamInfo> data) {
  15. std::scoped_lock lock(this->accessMutex);
  16. for (int i = 0; i < data->numSamples; i++) {
  17. // Apply gain to all channels
  18. for (auto& channel : channels) {
  19. data->data[channel][i] *= gainFactor;
  20. }
  21. }
  22. return data;
  23. }