OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Software adjust volume of samples, allows each audio stream its own | 5 // Software adjust volume of samples, allows each audio stream its own |
6 // volume without impacting master volume for chrome and other applications. | 6 // volume without impacting master volume for chrome and other applications. |
7 | 7 |
8 // Implemented as templates to allow 8, 16 and 32 bit implementations. | 8 // Implemented as templates to allow 8, 16 and 32 bit implementations. |
9 // 8 bit is unsigned and biased by 128. | 9 // 8 bit is unsigned and biased by 128. |
10 | 10 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 } | 197 } |
198 return true; | 198 return true; |
199 } | 199 } |
200 | 200 |
201 default: | 201 default: |
202 break; | 202 break; |
203 } | 203 } |
204 return false; | 204 return false; |
205 } | 205 } |
206 | 206 |
| 207 void InterleaveFloatToInt16(const std::vector<float*>& source, |
| 208 int16* destination, |
| 209 size_t number_of_frames) { |
| 210 const float kScale = 32768.0f; |
| 211 int channels = source.size(); |
| 212 for (int i = 0; i < channels; ++i) { |
| 213 float* channel_data = source[i]; |
| 214 for (size_t j = 0; j < number_of_frames; ++j) { |
| 215 float sample = kScale * channel_data[j]; |
| 216 if (sample < -32768.0) |
| 217 sample = -32768.0; |
| 218 else if (sample > 32767.0) |
| 219 sample = 32767.0; |
| 220 |
| 221 destination[j * channels + i] = static_cast<int16>(sample); |
| 222 } |
| 223 } |
| 224 } |
| 225 |
207 } // namespace media | 226 } // namespace media |
OLD | NEW |