gain_applier.h (1618B)
1 /* 2 * Copyright (c) 2018 The WebRTC project authors. All Rights Reserved. 3 * 4 * Use of this source code is governed by a BSD-style license 5 * that can be found in the LICENSE file in the root of the source 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #ifndef MODULES_AUDIO_PROCESSING_AGC2_GAIN_APPLIER_H_ 12 #define MODULES_AUDIO_PROCESSING_AGC2_GAIN_APPLIER_H_ 13 14 #include <stddef.h> 15 16 #include "api/audio/audio_view.h" 17 #include "modules/audio_processing/include/audio_frame_view.h" 18 19 namespace webrtc { 20 class GainApplier { 21 public: 22 GainApplier(bool hard_clip_samples, float initial_gain_factor); 23 24 void ApplyGain(DeinterleavedView<float> signal); 25 void SetGainFactor(float gain_factor); 26 float GetGainFactor() const { return current_gain_factor_; } 27 28 [[deprecated("Use DeinterleavedView<> version")]] void ApplyGain( 29 AudioFrameView<float> signal) { 30 ApplyGain(signal.view()); 31 } 32 33 private: 34 void Initialize(int samples_per_channel); 35 36 // Whether to clip samples after gain is applied. If 'true', result 37 // will fit in FloatS16 range. 38 const bool hard_clip_samples_; 39 float last_gain_factor_; 40 41 // If this value is not equal to 'last_gain_factor', gain will be 42 // ramped from 'last_gain_factor_' to this value during the next 43 // 'ApplyGain'. 44 float current_gain_factor_; 45 int samples_per_channel_ = -1; 46 float inverse_samples_per_channel_ = -1.f; 47 }; 48 } // namespace webrtc 49 50 #endif // MODULES_AUDIO_PROCESSING_AGC2_GAIN_APPLIER_H_