blob: a7ffa36ade5c1b669ba11a23de76bb1a76031fb2 [file] [log] [blame]
Alex Loikoa05ee822018-02-20 15:58:36 +01001/*
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_CURVE_APPLIER_H_
12#define MODULES_AUDIO_PROCESSING_AGC2_GAIN_CURVE_APPLIER_H_
13
14#include <vector>
15
16#include "modules/audio_processing/agc2/fixed_digital_level_estimator.h"
17#include "modules/audio_processing/agc2/interpolated_gain_curve.h"
18#include "modules/audio_processing/include/audio_frame_view.h"
19#include "rtc_base/constructormagic.h"
20
21namespace webrtc {
22class ApmDataDumper;
23
24class GainCurveApplier {
25 public:
Alex Loiko03ad9b82018-08-13 17:40:43 +020026 GainCurveApplier(size_t sample_rate_hz,
27 ApmDataDumper* apm_data_dumper,
28 std::string histogram_name_prefix);
Alex Loikoa05ee822018-02-20 15:58:36 +010029
30 ~GainCurveApplier();
31
32 void Process(AudioFrameView<float> signal);
33 InterpolatedGainCurve::Stats GetGainCurveStats() const;
34
35 // Supported rates must be
36 // * supported by FixedDigitalLevelEstimator
37 // * below kMaximalNumberOfSamplesPerChannel*1000/kFrameDurationMs
38 // so that samples_per_channel fit in the
39 // per_sample_scaling_factors_ array.
40 void SetSampleRate(size_t sample_rate_hz);
41
Alessio Bazzica82ec0fa2018-08-27 14:24:16 +020042 // Resets the internal state.
43 void Reset();
44
Alex Loikoa05ee822018-02-20 15:58:36 +010045 private:
46 const InterpolatedGainCurve interp_gain_curve_;
47 FixedDigitalLevelEstimator level_estimator_;
48 ApmDataDumper* const apm_data_dumper_ = nullptr;
49
50 // Work array containing the sub-frame scaling factors to be interpolated.
51 std::array<float, kSubFramesInFrame + 1> scaling_factors_ = {};
52 std::array<float, kMaximalNumberOfSamplesPerChannel>
53 per_sample_scaling_factors_ = {};
54 float last_scaling_factor_ = 1.f;
55
56 RTC_DISALLOW_COPY_AND_ASSIGN(GainCurveApplier);
57};
58
59} // namespace webrtc
60
61#endif // MODULES_AUDIO_PROCESSING_AGC2_GAIN_CURVE_APPLIER_H_