| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 } | 81 } |
| 82 | 82 |
| 83 // Deinterleave audio from |interleaved| to the channel buffers pointed to | 83 // Deinterleave audio from |interleaved| to the channel buffers pointed to |
| 84 // by |deinterleaved|. There must be sufficient space allocated in the | 84 // by |deinterleaved|. There must be sufficient space allocated in the |
| 85 // |deinterleaved| buffers (|num_channel| buffers with |samples_per_channel| | 85 // |deinterleaved| buffers (|num_channel| buffers with |samples_per_channel| |
| 86 // per buffer). | 86 // per buffer). |
| 87 template <typename T> | 87 template <typename T> |
| 88 void Deinterleave(const T* interleaved, | 88 void Deinterleave(const T* interleaved, |
| 89 int samples_per_channel, | 89 size_t samples_per_channel, |
| 90 int num_channels, | 90 int num_channels, |
| 91 T* const* deinterleaved) { | 91 T* const* deinterleaved) { |
| 92 for (int i = 0; i < num_channels; ++i) { | 92 for (int i = 0; i < num_channels; ++i) { |
| 93 T* channel = deinterleaved[i]; | 93 T* channel = deinterleaved[i]; |
| 94 int interleaved_idx = i; | 94 int interleaved_idx = i; |
| 95 for (int j = 0; j < samples_per_channel; ++j) { | 95 for (size_t j = 0; j < samples_per_channel; ++j) { |
| 96 channel[j] = interleaved[interleaved_idx]; | 96 channel[j] = interleaved[interleaved_idx]; |
| 97 interleaved_idx += num_channels; | 97 interleaved_idx += num_channels; |
| 98 } | 98 } |
| 99 } | 99 } |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Interleave audio from the channel buffers pointed to by |deinterleaved| to | 102 // Interleave audio from the channel buffers pointed to by |deinterleaved| to |
| 103 // |interleaved|. There must be sufficient space allocated in |interleaved| | 103 // |interleaved|. There must be sufficient space allocated in |interleaved| |
| 104 // (|samples_per_channel| * |num_channels|). | 104 // (|samples_per_channel| * |num_channels|). |
| 105 template <typename T> | 105 template <typename T> |
| 106 void Interleave(const T* const* deinterleaved, | 106 void Interleave(const T* const* deinterleaved, |
| 107 int samples_per_channel, | 107 size_t samples_per_channel, |
| 108 int num_channels, | 108 int num_channels, |
| 109 T* interleaved) { | 109 T* interleaved) { |
| 110 for (int i = 0; i < num_channels; ++i) { | 110 for (int i = 0; i < num_channels; ++i) { |
| 111 const T* channel = deinterleaved[i]; | 111 const T* channel = deinterleaved[i]; |
| 112 int interleaved_idx = i; | 112 int interleaved_idx = i; |
| 113 for (int j = 0; j < samples_per_channel; ++j) { | 113 for (size_t j = 0; j < samples_per_channel; ++j) { |
| 114 interleaved[interleaved_idx] = channel[j]; | 114 interleaved[interleaved_idx] = channel[j]; |
| 115 interleaved_idx += num_channels; | 115 interleaved_idx += num_channels; |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| 120 // Copies audio from a single channel buffer pointed to by |mono| to each | 120 // Copies audio from a single channel buffer pointed to by |mono| to each |
| 121 // channel of |interleaved|. There must be sufficient space allocated in | 121 // channel of |interleaved|. There must be sufficient space allocated in |
| 122 // |interleaved| (|samples_per_channel| * |num_channels|). | 122 // |interleaved| (|samples_per_channel| * |num_channels|). |
| 123 template <typename T> | 123 template <typename T> |
| 124 void UpmixMonoToInterleaved(const T* mono, | 124 void UpmixMonoToInterleaved(const T* mono, |
| 125 int num_frames, | 125 int num_frames, |
| 126 int num_channels, | 126 int num_channels, |
| 127 T* interleaved) { | 127 T* interleaved) { |
| 128 int interleaved_idx = 0; | 128 int interleaved_idx = 0; |
| 129 for (int i = 0; i < num_frames; ++i) { | 129 for (int i = 0; i < num_frames; ++i) { |
| 130 for (int j = 0; j < num_channels; ++j) { | 130 for (int j = 0; j < num_channels; ++j) { |
| 131 interleaved[interleaved_idx++] = mono[i]; | 131 interleaved[interleaved_idx++] = mono[i]; |
| 132 } | 132 } |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 | 135 |
| 136 template <typename T, typename Intermediate> | 136 template <typename T, typename Intermediate> |
| 137 void DownmixToMono(const T* const* input_channels, | 137 void DownmixToMono(const T* const* input_channels, |
| 138 int num_frames, | 138 size_t num_frames, |
| 139 int num_channels, | 139 int num_channels, |
| 140 T* out) { | 140 T* out) { |
| 141 for (int i = 0; i < num_frames; ++i) { | 141 for (size_t i = 0; i < num_frames; ++i) { |
| 142 Intermediate value = input_channels[0][i]; | 142 Intermediate value = input_channels[0][i]; |
| 143 for (int j = 1; j < num_channels; ++j) { | 143 for (int j = 1; j < num_channels; ++j) { |
| 144 value += input_channels[j][i]; | 144 value += input_channels[j][i]; |
| 145 } | 145 } |
| 146 out[i] = value / num_channels; | 146 out[i] = value / num_channels; |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 | 149 |
| 150 // Downmixes an interleaved multichannel signal to a single channel by averaging | 150 // Downmixes an interleaved multichannel signal to a single channel by averaging |
| 151 // all channels. | 151 // all channels. |
| 152 template <typename T, typename Intermediate> | 152 template <typename T, typename Intermediate> |
| 153 void DownmixInterleavedToMonoImpl(const T* interleaved, | 153 void DownmixInterleavedToMonoImpl(const T* interleaved, |
| 154 int num_frames, | 154 size_t num_frames, |
| 155 int num_channels, | 155 int num_channels, |
| 156 T* deinterleaved) { | 156 T* deinterleaved) { |
| 157 DCHECK_GT(num_channels, 0); | 157 DCHECK_GT(num_channels, 0); |
| 158 DCHECK_GT(num_frames, 0); | 158 DCHECK_GT(num_frames, 0u); |
| 159 | 159 |
| 160 const T* const end = interleaved + num_frames * num_channels; | 160 const T* const end = interleaved + num_frames * num_channels; |
| 161 | 161 |
| 162 while (interleaved < end) { | 162 while (interleaved < end) { |
| 163 const T* const frame_end = interleaved + num_channels; | 163 const T* const frame_end = interleaved + num_channels; |
| 164 | 164 |
| 165 Intermediate value = *interleaved++; | 165 Intermediate value = *interleaved++; |
| 166 while (interleaved < frame_end) { | 166 while (interleaved < frame_end) { |
| 167 value += *interleaved++; | 167 value += *interleaved++; |
| 168 } | 168 } |
| 169 | 169 |
| 170 *deinterleaved++ = value / num_channels; | 170 *deinterleaved++ = value / num_channels; |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 | 173 |
| 174 template <typename T> | 174 template <typename T> |
| 175 void DownmixInterleavedToMono(const T* interleaved, | 175 void DownmixInterleavedToMono(const T* interleaved, |
| 176 int num_frames, | 176 size_t num_frames, |
| 177 int num_channels, | 177 int num_channels, |
| 178 T* deinterleaved); | 178 T* deinterleaved); |
| 179 | 179 |
| 180 template <> | 180 template <> |
| 181 void DownmixInterleavedToMono<int16_t>(const int16_t* interleaved, | 181 void DownmixInterleavedToMono<int16_t>(const int16_t* interleaved, |
| 182 int num_frames, | 182 size_t num_frames, |
| 183 int num_channels, | 183 int num_channels, |
| 184 int16_t* deinterleaved); | 184 int16_t* deinterleaved); |
| 185 | 185 |
| 186 } // namespace webrtc | 186 } // namespace webrtc |
| 187 | 187 |
| 188 #endif // WEBRTC_COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_ | 188 #endif // WEBRTC_COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_ |
| OLD | NEW |