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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 // Deinterleave audio from |interleaved| to the channel buffers pointed to | 68 // Deinterleave audio from |interleaved| to the channel buffers pointed to |
69 // by |deinterleaved|. There must be sufficient space allocated in the | 69 // by |deinterleaved|. There must be sufficient space allocated in the |
70 // |deinterleaved| buffers (|num_channel| buffers with |samples_per_channel| | 70 // |deinterleaved| buffers (|num_channel| buffers with |samples_per_channel| |
71 // per buffer). | 71 // per buffer). |
72 template <typename T> | 72 template <typename T> |
73 void Deinterleave(const T* interleaved, | 73 void Deinterleave(const T* interleaved, |
74 int samples_per_channel, | 74 size_t samples_per_channel, |
75 int num_channels, | 75 int num_channels, |
76 T* const* deinterleaved) { | 76 T* const* deinterleaved) { |
77 for (int i = 0; i < num_channels; ++i) { | 77 for (int i = 0; i < num_channels; ++i) { |
78 T* channel = deinterleaved[i]; | 78 T* channel = deinterleaved[i]; |
79 int interleaved_idx = i; | 79 int interleaved_idx = i; |
80 for (int j = 0; j < samples_per_channel; ++j) { | 80 for (size_t j = 0; j < samples_per_channel; ++j) { |
81 channel[j] = interleaved[interleaved_idx]; | 81 channel[j] = interleaved[interleaved_idx]; |
82 interleaved_idx += num_channels; | 82 interleaved_idx += num_channels; |
83 } | 83 } |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 // Interleave audio from the channel buffers pointed to by |deinterleaved| to | 87 // Interleave audio from the channel buffers pointed to by |deinterleaved| to |
88 // |interleaved|. There must be sufficient space allocated in |interleaved| | 88 // |interleaved|. There must be sufficient space allocated in |interleaved| |
89 // (|samples_per_channel| * |num_channels|). | 89 // (|samples_per_channel| * |num_channels|). |
90 template <typename T> | 90 template <typename T> |
91 void Interleave(const T* const* deinterleaved, | 91 void Interleave(const T* const* deinterleaved, |
92 int samples_per_channel, | 92 size_t samples_per_channel, |
93 int num_channels, | 93 int num_channels, |
94 T* interleaved) { | 94 T* interleaved) { |
95 for (int i = 0; i < num_channels; ++i) { | 95 for (int i = 0; i < num_channels; ++i) { |
96 const T* channel = deinterleaved[i]; | 96 const T* channel = deinterleaved[i]; |
97 int interleaved_idx = i; | 97 int interleaved_idx = i; |
98 for (int j = 0; j < samples_per_channel; ++j) { | 98 for (size_t j = 0; j < samples_per_channel; ++j) { |
99 interleaved[interleaved_idx] = channel[j]; | 99 interleaved[interleaved_idx] = channel[j]; |
100 interleaved_idx += num_channels; | 100 interleaved_idx += num_channels; |
101 } | 101 } |
102 } | 102 } |
103 } | 103 } |
104 | 104 |
105 template <typename T, typename Intermediate> | 105 template <typename T, typename Intermediate> |
106 void DownmixToMono(const T* const* input_channels, | 106 void DownmixToMono(const T* const* input_channels, |
107 int num_frames, | 107 size_t num_frames, |
108 int num_channels, | 108 int num_channels, |
109 T* out) { | 109 T* out) { |
110 for (int i = 0; i < num_frames; ++i) { | 110 for (size_t i = 0; i < num_frames; ++i) { |
111 Intermediate value = input_channels[0][i]; | 111 Intermediate value = input_channels[0][i]; |
112 for (int j = 1; j < num_channels; ++j) { | 112 for (int j = 1; j < num_channels; ++j) { |
113 value += input_channels[j][i]; | 113 value += input_channels[j][i]; |
114 } | 114 } |
115 out[i] = value / num_channels; | 115 out[i] = value / num_channels; |
116 } | 116 } |
117 } | 117 } |
118 | 118 |
119 // Downmixes an interleaved multichannel signal to a single channel by averaging | 119 // Downmixes an interleaved multichannel signal to a single channel by averaging |
120 // all channels. | 120 // all channels. |
121 template <typename T, typename Intermediate> | 121 template <typename T, typename Intermediate> |
122 void DownmixInterleavedToMonoImpl(const T* interleaved, | 122 void DownmixInterleavedToMonoImpl(const T* interleaved, |
123 int num_frames, | 123 size_t num_frames, |
124 int num_channels, | 124 int num_channels, |
125 T* deinterleaved) { | 125 T* deinterleaved) { |
126 DCHECK_GT(num_channels, 0); | 126 DCHECK_GT(num_channels, 0); |
127 DCHECK_GT(num_frames, 0); | 127 DCHECK_GT(num_frames, 0u); |
128 | 128 |
129 const T* const end = interleaved + num_frames * num_channels; | 129 const T* const end = interleaved + num_frames * num_channels; |
130 | 130 |
131 while (interleaved < end) { | 131 while (interleaved < end) { |
132 const T* const frame_end = interleaved + num_channels; | 132 const T* const frame_end = interleaved + num_channels; |
133 | 133 |
134 Intermediate value = *interleaved++; | 134 Intermediate value = *interleaved++; |
135 while (interleaved < frame_end) { | 135 while (interleaved < frame_end) { |
136 value += *interleaved++; | 136 value += *interleaved++; |
137 } | 137 } |
138 | 138 |
139 *deinterleaved++ = value / num_channels; | 139 *deinterleaved++ = value / num_channels; |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 template <typename T> | 143 template <typename T> |
144 void DownmixInterleavedToMono(const T* interleaved, | 144 void DownmixInterleavedToMono(const T* interleaved, |
145 int num_frames, | 145 size_t num_frames, |
146 int num_channels, | 146 int num_channels, |
147 T* deinterleaved); | 147 T* deinterleaved); |
148 | 148 |
149 template <> | 149 template <> |
150 void DownmixInterleavedToMono<int16_t>(const int16_t* interleaved, | 150 void DownmixInterleavedToMono<int16_t>(const int16_t* interleaved, |
151 int num_frames, | 151 size_t num_frames, |
152 int num_channels, | 152 int num_channels, |
153 int16_t* deinterleaved); | 153 int16_t* deinterleaved); |
154 | 154 |
155 } // namespace webrtc | 155 } // namespace webrtc |
156 | 156 |
157 #endif // WEBRTC_COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_ | 157 #endif // WEBRTC_COMMON_AUDIO_INCLUDE_AUDIO_UTIL_H_ |
OLD | NEW |