andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 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 | #include "common_audio/include/audio_util.h" |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 12 | |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 13 | namespace webrtc { |
| 14 | |
andrew@webrtc.org | 4fc4add | 2014-10-30 03:40:10 +0000 | [diff] [blame] | 15 | void FloatToS16(const float* src, size_t size, int16_t* dest) { |
kwiberg@webrtc.org | efb81d8 | 2014-07-16 08:36:52 +0000 | [diff] [blame] | 16 | for (size_t i = 0; i < size; ++i) |
andrew@webrtc.org | 4fc4add | 2014-10-30 03:40:10 +0000 | [diff] [blame] | 17 | dest[i] = FloatToS16(src[i]); |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 18 | } |
| 19 | |
andrew@webrtc.org | 4fc4add | 2014-10-30 03:40:10 +0000 | [diff] [blame] | 20 | void S16ToFloat(const int16_t* src, size_t size, float* dest) { |
kwiberg@webrtc.org | efb81d8 | 2014-07-16 08:36:52 +0000 | [diff] [blame] | 21 | for (size_t i = 0; i < size; ++i) |
andrew@webrtc.org | 4fc4add | 2014-10-30 03:40:10 +0000 | [diff] [blame] | 22 | dest[i] = S16ToFloat(src[i]); |
andrew@webrtc.org | 17e4064 | 2014-03-04 20:58:13 +0000 | [diff] [blame] | 23 | } |
| 24 | |
andrew@webrtc.org | 4fc4add | 2014-10-30 03:40:10 +0000 | [diff] [blame] | 25 | void FloatS16ToS16(const float* src, size_t size, int16_t* dest) { |
kwiberg@webrtc.org | efb81d8 | 2014-07-16 08:36:52 +0000 | [diff] [blame] | 26 | for (size_t i = 0; i < size; ++i) |
andrew@webrtc.org | 4fc4add | 2014-10-30 03:40:10 +0000 | [diff] [blame] | 27 | dest[i] = FloatS16ToS16(src[i]); |
| 28 | } |
| 29 | |
| 30 | void FloatToFloatS16(const float* src, size_t size, float* dest) { |
| 31 | for (size_t i = 0; i < size; ++i) |
| 32 | dest[i] = FloatToFloatS16(src[i]); |
| 33 | } |
| 34 | |
| 35 | void FloatS16ToFloat(const float* src, size_t size, float* dest) { |
| 36 | for (size_t i = 0; i < size; ++i) |
| 37 | dest[i] = FloatS16ToFloat(src[i]); |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 40 | template <> |
| 41 | void DownmixInterleavedToMono<int16_t>(const int16_t* interleaved, |
Peter Kasting | dce40cf | 2015-08-24 14:52:23 -0700 | [diff] [blame] | 42 | size_t num_frames, |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 43 | int num_channels, |
| 44 | int16_t* deinterleaved) { |
andrew | 7a1c24f | 2015-07-24 17:10:52 -0700 | [diff] [blame] | 45 | DownmixInterleavedToMonoImpl<int16_t, int32_t>(interleaved, num_frames, |
| 46 | num_channels, deinterleaved); |
Michael Graczyk | 86c6d33 | 2015-07-23 11:41:39 -0700 | [diff] [blame] | 47 | } |
| 48 | |
andrew@webrtc.org | 50b2efe | 2013-04-29 17:27:29 +0000 | [diff] [blame] | 49 | } // namespace webrtc |