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|. |
| 28 | // Expects |dst_frame| to have its |num_channels_| and |sample_rate_hz_| set to |
| 29 | // the desired values. Updates |samples_per_channel_| accordingly. |
| 30 | // |
| 31 | // On failure, returns -1 and copies |src_frame| to |dst_frame|. |
| 32 | void RemixAndResample(const AudioFrame& src_frame, |
andrew@webrtc.org | f5a33f1 | 2014-04-19 00:32:07 +0000 | [diff] [blame^] | 33 | PushResampler<int16_t>* resampler, |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 34 | AudioFrame* dst_frame); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 35 | |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 36 | // Downmix and downsample the audio in |src_data| to |dst_af| as necessary, |
| 37 | // specified by |codec_num_channels| and |codec_rate_hz|. |mono_buffer| is |
| 38 | // temporary space and must be of sufficient size to hold the downmixed source |
| 39 | // audio (recommend using a size of kMaxMonoDataSizeSamples). |
| 40 | void DownConvertToCodecFormat(const int16_t* src_data, |
| 41 | int samples_per_channel, |
| 42 | int num_channels, |
| 43 | int sample_rate_hz, |
| 44 | int codec_num_channels, |
| 45 | int codec_rate_hz, |
| 46 | int16_t* mono_buffer, |
andrew@webrtc.org | f5a33f1 | 2014-04-19 00:32:07 +0000 | [diff] [blame^] | 47 | PushResampler<int16_t>* resampler, |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 48 | AudioFrame* dst_af); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 49 | |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 50 | void MixWithSat(int16_t target[], |
| 51 | int target_channel, |
| 52 | const int16_t source[], |
| 53 | int source_channel, |
| 54 | int source_len); |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 55 | |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 56 | } // namespace voe |
pbos@webrtc.org | d900e8b | 2013-07-03 15:12:26 +0000 | [diff] [blame] | 57 | } // namespace webrtc |
niklase@google.com | 470e71d | 2011-07-07 08:21:25 +0000 | [diff] [blame] | 58 | |
andrew@webrtc.org | 40ee3d0 | 2014-04-03 21:56:01 +0000 | [diff] [blame] | 59 | #endif // WEBRTC_VOICE_ENGINE_UTILITY_H_ |