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

Side by Side Diff: media/base/audio_bus.cc

Issue 2469023002: Support floating-point audio output for Linux (Closed)
Patch Set: Implement correctly Created 4 years, 1 month 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
« media/audio/pulse/pulse_util.cc ('K') | « media/base/audio_bus.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "media/base/audio_bus.h" 5 #include "media/base/audio_bus.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <limits> 10 #include <limits>
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 330
331 void AudioBus::Scale(float volume) { 331 void AudioBus::Scale(float volume) {
332 if (volume > 0 && volume != 1) { 332 if (volume > 0 && volume != 1) {
333 for (int i = 0; i < channels(); ++i) 333 for (int i = 0; i < channels(); ++i)
334 vector_math::FMUL(channel(i), volume, frames(), channel(i)); 334 vector_math::FMUL(channel(i), volume, frames(), channel(i));
335 } else if (volume == 0) { 335 } else if (volume == 0) {
336 Zero(); 336 Zero();
337 } 337 }
338 } 338 }
339 339
340 void AudioBus::Clamp() {
DaleCurtis 2016/11/01 23:07:53 No need IIRC, interleave should take care of this.
Raymond Toy 2016/11/01 23:18:50 You're right. I tested with a webaudio manual test
341 for (int ch = 0; ch < channels(); ++ch) {
342 // Replace NaN with 0 and then clamp the data to [-1, 1].
343 float* channel_data = channel(ch);
344 for (int k = 0; k < frames_; ++k) {
345 float value = channel_data[k];
346 if (value < -1)
347 value = -1;
348 else if (value > 1)
349 value = 1;
350 else if (std::isnan(value))
351 value = 0;
352 channel_data[k] = value;
353 }
354 }
355 }
356
340 void AudioBus::SwapChannels(int a, int b) { 357 void AudioBus::SwapChannels(int a, int b) {
341 DCHECK(a < channels() && a >= 0); 358 DCHECK(a < channels() && a >= 0);
342 DCHECK(b < channels() && b >= 0); 359 DCHECK(b < channels() && b >= 0);
343 DCHECK_NE(a, b); 360 DCHECK_NE(a, b);
344 std::swap(channel_data_[a], channel_data_[b]); 361 std::swap(channel_data_[a], channel_data_[b]);
345 } 362 }
346 363
347 scoped_refptr<AudioBusRefCounted> AudioBusRefCounted::Create( 364 scoped_refptr<AudioBusRefCounted> AudioBusRefCounted::Create(
348 int channels, int frames) { 365 int channels, int frames) {
349 return scoped_refptr<AudioBusRefCounted>( 366 return scoped_refptr<AudioBusRefCounted>(
350 new AudioBusRefCounted(channels, frames)); 367 new AudioBusRefCounted(channels, frames));
351 } 368 }
352 369
353 AudioBusRefCounted::AudioBusRefCounted(int channels, int frames) 370 AudioBusRefCounted::AudioBusRefCounted(int channels, int frames)
354 : AudioBus(channels, frames) {} 371 : AudioBus(channels, frames) {}
355 372
356 AudioBusRefCounted::~AudioBusRefCounted() {} 373 AudioBusRefCounted::~AudioBusRefCounted() {}
357 374
358 } // namespace media 375 } // namespace media
OLDNEW
« media/audio/pulse/pulse_util.cc ('K') | « media/base/audio_bus.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698