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 5 #ifndef REMOTING_HOST_AUDIO_VOLUME_FILTER_H_ 6 #define REMOTING_HOST_AUDIO_VOLUME_FILTER_H_ 7 8 #include "remoting/host/audio_silence_detector.h" 9 10 namespace remoting { 11 12 // A component to modify input audio sample to apply the audio level. This class 13 // is used on platforms which returns non-adjusted audio samples, e.g. Windows. 14 // This class supports frames with 16 bits per sample only. 15 class AudioVolumeFilter { 16 public: 17 // See AudioSilenceDetector for the meaning of |silence_threshold|. 18 explicit AudioVolumeFilter(int silence_threshold); 19 virtual ~AudioVolumeFilter(); 20 21 // Adjusts audio samples in |data|. If the samples are silent before applying 22 // the volume level or the GetAudioLevel() returns 0, this function returns 23 // false. If |frames| is 0, this function also returns false. 24 bool Apply(int16_t* data, size_t frames); 25 26 // Updates the sampling rate and channels. 27 void Initialize(int sampling_rate, int channels); 28 29 protected: 30 // Returns the volume level in [0, 1]. This should be a normalized scalar 31 // value: sample values can be simply multiplied by the result of this 32 // function to apply volume. 33 virtual float GetAudioLevel() = 0; 34 35 private: 36 AudioSilenceDetector silence_detector_; 37 }; 38 39 } // namespace remoting 40 41 #endif // REMOTING_HOST_AUDIO_VOLUME_FILTER_H_ 42