aleloi | 24899e5 | 2017-02-21 05:06:29 -0800 | [diff] [blame] | 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef MODULES_AUDIO_MIXER_FRAME_COMBINER_H_ |
| 12 | #define MODULES_AUDIO_MIXER_FRAME_COMBINER_H_ |
aleloi | 24899e5 | 2017-02-21 05:06:29 -0800 | [diff] [blame] | 13 | |
| 14 | #include <memory> |
| 15 | #include <vector> |
| 16 | |
Olga Sharonova | 0607c96 | 2020-10-19 14:23:46 +0200 | [diff] [blame] | 17 | #include "api/array_view.h" |
Alex Loiko | 8396e34 | 2018-06-21 12:04:05 +0200 | [diff] [blame] | 18 | #include "api/audio/audio_frame.h" |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 19 | #include "modules/audio_processing/agc2/limiter.h" |
aleloi | 24899e5 | 2017-02-21 05:06:29 -0800 | [diff] [blame] | 20 | |
| 21 | namespace webrtc { |
Alex Loiko | 507e8d1 | 2018-02-27 13:51:47 +0100 | [diff] [blame] | 22 | class ApmDataDumper; |
aleloi | 24899e5 | 2017-02-21 05:06:29 -0800 | [diff] [blame] | 23 | |
| 24 | class FrameCombiner { |
| 25 | public: |
Alex Loiko | 507e8d1 | 2018-02-27 13:51:47 +0100 | [diff] [blame] | 26 | enum class LimiterType { kNoLimiter, kApmAgcLimiter, kApmAgc2Limiter }; |
Alex Loiko | 507e8d1 | 2018-02-27 13:51:47 +0100 | [diff] [blame] | 27 | explicit FrameCombiner(bool use_limiter); |
aleloi | 24899e5 | 2017-02-21 05:06:29 -0800 | [diff] [blame] | 28 | ~FrameCombiner(); |
| 29 | |
| 30 | // Combine several frames into one. Assumes sample_rate, |
| 31 | // samples_per_channel of the input frames match the parameters. The |
aleloi | 2c9306e | 2017-03-29 04:25:16 -0700 | [diff] [blame] | 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. |
Olga Sharonova | 0607c96 | 2020-10-19 14:23:46 +0200 | [diff] [blame] | 36 | void Combine(rtc::ArrayView<AudioFrame* const> mix_list, |
aleloi | 24899e5 | 2017-02-21 05:06:29 -0800 | [diff] [blame] | 37 | size_t number_of_channels, |
| 38 | int sample_rate, |
aleloi | 2c9306e | 2017-03-29 04:25:16 -0700 | [diff] [blame] | 39 | size_t number_of_streams, |
Alex Loiko | 507e8d1 | 2018-02-27 13:51:47 +0100 | [diff] [blame] | 40 | AudioFrame* audio_frame_for_mixing); |
aleloi | 24899e5 | 2017-02-21 05:06:29 -0800 | [diff] [blame] | 41 | |
Alex Loiko | b4977de | 2019-01-28 16:38:38 +0100 | [diff] [blame] | 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 | |
aleloi | 24899e5 | 2017-02-21 05:06:29 -0800 | [diff] [blame] | 49 | private: |
Olga Sharonova | 0607c96 | 2020-10-19 14:23:46 +0200 | [diff] [blame] | 50 | void LogMixingStats(rtc::ArrayView<const AudioFrame* const> mix_list, |
Alex Loiko | 6f2fcb4 | 2018-03-14 12:27:05 +0100 | [diff] [blame] | 51 | int sample_rate, |
| 52 | size_t number_of_streams) const; |
| 53 | |
Alex Loiko | 507e8d1 | 2018-02-27 13:51:47 +0100 | [diff] [blame] | 54 | std::unique_ptr<ApmDataDumper> data_dumper_; |
Alex Loiko | b4977de | 2019-01-28 16:38:38 +0100 | [diff] [blame] | 55 | std::unique_ptr<MixingBuffer> mixing_buffer_; |
Alessio Bazzica | 3e4c77f | 2018-11-01 21:31:38 +0100 | [diff] [blame] | 56 | Limiter limiter_; |
Alex Loiko | 8396e34 | 2018-06-21 12:04:05 +0200 | [diff] [blame] | 57 | const bool use_limiter_; |
Alex Loiko | 6f2fcb4 | 2018-03-14 12:27:05 +0100 | [diff] [blame] | 58 | mutable int uma_logging_counter_ = 0; |
aleloi | 24899e5 | 2017-02-21 05:06:29 -0800 | [diff] [blame] | 59 | }; |
| 60 | } // namespace webrtc |
| 61 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 62 | #endif // MODULES_AUDIO_MIXER_FRAME_COMBINER_H_ |