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 "dsp/mixer.h"
18
19#include "base/logging.h"
20
21namespace vraudio {
22
23Mixer::Mixer(size_t target_num_channels, size_t frames_per_buffer)
24 : output_(target_num_channels, frames_per_buffer), is_empty_(false) {
25 Reset();
26}
27
28void Mixer::AddInput(const AudioBuffer& input) {
29 DCHECK_EQ(input.num_frames(), output_.num_frames());
30
31 // Accumulate the input buffers into the output buffer.
32 const size_t num_channels =
33 std::min(a: input.num_channels(), b: output_.num_channels());
34 for (size_t n = 0; n < num_channels; ++n) {
35 if (input[n].IsEnabled()) {
36 output_[n] += input[n];
37 }
38 }
39 is_empty_ = false;
40}
41
42const AudioBuffer* Mixer::GetOutput() const {
43 if (is_empty_) {
44 return nullptr;
45 }
46 return &output_;
47}
48
49void Mixer::Reset() {
50 if (!is_empty_) {
51 output_.Clear();
52 }
53 is_empty_ = true;
54}
55
56} // namespace vraudio
57

source code of qtmultimedia/src/3rdparty/resonance-audio/resonance_audio/dsp/mixer.cc