void MediaElementAudioSourceNode::setFormat(size_t numberOfChannels, float sourceSampleRate) { if (numberOfChannels != m_sourceNumberOfChannels || sourceSampleRate != m_sourceSampleRate) { if (!numberOfChannels || numberOfChannels > AudioContext::maxNumberOfChannels() || sourceSampleRate < minSampleRate || sourceSampleRate > maxSampleRate) { // process() will generate silence for these uninitialized values. LOG(Media, "MediaElementAudioSourceNode::setFormat(%u, %f) - unhandled format change", static_cast<unsigned>(numberOfChannels), sourceSampleRate); m_sourceNumberOfChannels = 0; m_sourceSampleRate = 0; return; } m_sourceNumberOfChannels = numberOfChannels; m_sourceSampleRate = sourceSampleRate; // Synchronize with process(). std::lock_guard<MediaElementAudioSourceNode> lock(*this); if (sourceSampleRate != sampleRate()) { double scaleFactor = sourceSampleRate / sampleRate(); m_multiChannelResampler = std::make_unique<MultiChannelResampler>(scaleFactor, numberOfChannels); } else { // Bypass resampling. m_multiChannelResampler = nullptr; } { // The context must be locked when changing the number of output channels. AudioContext::AutoLocker contextLocker(context()); // Do any necesssary re-configuration to the output's number of channels. output(0)->setNumberOfChannels(numberOfChannels); } } }
bool AudioBufferSourceNode::setBuffer(AudioBuffer* buffer) { ASSERT(isMainThread()); // The context must be locked since changing the buffer can re-configure the number of channels that are output. AudioContext::AutoLocker contextLocker(context()); // This synchronizes with process(). MutexLocker processLocker(m_processLock); if (buffer) { // Do any necesssary re-configuration to the buffer's number of channels. unsigned numberOfChannels = buffer->numberOfChannels(); if (numberOfChannels > AudioContext::maxNumberOfChannels()) return false; output(0)->setNumberOfChannels(numberOfChannels); m_sourceChannels = adoptArrayPtr(new const float* [numberOfChannels]); m_destinationChannels = adoptArrayPtr(new float* [numberOfChannels]); for (unsigned i = 0; i < numberOfChannels; ++i) m_sourceChannels[i] = buffer->getChannelData(i)->data(); } m_virtualReadIndex = 0; m_buffer = buffer; return true; }
bool AudioBufferSourceNode::setBuffer(AudioBuffer* buffer) { ASSERT(isMainThread()); // The context must be locked since changing the buffer can re-configure the number of channels that are output. AudioContext::AutoLocker contextLocker(context()); // This synchronizes with process(). MutexLocker processLocker(m_processLock); if (buffer) { // Do any necesssary re-configuration to the buffer's number of channels. unsigned numberOfChannels = buffer->numberOfChannels(); if (!numberOfChannels || numberOfChannels > 2) { // FIXME: implement multi-channel greater than stereo. return false; } output(0)->setNumberOfChannels(numberOfChannels); } m_virtualReadIndex = 0; m_buffer = buffer; return true; }
void AudioBufferSourceNode::setBuffer(AudioBuffer* buffer, ExceptionState& exceptionState) { ASSERT(isMainThread()); // The context must be locked since changing the buffer can re-configure the number of channels that are output. AudioContext::AutoLocker contextLocker(context()); // This synchronizes with process(). MutexLocker processLocker(m_processLock); if (buffer) { // Do any necesssary re-configuration to the buffer's number of channels. unsigned numberOfChannels = buffer->numberOfChannels(); if (numberOfChannels > AudioContext::maxNumberOfChannels()) { exceptionState.throwTypeError("number of input channels (" + String::number(numberOfChannels) + ") exceeds maximum (" + String::number(AudioContext::maxNumberOfChannels()) + ")."); return; } output(0)->setNumberOfChannels(numberOfChannels); m_sourceChannels = adoptArrayPtr(new const float* [numberOfChannels]); m_destinationChannels = adoptArrayPtr(new float* [numberOfChannels]); for (unsigned i = 0; i < numberOfChannels; ++i) m_sourceChannels[i] = buffer->getChannelData(i)->data(); } m_virtualReadIndex = 0; m_buffer = buffer; }
void MediaStreamAudioSourceNode::setFormat(size_t numberOfChannels, float sourceSampleRate) { if (numberOfChannels != m_sourceNumberOfChannels || sourceSampleRate != sampleRate()) { // The sample-rate must be equal to the context's sample-rate. if (!numberOfChannels || numberOfChannels > AudioContext::maxNumberOfChannels() || sourceSampleRate != sampleRate()) { // process() will generate silence for these uninitialized values. LOG(Media, "MediaStreamAudioSourceNode::setFormat(%u, %f) - unhandled format change", static_cast<unsigned>(numberOfChannels), sourceSampleRate); m_sourceNumberOfChannels = 0; return; } // Synchronize with process(). MutexLocker locker(m_processLock); m_sourceNumberOfChannels = numberOfChannels; { // The context must be locked when changing the number of output channels. AudioContext::AutoLocker contextLocker(context()); // Do any necesssary re-configuration to the output's number of channels. output(0)->setNumberOfChannels(numberOfChannels); } } }
void MediaElementAudioSourceHandler::setFormat(size_t numberOfChannels, float sourceSampleRate) { if (numberOfChannels != m_sourceNumberOfChannels || sourceSampleRate != m_sourceSampleRate) { if (!numberOfChannels || numberOfChannels > AudioContext::maxNumberOfChannels() || !AudioUtilities::isValidAudioBufferSampleRate(sourceSampleRate)) { // process() will generate silence for these uninitialized values. WTF_LOG(Media, "MediaElementAudioSourceNode::setFormat(%u, %f) - unhandled format change", static_cast<unsigned>(numberOfChannels), sourceSampleRate); m_sourceNumberOfChannels = 0; m_sourceSampleRate = 0; return; } m_sourceNumberOfChannels = numberOfChannels; m_sourceSampleRate = sourceSampleRate; // Synchronize with process(). Locker<MediaElementAudioSourceHandler> locker(*this); if (sourceSampleRate != sampleRate()) { double scaleFactor = sourceSampleRate / sampleRate(); m_multiChannelResampler = adoptPtr(new MultiChannelResampler(scaleFactor, numberOfChannels)); } else { // Bypass resampling. m_multiChannelResampler.clear(); } { // The context must be locked when changing the number of output channels. AudioContext::AutoLocker contextLocker(context()); // Do any necesssary re-configuration to the output's number of channels. output(0).setNumberOfChannels(numberOfChannels); } } }
void WaveShaperNode::setOversample(OverSampleType type) { ASSERT(isMainThread()); // Synchronize with any graph changes or changes to channel configuration. AudioContext::AutoLocker contextLocker(context()); waveShaperProcessor()->setOversample(processorType(type)); }
void AudioBufferSourceHandler::setBuffer(AudioBuffer* buffer, ExceptionState& exceptionState) { ASSERT(isMainThread()); if (m_buffer) { exceptionState.throwDOMException( InvalidStateError, "Cannot set buffer after it has been already been set"); return; } // The context must be locked since changing the buffer can re-configure the number of channels that are output. AbstractAudioContext::AutoLocker contextLocker(context()); // This synchronizes with process(). MutexLocker processLocker(m_processLock); if (buffer) { // Do any necesssary re-configuration to the buffer's number of channels. unsigned numberOfChannels = buffer->numberOfChannels(); // This should not be possible since AudioBuffers can't be created with too many channels // either. if (numberOfChannels > AbstractAudioContext::maxNumberOfChannels()) { exceptionState.throwDOMException( NotSupportedError, ExceptionMessages::indexOutsideRange( "number of input channels", numberOfChannels, 1u, ExceptionMessages::InclusiveBound, AbstractAudioContext::maxNumberOfChannels(), ExceptionMessages::InclusiveBound)); return; } output(0).setNumberOfChannels(numberOfChannels); m_sourceChannels = wrapArrayUnique(new const float* [numberOfChannels]); m_destinationChannels = wrapArrayUnique(new float* [numberOfChannels]); for (unsigned i = 0; i < numberOfChannels; ++i) m_sourceChannels[i] = buffer->getChannelData(i)->data(); // If this is a grain (as set by a previous call to start()), validate the grain parameters // now since it wasn't validated when start was called (because there was no buffer then). if (m_isGrain) clampGrainParameters(buffer); } m_virtualReadIndex = 0; m_buffer = buffer; }
void WaveShaperNode::setOversample(const String& type, ExceptionCode& ec) { ASSERT(isMainThread()); // This is to synchronize with the changes made in // AudioBasicProcessorNode::checkNumberOfChannelsForInput() where we can // initialize() and uninitialize(). AudioContext::AutoLocker contextLocker(context()); if (type == "none") waveShaperProcessor()->setOversample(WaveShaperProcessor::OverSampleNone); else if (type == "2x") waveShaperProcessor()->setOversample(WaveShaperProcessor::OverSample2x); else if (type == "4x") waveShaperProcessor()->setOversample(WaveShaperProcessor::OverSample4x); else ec = INVALID_STATE_ERR; }
void WaveShaperNode::setOversample(const String& type) { ASSERT(isMainThread()); // This is to synchronize with the changes made in // AudioBasicProcessorNode::checkNumberOfChannelsForInput() where we can // initialize() and uninitialize(). AbstractAudioContext::AutoLocker contextLocker(context()); if (type == "none") { waveShaperProcessor()->setOversample(WaveShaperProcessor::OverSampleNone); } else if (type == "2x") { waveShaperProcessor()->setOversample(WaveShaperProcessor::OverSample2x); } else if (type == "4x") { waveShaperProcessor()->setOversample(WaveShaperProcessor::OverSample4x); } else { ASSERT_NOT_REACHED(); } }
void MediaElementAudioSourceHandler::setFormat(size_t numberOfChannels, float sourceSampleRate) { if (numberOfChannels != m_sourceNumberOfChannels || sourceSampleRate != m_sourceSampleRate) { if (!numberOfChannels || numberOfChannels > BaseAudioContext::maxNumberOfChannels() || !AudioUtilities::isValidAudioBufferSampleRate(sourceSampleRate)) { // process() will generate silence for these uninitialized values. DLOG(ERROR) << "setFormat(" << numberOfChannels << ", " << sourceSampleRate << ") - unhandled format change"; // Synchronize with process(). Locker<MediaElementAudioSourceHandler> locker(*this); m_sourceNumberOfChannels = 0; m_sourceSampleRate = 0; return; } // Synchronize with process() to protect m_sourceNumberOfChannels, // m_sourceSampleRate, and m_multiChannelResampler. Locker<MediaElementAudioSourceHandler> locker(*this); m_sourceNumberOfChannels = numberOfChannels; m_sourceSampleRate = sourceSampleRate; if (sourceSampleRate != sampleRate()) { double scaleFactor = sourceSampleRate / sampleRate(); m_multiChannelResampler = WTF::makeUnique<MultiChannelResampler>(scaleFactor, numberOfChannels); } else { // Bypass resampling. m_multiChannelResampler.reset(); } { // The context must be locked when changing the number of output channels. BaseAudioContext::AutoLocker contextLocker(context()); // Do any necesssary re-configuration to the output's number of channels. output(0).setNumberOfChannels(numberOfChannels); } } }