1/*
2Copyright 2018 Google Inc. All Rights Reserved.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS-IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17#ifndef RESONANCE_AUDIO_DSP_GAIN_H_
18#define RESONANCE_AUDIO_DSP_GAIN_H_
19
20#include <cstddef>
21#include "base/audio_buffer.h"
22
23namespace vraudio {
24
25// Implements a linearly-interpolated application of gain to a buffer channel.
26//
27// @param ramp_length Length of interpolation ramp in samples. Must be > 0.
28// @param start_gain Starting gain value for ramp.
29// @param end_gain Finishing gain value for ramp.
30// @param input_samples Channel buffer to which interpolated gain is applied.
31// @param output_samples Channel buffer to contain scaled output.
32// @param accumulate_output True if the processed input should be mixed into the
33// output. Otherwise, the output will be replaced by the processed input.
34// @return Next gain value to be applied to the buffer channel.
35float LinearGainRamp(size_t ramp_length, float start_gain, float end_gain,
36 const AudioBuffer::Channel& input_samples,
37 AudioBuffer::Channel* output_samples,
38 bool accumulate_output);
39
40// Applies a gain value to a vector of buffer samples starting at some offset.
41//
42// @param offset_index Starting index for gain application in buffer.
43// @param gain Gain value applied to samples.
44// @param input_samples Channel buffer to which gain is applied.
45// @param output_samples Channel buffer to contain scaled output.
46// @param accumulate_output True if the processed input should be mixed into the
47// output. Otherwise, the output will be replaced by the processed input.
48void ConstantGain(size_t offset_index, float gain,
49 const AudioBuffer::Channel& input_samples,
50 AudioBuffer::Channel* output_samples, bool accumulate_output);
51
52// Checks if the gain factor is close enough to zero (less than -60 decibels).
53//
54// @param gain Gain value to be tested.
55// @return true if the current gain factors are near zero, false otherwise.
56bool IsGainNearZero(float gain);
57
58// Checks if the gain state is close enough to Unity (less than -60 decibels
59// below or above).
60//
61// @param gain Gain value to be tested.
62// @return true if the current gain factors are near unity, false otherwise.
63bool IsGainNearUnity(float gain);
64
65} // namespace vraudio
66
67#endif // RESONANCE_AUDIO_DSP_GAIN_H_
68

source code of qtmultimedia/src/3rdparty/resonance-audio/resonance_audio/dsp/gain.h