Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 58 static const float kMinInt16Inverse = 1.f / limits_int16::min(); | 58 static const float kMinInt16Inverse = 1.f / limits_int16::min(); |
| 59 return v * (v > 0 ? kMaxInt16Inverse : -kMinInt16Inverse); | 59 return v * (v > 0 ? kMaxInt16Inverse : -kMinInt16Inverse); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void FloatToS16(const float* src, size_t size, int16_t* dest); | 62 void FloatToS16(const float* src, size_t size, int16_t* dest); |
| 63 void S16ToFloat(const int16_t* src, size_t size, float* dest); | 63 void S16ToFloat(const int16_t* src, size_t size, float* dest); |
| 64 void FloatS16ToS16(const float* src, size_t size, int16_t* dest); | 64 void FloatS16ToS16(const float* src, size_t size, int16_t* dest); |
| 65 void FloatToFloatS16(const float* src, size_t size, float* dest); | 65 void FloatToFloatS16(const float* src, size_t size, float* dest); |
| 66 void FloatS16ToFloat(const float* src, size_t size, float* dest); | 66 void FloatS16ToFloat(const float* src, size_t size, float* dest); |
| 67 | 67 |
| 68 // Copy audio from |src| channels to |dest| channels. |src| and |dest| must | |
| 69 // have the same number of channels, and there must be sufficient space | |
| 70 // allocated in the |dest| channels. | |
| 71 template <typename T> | |
| 72 void CopyAudio(const T* const* src, | |
|
Andrew MacDonald
2015/08/05 06:18:18
Perhaps call this CopyAudioIfNeeded() and check if
ekm
2015/08/07 06:05:59
Nice. Done.
| |
| 73 int samples_per_channel, | |
|
Andrew MacDonald
2015/08/05 06:18:17
num_frames is the new way.
ekm
2015/08/07 06:05:59
Done.
| |
| 74 int num_channels, | |
| 75 T* const* dest) { | |
| 76 for (int i = 0; i < num_channels; ++i) { | |
| 77 const T* src_channel = src[i]; | |
| 78 T* dest_channel = dest[i]; | |
| 79 for (int j = 0; j < samples_per_channel; ++j) { | |
| 80 dest_channel[j] = src_channel[j]; | |
|
Andrew MacDonald
2015/08/05 06:18:18
Do a memcpy (or std::copy) instead of individual a
ekm
2015/08/07 06:05:59
Done.
| |
| 81 } | |
| 82 } | |
| 83 } | |
| 84 | |
| 68 // Deinterleave audio from |interleaved| to the channel buffers pointed to | 85 // Deinterleave audio from |interleaved| to the channel buffers pointed to |
| 69 // by |deinterleaved|. There must be sufficient space allocated in the | 86 // by |deinterleaved|. There must be sufficient space allocated in the |
| 70 // |deinterleaved| buffers (|num_channel| buffers with |samples_per_channel| | 87 // |deinterleaved| buffers (|num_channel| buffers with |samples_per_channel| |
| 71 // per buffer). | 88 // per buffer). |
| 72 template <typename T> | 89 template <typename T> |
| 73 void Deinterleave(const T* interleaved, | 90 void Deinterleave(const T* interleaved, |
| 74 int samples_per_channel, | 91 int samples_per_channel, |
| 75 int num_channels, | 92 int num_channels, |
| 76 T* const* deinterleaved) { | 93 T* const* deinterleaved) { |
| 77 for (int i = 0; i < num_channels; ++i) { | 94 for (int i = 0; i < num_channels; ++i) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 95 for (int i = 0; i < num_channels; ++i) { | 112 for (int i = 0; i < num_channels; ++i) { |
| 96 const T* channel = deinterleaved[i]; | 113 const T* channel = deinterleaved[i]; |
| 97 int interleaved_idx = i; | 114 int interleaved_idx = i; |
| 98 for (int j = 0; j < samples_per_channel; ++j) { | 115 for (int j = 0; j < samples_per_channel; ++j) { |
| 99 interleaved[interleaved_idx] = channel[j]; | 116 interleaved[interleaved_idx] = channel[j]; |
| 100 interleaved_idx += num_channels; | 117 interleaved_idx += num_channels; |
| 101 } | 118 } |
| 102 } | 119 } |
| 103 } | 120 } |
| 104 | 121 |
| 122 // Copies audio from a single channel buffer pointed to by |mono| to each | |
| 123 // channel of |interleaved|. There must be sufficient space allocated in | |
| 124 // |interleaved| (|samples_per_channel| * |num_channels|). | |
| 125 template <typename T> | |
| 126 void UpmixMonoToInterleaved(const T* mono, | |
| 127 int num_frames, | |
| 128 int num_channels, | |
| 129 T* interleaved) { | |
| 130 int interleaved_idx = 0; | |
| 131 for (int i = 0; i < num_frames; ++i) { | |
| 132 for (int j = 0; j < num_channels; ++j) { | |
| 133 interleaved[interleaved_idx++] = mono[i]; | |
| 134 } | |
| 135 } | |
| 136 } | |
| 137 | |
| 105 template <typename T, typename Intermediate> | 138 template <typename T, typename Intermediate> |
| 106 void DownmixToMono(const T* const* input_channels, | 139 void DownmixToMono(const T* const* input_channels, |
| 107 int num_frames, | 140 int num_frames, |
| 108 int num_channels, | 141 int num_channels, |
| 109 T* out) { | 142 T* out) { |
| 110 for (int i = 0; i < num_frames; ++i) { | 143 for (int i = 0; i < num_frames; ++i) { |
| 111 Intermediate value = input_channels[0][i]; | 144 Intermediate value = input_channels[0][i]; |
| 112 for (int j = 1; j < num_channels; ++j) { | 145 for (int j = 1; j < num_channels; ++j) { |
| 113 value += input_channels[j][i]; | 146 value += input_channels[j][i]; |
| 114 } | 147 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 | 181 |
| 149 template <> | 182 template <> |
| 150 void DownmixInterleavedToMono<int16_t>(const int16_t* interleaved, | 183 void DownmixInterleavedToMono<int16_t>(const int16_t* interleaved, |
| 151 int num_frames, | 184 int num_frames, |
| 152 int num_channels, | 185 int num_channels, |
| 153 int16_t* deinterleaved); | 186 int16_t* deinterleaved); |
| 154 | 187 |
| 155 } // namespace webrtc | 188 } // namespace webrtc |
| 156 | 189 |
| 157 #endif // WEBRTC_COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_ | 190 #endif // WEBRTC_COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_ |
| OLD | NEW |