void ConvolverNode::SetBuffer(JSContext* aCx, AudioBuffer* aBuffer, ErrorResult& aRv) { if (aBuffer) { switch (aBuffer->NumberOfChannels()) { case 1: case 2: case 4: // Supported number of channels break; default: aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR); return; } } mBuffer = aBuffer; // Send the buffer to the stream AudioNodeStream* ns = static_cast<AudioNodeStream*>(mStream.get()); MOZ_ASSERT(ns, "Why don't we have a stream here?"); if (mBuffer) { uint32_t length = mBuffer->Length(); nsRefPtr<ThreadSharedFloatArrayBufferList> data = mBuffer->GetThreadSharedChannelsForRate(aCx); if (data && length < WEBAUDIO_BLOCK_SIZE) { // For very small impulse response buffers, we need to pad the // buffer with 0 to make sure that the Reverb implementation // has enough data to compute FFTs from. length = WEBAUDIO_BLOCK_SIZE; nsRefPtr<ThreadSharedFloatArrayBufferList> paddedBuffer = new ThreadSharedFloatArrayBufferList(data->GetChannels()); float* channelData = (float*) malloc(sizeof(float) * length * data->GetChannels()); for (uint32_t i = 0; i < data->GetChannels(); ++i) { PodCopy(channelData + length * i, data->GetData(i), mBuffer->Length()); PodZero(channelData + length * i + mBuffer->Length(), WEBAUDIO_BLOCK_SIZE - mBuffer->Length()); paddedBuffer->SetData(i, (i == 0) ? channelData : nullptr, free, channelData); } data = paddedBuffer; } SendInt32ParameterToStream(ConvolverNodeEngine::BUFFER_LENGTH, length); SendDoubleParameterToStream(ConvolverNodeEngine::SAMPLE_RATE, mBuffer->SampleRate()); ns->SetBuffer(data.forget()); } else { ns->SetBuffer(nullptr); } }
void AudioDestinationNode::Unmute() { MOZ_ASSERT(Context() && !Context()->IsOffline()); SendDoubleParameterToStream(DestinationNodeEngine::VOLUME, 1.0f); }
void AudioBufferSourceNode::SendDopplerShiftToStream(double aDopplerShift) { SendDoubleParameterToStream(DOPPLERSHIFT, aDopplerShift); }
void AudioBufferSourceNode::SendDopplerShiftToStream(double aDopplerShift) { MOZ_ASSERT(mStream, "Should have disconnected panner if no stream"); SendDoubleParameterToStream(DOPPLERSHIFT, aDopplerShift); }