| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #include "platform/audio/AudioBus.h" | 29 #include "platform/audio/AudioBus.h" |
| 30 #include "platform/audio/AudioFileReader.h" | 30 #include "platform/audio/AudioFileReader.h" |
| 31 #include "platform/audio/DenormalDisabler.h" | 31 #include "platform/audio/DenormalDisabler.h" |
| 32 #include "platform/audio/SincResampler.h" | 32 #include "platform/audio/SincResampler.h" |
| 33 #include "platform/audio/VectorMath.h" | 33 #include "platform/audio/VectorMath.h" |
| 34 #include "public/platform/Platform.h" | 34 #include "public/platform/Platform.h" |
| 35 #include "public/platform/WebAudioBus.h" | 35 #include "public/platform/WebAudioBus.h" |
| 36 #include "wtf/PtrUtil.h" | 36 #include "wtf/OwnPtr.h" |
| 37 #include <algorithm> | |
| 38 #include <assert.h> | 37 #include <assert.h> |
| 39 #include <math.h> | 38 #include <math.h> |
| 40 #include <memory> | 39 #include <algorithm> |
| 41 | 40 |
| 42 namespace blink { | 41 namespace blink { |
| 43 | 42 |
| 44 using namespace VectorMath; | 43 using namespace VectorMath; |
| 45 | 44 |
| 46 const unsigned MaxBusChannels = 32; | 45 const unsigned MaxBusChannels = 32; |
| 47 | 46 |
| 48 PassRefPtr<AudioBus> AudioBus::create(unsigned numberOfChannels, size_t length,
bool allocate) | 47 PassRefPtr<AudioBus> AudioBus::create(unsigned numberOfChannels, size_t length,
bool allocate) |
| 49 { | 48 { |
| 50 ASSERT(numberOfChannels <= MaxBusChannels); | 49 ASSERT(numberOfChannels <= MaxBusChannels); |
| 51 if (numberOfChannels > MaxBusChannels) | 50 if (numberOfChannels > MaxBusChannels) |
| 52 return nullptr; | 51 return nullptr; |
| 53 | 52 |
| 54 return adoptRef(new AudioBus(numberOfChannels, length, allocate)); | 53 return adoptRef(new AudioBus(numberOfChannels, length, allocate)); |
| 55 } | 54 } |
| 56 | 55 |
| 57 AudioBus::AudioBus(unsigned numberOfChannels, size_t length, bool allocate) | 56 AudioBus::AudioBus(unsigned numberOfChannels, size_t length, bool allocate) |
| 58 : m_length(length) | 57 : m_length(length) |
| 59 , m_busGain(1) | 58 , m_busGain(1) |
| 60 , m_isFirstTime(true) | 59 , m_isFirstTime(true) |
| 61 , m_sampleRate(0) | 60 , m_sampleRate(0) |
| 62 { | 61 { |
| 63 m_channels.reserveInitialCapacity(numberOfChannels); | 62 m_channels.reserveInitialCapacity(numberOfChannels); |
| 64 | 63 |
| 65 for (unsigned i = 0; i < numberOfChannels; ++i) { | 64 for (unsigned i = 0; i < numberOfChannels; ++i) { |
| 66 std::unique_ptr<AudioChannel> channel = allocate ? wrapUnique(new AudioC
hannel(length)) : wrapUnique(new AudioChannel(0, length)); | 65 PassOwnPtr<AudioChannel> channel = allocate ? adoptPtr(new AudioChannel(
length)) : adoptPtr(new AudioChannel(0, length)); |
| 67 m_channels.append(std::move(channel)); | 66 m_channels.append(std::move(channel)); |
| 68 } | 67 } |
| 69 | 68 |
| 70 m_layout = LayoutCanonical; // for now this is the only layout we define | 69 m_layout = LayoutCanonical; // for now this is the only layout we define |
| 71 } | 70 } |
| 72 | 71 |
| 73 void AudioBus::setChannelMemory(unsigned channelIndex, float* storage, size_t le
ngth) | 72 void AudioBus::setChannelMemory(unsigned channelIndex, float* storage, size_t le
ngth) |
| 74 { | 73 { |
| 75 if (channelIndex < m_channels.size()) { | 74 if (channelIndex < m_channels.size()) { |
| 76 channel(channelIndex)->set(storage, length); | 75 channel(channelIndex)->set(storage, length); |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 // FIXME: this value may need tweaking. | 482 // FIXME: this value may need tweaking. |
| 484 const float epsilon = 0.001f; | 483 const float epsilon = 0.001f; |
| 485 float gainDiff = fabs(totalDesiredGain - gain); | 484 float gainDiff = fabs(totalDesiredGain - gain); |
| 486 | 485 |
| 487 // Number of frames to de-zipper before we are close enough to the target ga
in. | 486 // Number of frames to de-zipper before we are close enough to the target ga
in. |
| 488 // FIXME: framesToDezipper could be smaller when target gain is close enough
within this process loop. | 487 // FIXME: framesToDezipper could be smaller when target gain is close enough
within this process loop. |
| 489 unsigned framesToDezipper = (gainDiff < epsilon) ? 0 : framesToProcess; | 488 unsigned framesToDezipper = (gainDiff < epsilon) ? 0 : framesToProcess; |
| 490 | 489 |
| 491 if (framesToDezipper) { | 490 if (framesToDezipper) { |
| 492 if (!m_dezipperGainValues.get() || m_dezipperGainValues->size() < frames
ToDezipper) | 491 if (!m_dezipperGainValues.get() || m_dezipperGainValues->size() < frames
ToDezipper) |
| 493 m_dezipperGainValues = wrapUnique(new AudioFloatArray(framesToDezipp
er)); | 492 m_dezipperGainValues = adoptPtr(new AudioFloatArray(framesToDezipper
)); |
| 494 | 493 |
| 495 float* gainValues = m_dezipperGainValues->data(); | 494 float* gainValues = m_dezipperGainValues->data(); |
| 496 for (unsigned i = 0; i < framesToDezipper; ++i) { | 495 for (unsigned i = 0; i < framesToDezipper; ++i) { |
| 497 gain += (totalDesiredGain - gain) * DezipperRate; | 496 gain += (totalDesiredGain - gain) * DezipperRate; |
| 498 | 497 |
| 499 // FIXME: If we are clever enough in calculating the framesToDezippe
r value, we can probably get | 498 // FIXME: If we are clever enough in calculating the framesToDezippe
r value, we can probably get |
| 500 // rid of this DenormalDisabler::flushDenormalFloatToZero() call. | 499 // rid of this DenormalDisabler::flushDenormalFloatToZero() call. |
| 501 gain = DenormalDisabler::flushDenormalFloatToZero(gain); | 500 gain = DenormalDisabler::flushDenormalFloatToZero(gain); |
| 502 *gainValues++ = gain; | 501 *gainValues++ = gain; |
| 503 } | 502 } |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 706 | 705 |
| 707 // If the bus needs no conversion then return as is. | 706 // If the bus needs no conversion then return as is. |
| 708 if ((!mixToMono || audioBus->numberOfChannels() == 1) && audioBus->sampleRat
e() == sampleRate) | 707 if ((!mixToMono || audioBus->numberOfChannels() == 1) && audioBus->sampleRat
e() == sampleRate) |
| 709 return audioBus; | 708 return audioBus; |
| 710 | 709 |
| 711 return AudioBus::createBySampleRateConverting(audioBus.get(), mixToMono, sam
pleRate); | 710 return AudioBus::createBySampleRateConverting(audioBus.get(), mixToMono, sam
pleRate); |
| 712 } | 711 } |
| 713 | 712 |
| 714 } // namespace blink | 713 } // namespace blink |
| 715 | 714 |
| OLD | NEW |