xref: /aosp_15_r20/external/webrtc/modules/audio_mixer/frame_combiner.h (revision d9f758449e529ab9291ac668be2861e7a55c2422)
1 /*
2  *  Copyright (c) 2017 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #ifndef MODULES_AUDIO_MIXER_FRAME_COMBINER_H_
12 #define MODULES_AUDIO_MIXER_FRAME_COMBINER_H_
13 
14 #include <memory>
15 #include <vector>
16 
17 #include "api/array_view.h"
18 #include "api/audio/audio_frame.h"
19 #include "modules/audio_processing/agc2/limiter.h"
20 
21 namespace webrtc {
22 class ApmDataDumper;
23 
24 class FrameCombiner {
25  public:
26   enum class LimiterType { kNoLimiter, kApmAgcLimiter, kApmAgc2Limiter };
27   explicit FrameCombiner(bool use_limiter);
28   ~FrameCombiner();
29 
30   // Combine several frames into one. Assumes sample_rate,
31   // samples_per_channel of the input frames match the parameters. The
32   // parameters 'number_of_channels' and 'sample_rate' are needed
33   // because 'mix_list' can be empty. The parameter
34   // 'number_of_streams' is used for determining whether to pass the
35   // data through a limiter.
36   void Combine(rtc::ArrayView<AudioFrame* const> mix_list,
37                size_t number_of_channels,
38                int sample_rate,
39                size_t number_of_streams,
40                AudioFrame* audio_frame_for_mixing);
41 
42   // Stereo, 48 kHz, 10 ms.
43   static constexpr size_t kMaximumNumberOfChannels = 8;
44   static constexpr size_t kMaximumChannelSize = 48 * 10;
45 
46   using MixingBuffer = std::array<std::array<float, kMaximumChannelSize>,
47                                   kMaximumNumberOfChannels>;
48 
49  private:
50   std::unique_ptr<ApmDataDumper> data_dumper_;
51   std::unique_ptr<MixingBuffer> mixing_buffer_;
52   Limiter limiter_;
53   const bool use_limiter_;
54 };
55 }  // namespace webrtc
56 
57 #endif  // MODULES_AUDIO_MIXER_FRAME_COMBINER_H_
58