From 68df460f8c50709002b08342d30b436a82b5d2fb Mon Sep 17 00:00:00 2001 From: Karl Tomlinson Date: Thu, 3 Sep 2015 19:05:02 +1200 Subject: [PATCH] bug 1197028 move AllocateAudioBlock to AudioBlock.h r=padenot In a subsequent patch, AllocateAudioBlock will become part of an AudioBlock class derived from AudioChunk and used for AudioNodeStream members. --HG-- extra : rebase_source : a3bfde8345995865c6f8e46abed24f008c112702 --- dom/media/webaudio/AudioBlock.cpp | 43 ++++++++++++++++++++++++++ dom/media/webaudio/AudioBlock.h | 21 +++++++++++++ dom/media/webaudio/AudioNodeEngine.cpp | 32 ------------------- dom/media/webaudio/AudioNodeEngine.h | 6 ---- dom/media/webaudio/AudioNodeStream.h | 2 +- dom/media/webaudio/blink/Reverb.cpp | 1 + dom/media/webaudio/moz.build | 2 ++ 7 files changed, 68 insertions(+), 39 deletions(-) create mode 100644 dom/media/webaudio/AudioBlock.cpp create mode 100644 dom/media/webaudio/AudioBlock.h diff --git a/dom/media/webaudio/AudioBlock.cpp b/dom/media/webaudio/AudioBlock.cpp new file mode 100644 index 000000000000..98a4ca6a5cbf --- /dev/null +++ b/dom/media/webaudio/AudioBlock.cpp @@ -0,0 +1,43 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "AudioBlock.h" + +namespace mozilla { + +void +AllocateAudioBlock(uint32_t aChannelCount, AudioChunk* aChunk) +{ + if (aChunk->mBuffer && !aChunk->mBuffer->IsShared() && + aChunk->ChannelCount() == aChannelCount) { + MOZ_ASSERT(aChunk->mBufferFormat == AUDIO_FORMAT_FLOAT32); + MOZ_ASSERT(aChunk->mDuration == WEBAUDIO_BLOCK_SIZE); + // No need to allocate again. + aChunk->mVolume = 1.0f; + return; + } + + CheckedInt size = WEBAUDIO_BLOCK_SIZE; + size *= aChannelCount; + size *= sizeof(float); + if (!size.isValid()) { + MOZ_CRASH(); + } + // XXX for SIMD purposes we should do something here to make sure the + // channel buffers are 16-byte aligned. + nsRefPtr buffer = SharedBuffer::Create(size.value()); + aChunk->mDuration = WEBAUDIO_BLOCK_SIZE; + aChunk->mChannelData.SetLength(aChannelCount); + float* data = static_cast(buffer->Data()); + for (uint32_t i = 0; i < aChannelCount; ++i) { + aChunk->mChannelData[i] = data + i*WEBAUDIO_BLOCK_SIZE; + } + aChunk->mBuffer = buffer.forget(); + aChunk->mVolume = 1.0f; + aChunk->mBufferFormat = AUDIO_FORMAT_FLOAT32; +} + +} // namespace mozilla diff --git a/dom/media/webaudio/AudioBlock.h b/dom/media/webaudio/AudioBlock.h new file mode 100644 index 000000000000..87c9f9db4e49 --- /dev/null +++ b/dom/media/webaudio/AudioBlock.h @@ -0,0 +1,21 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim:set ts=2 sw=2 sts=2 et cindent: */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifndef MOZILLA_AUDIOBLOCK_H_ +#define MOZILLA_AUDIOBLOCK_H_ + +#include "AudioSegment.h" + +namespace mozilla { + +/** + * Allocates, if necessary, aChannelCount buffers of WEBAUDIO_BLOCK_SIZE float + * samples for writing to an AudioChunk. + */ +void AllocateAudioBlock(uint32_t aChannelCount, AudioChunk* aChunk); + +} // namespace mozilla + +#endif // MOZILLA_AUDIOBLOCK_H_ diff --git a/dom/media/webaudio/AudioNodeEngine.cpp b/dom/media/webaudio/AudioNodeEngine.cpp index 19a33968b2e2..47952bf28884 100644 --- a/dom/media/webaudio/AudioNodeEngine.cpp +++ b/dom/media/webaudio/AudioNodeEngine.cpp @@ -32,38 +32,6 @@ ThreadSharedFloatArrayBufferList::Create(uint32_t aChannelCount, return buffer.forget(); } -void -AllocateAudioBlock(uint32_t aChannelCount, AudioChunk* aChunk) -{ - if (aChunk->mBuffer && !aChunk->mBuffer->IsShared() && - aChunk->ChannelCount() == aChannelCount) { - MOZ_ASSERT(aChunk->mBufferFormat == AUDIO_FORMAT_FLOAT32); - MOZ_ASSERT(aChunk->mDuration == WEBAUDIO_BLOCK_SIZE); - // No need to allocate again. - aChunk->mVolume = 1.0f; - return; - } - - CheckedInt size = WEBAUDIO_BLOCK_SIZE; - size *= aChannelCount; - size *= sizeof(float); - if (!size.isValid()) { - MOZ_CRASH(); - } - // XXX for SIMD purposes we should do something here to make sure the - // channel buffers are 16-byte aligned. - nsRefPtr buffer = SharedBuffer::Create(size.value()); - aChunk->mDuration = WEBAUDIO_BLOCK_SIZE; - aChunk->mChannelData.SetLength(aChannelCount); - float* data = static_cast(buffer->Data()); - for (uint32_t i = 0; i < aChannelCount; ++i) { - aChunk->mChannelData[i] = data + i*WEBAUDIO_BLOCK_SIZE; - } - aChunk->mBuffer = buffer.forget(); - aChunk->mVolume = 1.0f; - aChunk->mBufferFormat = AUDIO_FORMAT_FLOAT32; -} - void WriteZeroesToAudioBlock(AudioChunk* aChunk, uint32_t aStart, uint32_t aLength) { diff --git a/dom/media/webaudio/AudioNodeEngine.h b/dom/media/webaudio/AudioNodeEngine.h index 440c8fdf6492..6dfd0b710f49 100644 --- a/dom/media/webaudio/AudioNodeEngine.h +++ b/dom/media/webaudio/AudioNodeEngine.h @@ -129,12 +129,6 @@ private: nsAutoTArray mContents; }; -/** - * Allocates, if necessary, aChannelCount buffers of WEBAUDIO_BLOCK_SIZE float - * samples for writing to an AudioChunk. - */ -void AllocateAudioBlock(uint32_t aChannelCount, AudioChunk* aChunk); - /** * aChunk must have been allocated by AllocateAudioBlock. */ diff --git a/dom/media/webaudio/AudioNodeStream.h b/dom/media/webaudio/AudioNodeStream.h index 982522c05afe..e9957682e551 100644 --- a/dom/media/webaudio/AudioNodeStream.h +++ b/dom/media/webaudio/AudioNodeStream.h @@ -8,7 +8,7 @@ #include "MediaStreamGraph.h" #include "mozilla/dom/AudioNodeBinding.h" -#include "AudioSegment.h" +#include "AudioBlock.h" namespace mozilla { diff --git a/dom/media/webaudio/blink/Reverb.cpp b/dom/media/webaudio/blink/Reverb.cpp index b78d096f7d0d..a4f380e14d54 100644 --- a/dom/media/webaudio/blink/Reverb.cpp +++ b/dom/media/webaudio/blink/Reverb.cpp @@ -30,6 +30,7 @@ #include "ReverbConvolverStage.h" #include +#include "AudioBlock.h" #include "ReverbConvolver.h" #include "mozilla/FloatingPoint.h" diff --git a/dom/media/webaudio/moz.build b/dom/media/webaudio/moz.build index 0535ea0e8ae9..6e68e681e859 100644 --- a/dom/media/webaudio/moz.build +++ b/dom/media/webaudio/moz.build @@ -20,6 +20,7 @@ MOCHITEST_CHROME_MANIFESTS += ['test/chrome.ini'] EXPORTS += [ 'AlignedTArray.h', + 'AudioBlock.h', 'AudioContext.h', 'AudioEventTimeline.h', 'AudioNodeEngine.h', @@ -67,6 +68,7 @@ EXPORTS.mozilla.dom += [ UNIFIED_SOURCES += [ 'AnalyserNode.cpp', + 'AudioBlock.cpp', 'AudioBuffer.cpp', 'AudioBufferSourceNode.cpp', 'AudioContext.cpp',