Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: media/audio/audio_util.cc

Issue 10871051: Convert WebAudio file handlers to use AudioBus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Comments. Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 reinterpret_cast<int32*>(buf), 175 reinterpret_cast<int32*>(buf),
176 sample_count, 176 sample_count,
177 volume, 177 volume,
178 channels); 178 channels);
179 return true; 179 return true;
180 } 180 }
181 } 181 }
182 return false; 182 return false;
183 } 183 }
184 184
185 // TODO(dalecurtis): Delete once everywhere is using the AudioBus version:
186 // http://crbug.com/120319.
187 bool DeinterleaveAudioChannel(void* source,
188 float* destination,
189 int channels,
190 int channel_index,
191 int bytes_per_sample,
192 size_t number_of_frames) {
193 switch (bytes_per_sample) {
194 case 1:
195 {
196 uint8* source8 = reinterpret_cast<uint8*>(source) + channel_index;
197 const float kScale = 1.0f / 128.0f;
198 for (unsigned i = 0; i < number_of_frames; ++i) {
199 destination[i] = kScale * (static_cast<int>(*source8) - 128);
200 source8 += channels;
201 }
202 return true;
203 }
204
205 case 2:
206 {
207 int16* source16 = reinterpret_cast<int16*>(source) + channel_index;
208 const float kScale = 1.0f / 32768.0f;
209 for (unsigned i = 0; i < number_of_frames; ++i) {
210 destination[i] = kScale * *source16;
211 source16 += channels;
212 }
213 return true;
214 }
215
216 case 4:
217 {
218 int32* source32 = reinterpret_cast<int32*>(source) + channel_index;
219 const float kScale = 1.0f / 2147483648.0f;
220 for (unsigned i = 0; i < number_of_frames; ++i) {
221 destination[i] = kScale * *source32;
222 source32 += channels;
223 }
224 return true;
225 }
226
227 default:
228 break;
229 }
230 return false;
231 }
232
233 // TODO(enal): use template specialization and size-specific intrinsics. 185 // TODO(enal): use template specialization and size-specific intrinsics.
234 // Call is on the time-critical path, and by using SSE/AVX 186 // Call is on the time-critical path, and by using SSE/AVX
235 // instructions we can speed things up by ~4-8x, more for the case 187 // instructions we can speed things up by ~4-8x, more for the case
236 // when we have to adjust volume as well. 188 // when we have to adjust volume as well.
237 template<class Format, class Fixed, int min_value, int max_value, int bias> 189 template<class Format, class Fixed, int min_value, int max_value, int bias>
238 static void MixStreams(Format* dst, Format* src, int count, float volume) { 190 static void MixStreams(Format* dst, Format* src, int count, float volume) {
239 if (volume == 0.0f) 191 if (volume == 0.0f)
240 return; 192 return;
241 if (volume == 1.0f) { 193 if (volume == 1.0f) {
242 // Most common case -- no need to adjust volume. 194 // Most common case -- no need to adjust volume.
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
501 // out performance was degraded compared to XP. 453 // out performance was degraded compared to XP.
502 // - The regression was fixed in Windows 7 and most configurations will work 454 // - The regression was fixed in Windows 7 and most configurations will work
503 // with 2, but some (e.g., some Sound Blasters) still need 3. 455 // with 2, but some (e.g., some Sound Blasters) still need 3.
504 // - Some XP configurations (even multi-processor ones) also need 3. 456 // - Some XP configurations (even multi-processor ones) also need 3.
505 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3; 457 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3;
506 } 458 }
507 459
508 #endif 460 #endif
509 461
510 } // namespace media 462 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_util.h ('k') | media/base/audio_bus.h » ('j') | media/base/audio_bus.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698