diff --git a/dom/media/webaudio/AudioBuffer.cpp b/dom/media/webaudio/AudioBuffer.cpp index d3efa5afdcb3..5bee7c701136 100644 --- a/dom/media/webaudio/AudioBuffer.cpp +++ b/dom/media/webaudio/AudioBuffer.cpp @@ -248,6 +248,23 @@ AudioBuffer::Create(nsPIDOMWindowInner* aWindow, uint32_t aNumberOfChannels, return buffer.forget(); } +/* static */ already_AddRefed +AudioBuffer::Create(nsPIDOMWindowInner* aWindow, float aSampleRate, + AudioChunk&& aInitialContents) +{ + AudioChunk initialContents = aInitialContents; + ErrorResult rv; + RefPtr buffer = + new AudioBuffer(aWindow, initialContents.ChannelCount(), + initialContents.mDuration, aSampleRate, rv); + if (rv.Failed()) { + return nullptr; + } + buffer->mSharedChannels = Move(aInitialContents); + + return buffer.forget(); +} + JSObject* AudioBuffer::WrapObject(JSContext* aCx, JS::Handle aGivenProto) { diff --git a/dom/media/webaudio/AudioBuffer.h b/dom/media/webaudio/AudioBuffer.h index 978c20c1f4c4..a9f65977fc0e 100644 --- a/dom/media/webaudio/AudioBuffer.h +++ b/dom/media/webaudio/AudioBuffer.h @@ -54,6 +54,11 @@ public: nullptr, aRv); } + // Non-unit AudioChunk::mVolume is not supported + static already_AddRefed + Create(nsPIDOMWindowInner* aWindow, float aSampleRate, + AudioChunk&& aInitialContents); + size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(AudioBuffer)