| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 | 46 |
| 47 // Factory method: Chromium-implementation | 47 // Factory method: Chromium-implementation |
| 48 PassOwnPtr<AudioDestination> AudioDestination::create(AudioIOCallback& callback,
const String& inputDeviceId, unsigned numberOfInputChannels, unsigned numberOfO
utputChannels, float sampleRate) | 48 PassOwnPtr<AudioDestination> AudioDestination::create(AudioIOCallback& callback,
const String& inputDeviceId, unsigned numberOfInputChannels, unsigned numberOfO
utputChannels, float sampleRate) |
| 49 { | 49 { |
| 50 return adoptPtr(new AudioDestinationChromium(callback, inputDeviceId, number
OfInputChannels, numberOfOutputChannels, sampleRate)); | 50 return adoptPtr(new AudioDestinationChromium(callback, inputDeviceId, number
OfInputChannels, numberOfOutputChannels, sampleRate)); |
| 51 } | 51 } |
| 52 | 52 |
| 53 AudioDestinationChromium::AudioDestinationChromium(AudioIOCallback& callback, co
nst String& inputDeviceId, unsigned numberOfInputChannels, unsigned numberOfOutp
utChannels, float sampleRate) | 53 AudioDestinationChromium::AudioDestinationChromium(AudioIOCallback& callback, co
nst String& inputDeviceId, unsigned numberOfInputChannels, unsigned numberOfOutp
utChannels, float sampleRate) |
| 54 : m_callback(callback) | 54 : m_callback(callback) |
| 55 , m_numberOfOutputChannels(numberOfOutputChannels) | 55 , m_numberOfOutputChannels(numberOfOutputChannels) |
| 56 , m_inputBus(numberOfInputChannels, renderBufferSize) | 56 , m_inputBus(AudioBus::create(numberOfInputChannels, renderBufferSize)) |
| 57 , m_renderBus(numberOfOutputChannels, renderBufferSize, false) | 57 , m_renderBus(AudioBus::create(numberOfOutputChannels, renderBufferSize, fal
se)) |
| 58 , m_sampleRate(sampleRate) | 58 , m_sampleRate(sampleRate) |
| 59 , m_isPlaying(false) | 59 , m_isPlaying(false) |
| 60 { | 60 { |
| 61 // Use the optimal buffer size recommended by the audio backend. | 61 // Use the optimal buffer size recommended by the audio backend. |
| 62 m_callbackBufferSize = WebKit::Platform::current()->audioHardwareBufferSize(
); | 62 m_callbackBufferSize = WebKit::Platform::current()->audioHardwareBufferSize(
); |
| 63 | 63 |
| 64 // Quick exit if the requested size is too large. | 64 // Quick exit if the requested size is too large. |
| 65 ASSERT(m_callbackBufferSize + renderBufferSize <= fifoSize); | 65 ASSERT(m_callbackBufferSize + renderBufferSize <= fifoSize); |
| 66 if (m_callbackBufferSize + renderBufferSize > fifoSize) | 66 if (m_callbackBufferSize + renderBufferSize > fifoSize) |
| 67 return; | 67 return; |
| 68 | 68 |
| 69 m_audioDevice = adoptPtr(WebKit::Platform::current()->createAudioDevice(m_ca
llbackBufferSize, numberOfInputChannels, numberOfOutputChannels, sampleRate, thi
s, inputDeviceId)); | 69 m_audioDevice = adoptPtr(WebKit::Platform::current()->createAudioDevice(m_ca
llbackBufferSize, numberOfInputChannels, numberOfOutputChannels, sampleRate, thi
s, inputDeviceId)); |
| 70 ASSERT(m_audioDevice); | 70 ASSERT(m_audioDevice); |
| 71 | 71 |
| 72 // Create a FIFO to handle the possibility of the callback size | 72 // Create a FIFO to handle the possibility of the callback size |
| 73 // not being a multiple of the render size. If the FIFO already | 73 // not being a multiple of the render size. If the FIFO already |
| 74 // contains enough data, the data will be provided directly. | 74 // contains enough data, the data will be provided directly. |
| 75 // Otherwise, the FIFO will call the provider enough times to | 75 // Otherwise, the FIFO will call the provider enough times to |
| 76 // satisfy the request for data. | 76 // satisfy the request for data. |
| 77 m_fifo = adoptPtr(new AudioPullFIFO(*this, numberOfOutputChannels, fifoSize,
renderBufferSize)); | 77 m_fifo = adoptPtr(new AudioPullFIFO(*this, numberOfOutputChannels, fifoSize,
renderBufferSize)); |
| 78 | 78 |
| 79 // Input buffering. | 79 // Input buffering. |
| 80 m_inputFifo = adoptPtr(new AudioFIFO(numberOfInputChannels, fifoSize)); | 80 m_inputFifo = adoptPtr(new AudioFIFO(numberOfInputChannels, fifoSize)); |
| 81 | 81 |
| 82 // If the callback size does not match the render size, then we need to buff
er some | 82 // If the callback size does not match the render size, then we need to buff
er some |
| 83 // extra silence for the input. Otherwise, we can over-consume the input FIF
O. | 83 // extra silence for the input. Otherwise, we can over-consume the input FIF
O. |
| 84 if (m_callbackBufferSize != renderBufferSize) { | 84 if (m_callbackBufferSize != renderBufferSize) { |
| 85 // FIXME: handle multi-channel input and don't hard-code to stereo. | 85 // FIXME: handle multi-channel input and don't hard-code to stereo. |
| 86 AudioBus silence(2, renderBufferSize); | 86 RefPtr<AudioBus> silence = AudioBus::create(2, renderBufferSize); |
| 87 m_inputFifo->push(&silence); | 87 m_inputFifo->push(silence.get()); |
| 88 } | 88 } |
| 89 } | 89 } |
| 90 | 90 |
| 91 AudioDestinationChromium::~AudioDestinationChromium() | 91 AudioDestinationChromium::~AudioDestinationChromium() |
| 92 { | 92 { |
| 93 stop(); | 93 stop(); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void AudioDestinationChromium::start() | 96 void AudioDestinationChromium::start() |
| 97 { | 97 { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 129 |
| 130 bool isBufferSizeGood = numberOfFrames == m_callbackBufferSize; | 130 bool isBufferSizeGood = numberOfFrames == m_callbackBufferSize; |
| 131 if (!isBufferSizeGood) { | 131 if (!isBufferSizeGood) { |
| 132 ASSERT_NOT_REACHED(); | 132 ASSERT_NOT_REACHED(); |
| 133 return; | 133 return; |
| 134 } | 134 } |
| 135 | 135 |
| 136 // Buffer optional live input. | 136 // Buffer optional live input. |
| 137 if (sourceData.size() >= 2) { | 137 if (sourceData.size() >= 2) { |
| 138 // FIXME: handle multi-channel input and don't hard-code to stereo. | 138 // FIXME: handle multi-channel input and don't hard-code to stereo. |
| 139 AudioBus wrapperBus(2, numberOfFrames, false); | 139 RefPtr<AudioBus> wrapperBus = AudioBus::create(2, numberOfFrames, false)
; |
| 140 wrapperBus.setChannelMemory(0, sourceData[0], numberOfFrames); | 140 wrapperBus->setChannelMemory(0, sourceData[0], numberOfFrames); |
| 141 wrapperBus.setChannelMemory(1, sourceData[1], numberOfFrames); | 141 wrapperBus->setChannelMemory(1, sourceData[1], numberOfFrames); |
| 142 m_inputFifo->push(&wrapperBus); | 142 m_inputFifo->push(wrapperBus.get()); |
| 143 } | 143 } |
| 144 | 144 |
| 145 for (unsigned i = 0; i < m_numberOfOutputChannels; ++i) | 145 for (unsigned i = 0; i < m_numberOfOutputChannels; ++i) |
| 146 m_renderBus.setChannelMemory(i, audioData[i], numberOfFrames); | 146 m_renderBus->setChannelMemory(i, audioData[i], numberOfFrames); |
| 147 | 147 |
| 148 m_fifo->consume(&m_renderBus, numberOfFrames); | 148 m_fifo->consume(m_renderBus.get(), numberOfFrames); |
| 149 } | 149 } |
| 150 | 150 |
| 151 void AudioDestinationChromium::provideInput(AudioBus* bus, size_t framesToProces
s) | 151 void AudioDestinationChromium::provideInput(AudioBus* bus, size_t framesToProces
s) |
| 152 { | 152 { |
| 153 AudioBus* sourceBus = 0; | 153 AudioBus* sourceBus = 0; |
| 154 if (m_inputFifo->framesInFifo() >= framesToProcess) { | 154 if (m_inputFifo->framesInFifo() >= framesToProcess) { |
| 155 m_inputFifo->consume(&m_inputBus, framesToProcess); | 155 m_inputFifo->consume(m_inputBus.get(), framesToProcess); |
| 156 sourceBus = &m_inputBus; | 156 sourceBus = m_inputBus.get(); |
| 157 } | 157 } |
| 158 | 158 |
| 159 m_callback.render(sourceBus, bus, framesToProcess); | 159 m_callback.render(sourceBus, bus, framesToProcess); |
| 160 } | 160 } |
| 161 | 161 |
| 162 } // namespace WebCore | 162 } // namespace WebCore |
| 163 | 163 |
| 164 #endif // ENABLE(WEB_AUDIO) | 164 #endif // ENABLE(WEB_AUDIO) |
| OLD | NEW |