blob: d9aa19d1aa0af2081cd738dfd5f1967c103de02e [file] [log] [blame]
Alex Loiko8a3eadd2018-04-13 11:15:34 +02001/*
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
Yves Gerey988cc082018-10-23 12:03:01 +020014#include <stddef.h>
15
Alex Loiko8a3eadd2018-04-13 11:15:34 +020016#include "modules/audio_processing/include/audio_frame_view.h"
17
18namespace webrtc {
19class GainApplier {
20 public:
21 GainApplier(bool hard_clip_samples, float initial_gain_factor);
22
23 void ApplyGain(AudioFrameView<float> signal);
24 void SetGainFactor(float gain_factor);
Nico Weber22f99252019-02-20 10:13:16 -050025 float GetGainFactor() const { return current_gain_factor_; }
Alex Loiko8a3eadd2018-04-13 11:15:34 +020026
27 private:
28 void Initialize(size_t samples_per_channel);
29
30 // Whether to clip samples after gain is applied. If 'true', result
31 // will fit in FloatS16 range.
32 const bool hard_clip_samples_;
33 float last_gain_factor_;
34
35 // If this value is not equal to 'last_gain_factor', gain will be
36 // ramped from 'last_gain_factor_' to this value during the next
37 // 'ApplyGain'.
38 float current_gain_factor_;
39 int samples_per_channel_ = -1;
40 float inverse_samples_per_channel_ = -1.f;
41};
42} // namespace webrtc
43
44#endif // MODULES_AUDIO_PROCESSING_AGC2_GAIN_APPLIER_H_