2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-01-30 09:39:08 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#ifndef MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_
|
|
|
|
|
#define MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2018-10-23 12:03:01 +02:00
|
|
|
#include <stddef.h>
|
|
|
|
|
#include <stdint.h>
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2016-02-19 07:04:49 -08:00
|
|
|
#include <memory>
|
2011-07-07 08:21:25 +00:00
|
|
|
#include <vector>
|
|
|
|
|
|
2018-10-23 12:03:01 +02:00
|
|
|
#include "absl/types/optional.h"
|
|
|
|
|
#include "api/array_view.h"
|
2019-10-15 10:10:26 +02:00
|
|
|
#include "modules/audio_processing/agc/gain_control.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/constructor_magic.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2014-02-27 22:23:17 +00:00
|
|
|
|
2016-10-28 03:12:11 -07:00
|
|
|
class ApmDataDumper;
|
2011-07-07 08:21:25 +00:00
|
|
|
class AudioBuffer;
|
|
|
|
|
|
2016-03-10 21:09:04 -08:00
|
|
|
class GainControlImpl : public GainControl {
|
2011-07-07 08:21:25 +00:00
|
|
|
public:
|
2019-03-27 13:28:08 +01:00
|
|
|
GainControlImpl();
|
|
|
|
|
GainControlImpl(const GainControlImpl&) = delete;
|
|
|
|
|
GainControlImpl& operator=(const GainControlImpl&) = delete;
|
|
|
|
|
|
2016-03-10 21:09:04 -08:00
|
|
|
~GainControlImpl() override;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-10-25 05:42:20 -07:00
|
|
|
void ProcessRenderAudio(rtc::ArrayView<const int16_t> packed_render_audio);
|
2019-11-22 18:22:04 +01:00
|
|
|
int AnalyzeCaptureAudio(const AudioBuffer& audio);
|
2016-03-15 02:28:08 -07:00
|
|
|
int ProcessCaptureAudio(AudioBuffer* audio, bool stream_has_echo);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-03-15 02:28:08 -07:00
|
|
|
void Initialize(size_t num_proc_channels, int sample_rate_hz);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2019-11-22 18:22:04 +01:00
|
|
|
static void PackRenderAudioBuffer(const AudioBuffer& audio,
|
2016-10-25 05:42:20 -07:00
|
|
|
std::vector<int16_t>* packed_buffer);
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
// GainControl implementation.
|
2015-03-04 12:58:35 +00:00
|
|
|
bool is_enabled() const override;
|
2019-03-27 13:28:08 +01:00
|
|
|
int stream_analog_level() const override;
|
2015-10-03 00:39:14 +02:00
|
|
|
bool is_limiter_enabled() const override;
|
|
|
|
|
Mode mode() const override;
|
2019-11-18 08:52:22 +01:00
|
|
|
int Enable(bool enable) override;
|
|
|
|
|
int set_mode(Mode mode) override;
|
2016-04-28 14:58:32 -07:00
|
|
|
int compression_gain_db() const override;
|
2019-11-18 08:52:22 +01:00
|
|
|
int set_analog_level_limits(int minimum, int maximum) override;
|
|
|
|
|
int set_compression_gain_db(int gain) override;
|
|
|
|
|
int set_target_level_dbfs(int level) override;
|
|
|
|
|
int enable_limiter(bool enable) override;
|
|
|
|
|
int set_stream_analog_level(int level) override;
|
2016-04-28 14:58:32 -07:00
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
private:
|
2016-03-10 21:09:04 -08:00
|
|
|
class GainController;
|
|
|
|
|
|
2011-07-07 08:21:25 +00:00
|
|
|
// GainControl implementation.
|
2015-03-04 12:58:35 +00:00
|
|
|
int target_level_dbfs() const override;
|
|
|
|
|
int analog_level_minimum() const override;
|
|
|
|
|
int analog_level_maximum() const override;
|
|
|
|
|
bool stream_is_saturated() const override;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2019-03-27 13:28:08 +01:00
|
|
|
int Configure();
|
2015-11-28 12:35:15 -08:00
|
|
|
|
2016-10-28 03:12:11 -07:00
|
|
|
std::unique_ptr<ApmDataDumper> data_dumper_;
|
|
|
|
|
|
2016-03-10 21:09:04 -08:00
|
|
|
bool enabled_ = false;
|
|
|
|
|
|
2019-03-27 13:28:08 +01:00
|
|
|
Mode mode_;
|
|
|
|
|
int minimum_capture_level_;
|
|
|
|
|
int maximum_capture_level_;
|
|
|
|
|
bool limiter_enabled_;
|
|
|
|
|
int target_level_dbfs_;
|
|
|
|
|
int compression_gain_db_;
|
|
|
|
|
int analog_capture_level_;
|
|
|
|
|
bool was_analog_level_set_;
|
|
|
|
|
bool stream_is_saturated_;
|
2015-11-28 12:35:15 -08:00
|
|
|
|
2016-03-10 21:09:04 -08:00
|
|
|
std::vector<std::unique_ptr<GainController>> gain_controllers_;
|
|
|
|
|
|
2019-03-27 13:28:08 +01:00
|
|
|
absl::optional<size_t> num_proc_channels_;
|
|
|
|
|
absl::optional<int> sample_rate_hz_;
|
2016-03-15 02:28:08 -07:00
|
|
|
|
2016-10-28 03:12:11 -07:00
|
|
|
static int instance_counter_;
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_AUDIO_PROCESSING_GAIN_CONTROL_IMPL_H_
|