OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "webkit/media/audio_decoder.h" | 5 #include "webkit/media/audio_decoder.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <limits.h> | 9 #include <limits.h> |
10 #include <sys/mman.h> | 10 #include <sys/mman.h> |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 // Convert the samples and save them in the audio bus. | 173 // Convert the samples and save them in the audio bus. |
174 size_t number_of_samples = decoded_samples.size(); | 174 size_t number_of_samples = decoded_samples.size(); |
175 size_t number_of_frames = number_of_samples / number_of_channels; | 175 size_t number_of_frames = number_of_samples / number_of_channels; |
176 | 176 |
177 destination_bus->initialize(number_of_channels, | 177 destination_bus->initialize(number_of_channels, |
178 number_of_frames, | 178 number_of_frames, |
179 file_sample_rate); | 179 file_sample_rate); |
180 | 180 |
181 size_t decoded_frames = 0; | 181 size_t decoded_frames = 0; |
182 const float kMaxScale = 1.0f / std::numeric_limits<int16_t>::max(); | 182 const float kMaxScale = 1.0f / std::numeric_limits<int16_t>::max(); |
183 const float kMinScale = 1.0f / std::numeric_limits<int16_t>::min(); | 183 const float kMinScale = -1.0f / std::numeric_limits<int16_t>::min(); |
184 | 184 |
185 for (size_t m = 0; m < number_of_samples; m += number_of_channels) { | 185 for (size_t m = 0; m < number_of_samples; m += number_of_channels) { |
186 for (size_t k = 0; k < number_of_channels; ++k) { | 186 for (size_t k = 0; k < number_of_channels; ++k) { |
187 int16_t sample = decoded_samples[m + k]; | 187 int16_t sample = decoded_samples[m + k]; |
188 destination_bus->channelData(k)[decoded_frames] = | 188 destination_bus->channelData(k)[decoded_frames] = |
189 sample * (sample < 0 ? kMinScale : kMaxScale); | 189 sample * (sample < 0 ? kMinScale : kMaxScale); |
190 } | 190 } |
191 ++decoded_frames; | 191 ++decoded_frames; |
192 } | 192 } |
193 | 193 |
194 return true; | 194 return true; |
195 } | 195 } |
196 | 196 |
197 } // namespace webkit_media | 197 } // namespace webkit_media |
OLD | NEW |