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

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 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 reinterpret_cast<int32*>(buf), 170 reinterpret_cast<int32*>(buf),
171 sample_count, 171 sample_count,
172 volume, 172 volume,
173 channels); 173 channels);
174 return true; 174 return true;
175 } 175 }
176 } 176 }
177 return false; 177 return false;
178 } 178 }
179 179
180 // TODO(dalecurtis): Delete once everywhere is using the AudioBus version:
181 // http://crbug.com/120319.
182 bool DeinterleaveAudioChannel(void* source,
183 float* destination,
184 int channels,
185 int channel_index,
186 int bytes_per_sample,
187 size_t number_of_frames) {
188 switch (bytes_per_sample) {
189 case 1:
190 {
191 uint8* source8 = reinterpret_cast<uint8*>(source) + channel_index;
192 const float kScale = 1.0f / 128.0f;
193 for (unsigned i = 0; i < number_of_frames; ++i) {
194 destination[i] = kScale * (static_cast<int>(*source8) - 128);
195 source8 += channels;
196 }
197 return true;
198 }
199
200 case 2:
201 {
202 int16* source16 = reinterpret_cast<int16*>(source) + channel_index;
203 const float kScale = 1.0f / 32768.0f;
204 for (unsigned i = 0; i < number_of_frames; ++i) {
205 destination[i] = kScale * *source16;
206 source16 += channels;
207 }
208 return true;
209 }
210
211 case 4:
212 {
213 int32* source32 = reinterpret_cast<int32*>(source) + channel_index;
214 const float kScale = 1.0f / 2147483648.0f;
215 for (unsigned i = 0; i < number_of_frames; ++i) {
216 destination[i] = kScale * *source32;
217 source32 += channels;
218 }
219 return true;
220 }
221
222 default:
223 break;
224 }
225 return false;
226 }
227
228 // TODO(enal): use template specialization and size-specific intrinsics. 180 // TODO(enal): use template specialization and size-specific intrinsics.
229 // Call is on the time-critical path, and by using SSE/AVX 181 // Call is on the time-critical path, and by using SSE/AVX
230 // instructions we can speed things up by ~4-8x, more for the case 182 // instructions we can speed things up by ~4-8x, more for the case
231 // when we have to adjust volume as well. 183 // when we have to adjust volume as well.
232 template<class Format, class Fixed, int min_value, int max_value, int bias> 184 template<class Format, class Fixed, int min_value, int max_value, int bias>
233 static void MixStreams(Format* dst, Format* src, int count, float volume) { 185 static void MixStreams(Format* dst, Format* src, int count, float volume) {
234 if (volume == 0.0f) 186 if (volume == 0.0f)
235 return; 187 return;
236 if (volume == 1.0f) { 188 if (volume == 1.0f) {
237 // Most common case -- no need to adjust volume. 189 // Most common case -- no need to adjust volume.
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 // out performance was degraded compared to XP. 398 // out performance was degraded compared to XP.
447 // - The regression was fixed in Windows 7 and most configurations will work 399 // - The regression was fixed in Windows 7 and most configurations will work
448 // with 2, but some (e.g., some Sound Blasters) still need 3. 400 // with 2, but some (e.g., some Sound Blasters) still need 3.
449 // - Some XP configurations (even multi-processor ones) also need 3. 401 // - Some XP configurations (even multi-processor ones) also need 3.
450 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3; 402 return (base::win::GetVersion() == base::win::VERSION_VISTA) ? 4 : 3;
451 } 403 }
452 404
453 #endif 405 #endif
454 406
455 } // namespace media 407 } // 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