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#include "graph/gain_mixer_node.h"
18
19#include <vector>
20
21#include "base/constants_and_types.h"
22
23
24namespace vraudio {
25
26GainMixerNode::GainMixerNode(const AttenuationType& attenuation_type,
27 const SystemSettings& system_settings,
28 size_t num_channels)
29 : mute_enabled_(false),
30 attenuation_type_(attenuation_type),
31 gain_mixer_(num_channels, system_settings.GetFramesPerBuffer()),
32 system_settings_(system_settings) {}
33
34void GainMixerNode::SetMute(bool mute_enabled) { mute_enabled_ = mute_enabled; }
35
36bool GainMixerNode::CleanUp() {
37 CallCleanUpOnInputNodes();
38 // Prevent node from being disconnected when all sources are removed.
39 return false;
40}
41
42const AudioBuffer* GainMixerNode::AudioProcess(const NodeInput& input) {
43
44
45 if (mute_enabled_) {
46 // Skip processing and output nullptr audio buffer.
47 return nullptr;
48 }
49
50 // Apply the gain to each input buffer channel.
51 gain_mixer_.Reset();
52 for (auto input_buffer : input.GetInputBuffers()) {
53 const auto source_parameters =
54 system_settings_.GetSourceParameters(source_id: input_buffer->source_id());
55 if (source_parameters != nullptr) {
56 const float target_gain =
57 source_parameters->attenuations[attenuation_type_];
58 const size_t num_channels = input_buffer->num_channels();
59 gain_mixer_.AddInput(input: *input_buffer,
60 gains: std::vector<float>(num_channels, target_gain));
61 }
62 }
63 return gain_mixer_.GetOutput();
64}
65
66} // namespace vraudio
67

source code of qtmultimedia/src/3rdparty/resonance-audio/resonance_audio/graph/gain_mixer_node.cc