You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
1.2KB

  1. #include "mixer.hpp"
  2. const float MixerChannel::maxDecibels = 6.0f;
  3. const float MixerChannel::minDecibels = Amplifier::minDecibels;
  4. const float MixerChannel::levelSlewTimeMS = 5.0f;
  5. const float MixerChannel::panSlewTimeMS = 10.0f;
  6. void MixerChannel::setSampleRate(float sampleRate) {
  7. _levelSL.setParams(sampleRate, levelSlewTimeMS, maxDecibels - minDecibels);
  8. _panSL.setParams(sampleRate, panSlewTimeMS, 2.0f);
  9. _rms.setSampleRate(sampleRate);
  10. }
  11. void MixerChannel::next(bool stereo) {
  12. if (!_inInput.active) {
  13. rms = out = left = right = 0.0f;
  14. return;
  15. }
  16. if (_muteParam.value > 0.5f) {
  17. _amplifier.setLevel(_levelSL.next(minDecibels));
  18. }
  19. else {
  20. float level = clamp(_levelParam.value, 0.0f, 1.0f);
  21. if (_levelInput.active) {
  22. level *= clamp(_levelInput.value / 10.0f, 0.0f, 1.0f);
  23. }
  24. level *= maxDecibels - minDecibels;
  25. level += minDecibels;
  26. _amplifier.setLevel(_levelSL.next(level));
  27. }
  28. out = _amplifier.next(_inInput.value);
  29. rms = _rms.next(out / 5.0f);
  30. if (stereo) {
  31. float pan = clamp(_panParam.value, -1.0f, 1.0f);
  32. if (_panInput.active) {
  33. pan *= clamp(_panInput.value / 5.0f, -1.0f, 1.0f);
  34. }
  35. _panner.setPan(_panSL.next(pan));
  36. _panner.next(out, left, right);
  37. }
  38. }