void OscillatorNode::Start(double aWhen, ErrorResult& aRv) { if (!WebAudioUtils::IsTimeValid(aWhen)) { aRv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR); return; } if (mStartCalled) { aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return; } mStartCalled = true; if (!mStream) { // Nothing to play, or we're already dead for some reason return; } // TODO: Perhaps we need to do more here. mStream->SetStreamTimeParameter(OscillatorNodeEngine::START, Context(), aWhen); MarkActive(); }
void AudioBufferSourceNode::SendOffsetAndDurationParametersToStream(AudioNodeStream* aStream) { NS_ASSERTION(mBuffer && mStartCalled, "Only call this when we have a buffer and start() has been called"); float rate = mBuffer->SampleRate(); aStream->SetInt32Parameter(SAMPLE_RATE, rate); int32_t bufferEnd = mBuffer->Length(); int32_t offsetSamples = std::max(0, NS_lround(mOffset * rate)); // Don't set parameter unnecessarily if (offsetSamples > 0) { aStream->SetInt32Parameter(BUFFERSTART, offsetSamples); } if (mDuration != std::numeric_limits<double>::min()) { MOZ_ASSERT(mDuration >= 0.0); // provided by Start() MOZ_ASSERT(rate >= 0.0f); // provided by AudioBuffer::Create() static_assert(std::numeric_limits<double>::digits >= std::numeric_limits<decltype(bufferEnd)>::digits, "bufferEnd should be represented exactly by double"); // + 0.5 rounds mDuration to nearest sample when assigned to bufferEnd. bufferEnd = std::min<double>(bufferEnd, offsetSamples + mDuration * rate + 0.5); } aStream->SetInt32Parameter(BUFFEREND, bufferEnd); MarkActive(); }
void ScriptProcessorNode::UpdateConnectedStatus() { bool isConnected = mHasPhantomInput || !(OutputNodes().IsEmpty() && OutputParams().IsEmpty() && InputNodes().IsEmpty()); // Events are queued even when there is no listener because a listener // may be added while events are in the queue. SendInt32ParameterToStream(ScriptProcessorNodeEngine::IS_CONNECTED, isConnected); if (isConnected && HasListenersFor(nsGkAtoms::onaudioprocess)) { MarkActive(); } else { MarkInactive(); } }
void AudioBufferSourceNode::SendOffsetAndDurationParametersToStream(AudioNodeStream* aStream) { NS_ASSERTION(mBuffer && mStartCalled, "Only call this when we have a buffer and start() has been called"); float rate = mBuffer->SampleRate(); int32_t bufferEnd = mBuffer->Length(); int32_t offsetSamples = std::max(0, NS_lround(mOffset * rate)); // Don't set parameter unnecessarily if (offsetSamples > 0) { aStream->SetInt32Parameter(BUFFERSTART, offsetSamples); } if (mDuration != std::numeric_limits<double>::min()) { bufferEnd = std::min(bufferEnd, offsetSamples + NS_lround(mDuration * rate)); } aStream->SetInt32Parameter(BUFFEREND, bufferEnd); MarkActive(); }