mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-13 22:00:47 +01:00

This CL adds functionality that allows adjusting the audio levels internally in APM. The main purpose of the functionality is to allow APM to optionally be moved to an integration that does not provide an analog gain to control, and the implementation of this has been tailored specifically to meet the requirements for that. More specifically, this CL does -Add a new variant of the pre-amplifier gain that is intended to replace the pre-amplifier gain (but at the moment can coexist with that). The main differences with the pre-amplifier gain is that an attenuating gain is allowed, the gain is applied jointly with any emulated analog gain, and that its packaging fits better with the post gain. -Add an emulation of an analog microphone gain. The emulation is designed to match the analog mic gain functionality in Chrome OS (which is digital) but should be usable also on other platforms. -Add a post-gain which is applied after all processing has been applied. The purpose of this gain is for it to work well with the integration in ChromeOS, and be used to compensate for the offset that there is applied on some USB audio devices. Bug: b/177830918 Change-Id: I0f312996e4088c9bd242a713a703eaaeb17f188a Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/209707 Commit-Queue: Per Åhgren <peah@webrtc.org> Reviewed-by: Gustaf Ullberg <gustaf@webrtc.org> Reviewed-by: Alessio Bazzica <alessiob@webrtc.org> Cr-Commit-Position: refs/heads/master@{#33466}
46 lines
1.7 KiB
C++
46 lines
1.7 KiB
C++
/*
|
|
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
#ifndef MODULES_AUDIO_PROCESSING_CAPTURE_LEVELS_ADJUSTER_AUDIO_SAMPLES_SCALER_H_
|
|
#define MODULES_AUDIO_PROCESSING_CAPTURE_LEVELS_ADJUSTER_AUDIO_SAMPLES_SCALER_H_
|
|
|
|
#include <stddef.h>
|
|
|
|
#include "modules/audio_processing/audio_buffer.h"
|
|
|
|
namespace webrtc {
|
|
|
|
// Handles and applies a gain to the samples in an audio buffer.
|
|
// The gain is applied for each sample and any changes in the gain take effect
|
|
// gradually (in a linear manner) over one frame.
|
|
class AudioSamplesScaler {
|
|
public:
|
|
// C-tor. The supplied `initial_gain` is used immediately at the first call to
|
|
// Process(), i.e., in contrast to the gain supplied by SetGain(...) there is
|
|
// no gradual change to the `initial_gain`.
|
|
explicit AudioSamplesScaler(float initial_gain);
|
|
AudioSamplesScaler(const AudioSamplesScaler&) = delete;
|
|
AudioSamplesScaler& operator=(const AudioSamplesScaler&) = delete;
|
|
|
|
// Applies the specified gain to the audio in `audio_buffer`.
|
|
void Process(AudioBuffer& audio_buffer);
|
|
|
|
// Sets the gain to apply to each sample.
|
|
void SetGain(float gain) { target_gain_ = gain; }
|
|
|
|
private:
|
|
float previous_gain_ = 1.f;
|
|
float target_gain_ = 1.f;
|
|
int samples_per_channel_ = -1;
|
|
float one_by_samples_per_channel_ = -1.f;
|
|
};
|
|
} // namespace webrtc
|
|
|
|
#endif // MODULES_AUDIO_PROCESSING_CAPTURE_LEVELS_ADJUSTER_AUDIO_SAMPLES_SCALER_H_
|