audio_volume_filter.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef REMOTING_HOST_AUDIO_VOLUME_FILTER_H_
  5. #define REMOTING_HOST_AUDIO_VOLUME_FILTER_H_
  6. #include "remoting/host/audio_silence_detector.h"
  7. namespace remoting {
  8. // A component to modify input audio sample to apply the audio level. This class
  9. // is used on platforms which returns non-adjusted audio samples, e.g. Windows.
  10. // This class supports frames with 16 bits per sample only.
  11. class AudioVolumeFilter {
  12. public:
  13. // See AudioSilenceDetector for the meaning of |silence_threshold|.
  14. explicit AudioVolumeFilter(int silence_threshold);
  15. virtual ~AudioVolumeFilter();
  16. // Adjusts audio samples in |data|. If the samples are silent before applying
  17. // the volume level or the GetAudioLevel() returns 0, this function returns
  18. // false. If |frames| is 0, this function also returns false.
  19. bool Apply(int16_t* data, size_t frames);
  20. // Updates the sampling rate and channels.
  21. void Initialize(int sampling_rate, int channels);
  22. protected:
  23. // Returns the volume level in [0, 1]. This should be a normalized scalar
  24. // value: sample values can be simply multiplied by the result of this
  25. // function to apply volume.
  26. virtual float GetAudioLevel() = 0;
  27. private:
  28. AudioSilenceDetector silence_detector_;
  29. };
  30. } // namespace remoting
  31. #endif // REMOTING_HOST_AUDIO_VOLUME_FILTER_H_