niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 1 | /* |
braveyao@webrtc.org | d713143 | 2012-03-29 10:39:44 +0000 | [diff] [blame] | 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 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 | /* |
| 12 | * Contains functions often used by different parts of VoiceEngine. |
| 13 | */ |
| 14 | |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 15 | #ifndef WEBRTC_VOICE_ENGINE_UTILITY_H_ |
| 16 | #define WEBRTC_VOICE_ENGINE_UTILITY_H_ |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 17 | |
andrew@webrtc.org | f5a33f1 | 2014-04-19 00:32:07 +0000 | [diff] [blame] | 18 | #include "webrtc/common_audio/resampler/include/push_resampler.h" |
pbos@webrtc.org | 956aa7e | 2013-05-21 13:52:32 +0000 | [diff] [blame] | 19 | #include "webrtc/typedefs.h" |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 20 | |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 21 | namespace webrtc { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 22 | |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 23 | class AudioFrame; |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 24 | |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 25 | namespace voe { |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 26 | |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 27 | // Upmix or downmix and resample the audio in |src_frame| to |dst_frame|. |
andrew@webrtc.org | 1fddd61 | 2014-05-30 17:28:50 +0000 | [diff] [blame] | 28 | // Expects |dst_frame| to have its sample rate and channels members set to the |
| 29 | // desired values. Updates the samples per channel member accordingly. No other |
| 30 | // members will be changed. |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 31 | void RemixAndResample(const AudioFrame& src_frame, |
andrew@webrtc.org | f5a33f1 | 2014-04-19 00:32:07 +0000 | [diff] [blame] | 32 | PushResampler<int16_t>* resampler, |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 33 | AudioFrame* dst_frame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 34 | |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 35 | // Downmix and downsample the audio in |src_data| to |dst_af| as necessary, |
| 36 | // specified by |codec_num_channels| and |codec_rate_hz|. |mono_buffer| is |
| 37 | // temporary space and must be of sufficient size to hold the downmixed source |
| 38 | // audio (recommend using a size of kMaxMonoDataSizeSamples). |
andrew@webrtc.org | 1fddd61 | 2014-05-30 17:28:50 +0000 | [diff] [blame] | 39 | // |
| 40 | // |dst_af| will have its data and format members (sample rate, channels and |
| 41 | // samples per channel) set appropriately. No other members will be changed. |
| 42 | // TODO(ajm): For now, this still calls Reset() on |dst_af|. Remove this, as |
| 43 | // it shouldn't be needed. |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 44 | void DownConvertToCodecFormat(const int16_t* src_data, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame^] | 45 | size_t samples_per_channel, |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 46 | int num_channels, |
| 47 | int sample_rate_hz, |
| 48 | int codec_num_channels, |
| 49 | int codec_rate_hz, |
| 50 | int16_t* mono_buffer, |
andrew@webrtc.org | f5a33f1 | 2014-04-19 00:32:07 +0000 | [diff] [blame] | 51 | PushResampler<int16_t>* resampler, |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 52 | AudioFrame* dst_af); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 53 | |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 54 | void MixWithSat(int16_t target[], |
| 55 | int target_channel, |
| 56 | const int16_t source[], |
| 57 | int source_channel, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame^] | 58 | size_t source_len); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 59 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 60 | } // namespace voe |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 61 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 62 | |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 63 | #endif // WEBRTC_VOICE_ENGINE_UTILITY_H_ |