bug 1197028 move AllocateAudioBlock to AudioBlock.h r=padenot
authorKarl Tomlinson <karlt+@karlt.net>
Thu, 03 Sep 2015 19:05:02 +1200
changeset 261545 61f99bbb1adf650b2d5ca701fcbd5084b1a5d15b
parent 261544 4a6f9f0704858debf78a05f0104e7ad923b832bb
child 261546 6f71147e33e7d128c491257b34304e52fe63bcc6
push id29348
push userkwierso@gmail.com
push dateWed, 09 Sep 2015 20:47:39 +0000
treeherdermozilla-central@dd2a1d737a64 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1197028
milestone43.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
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.
dom/media/webaudio/AudioBlock.cpp
dom/media/webaudio/AudioBlock.h
dom/media/webaudio/AudioNodeEngine.cpp
dom/media/webaudio/AudioNodeEngine.h
dom/media/webaudio/AudioNodeStream.h
dom/media/webaudio/blink/Reverb.cpp
dom/media/webaudio/moz.build
new file mode 100644
--- /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_t> 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<SharedBuffer> buffer = SharedBuffer::Create(size.value());
+  aChunk->mDuration = WEBAUDIO_BLOCK_SIZE;
+  aChunk->mChannelData.SetLength(aChannelCount);
+  float* data = static_cast<float*>(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
new file mode 100644
--- /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_
--- a/dom/media/webaudio/AudioNodeEngine.cpp
+++ b/dom/media/webaudio/AudioNodeEngine.cpp
@@ -28,48 +28,16 @@ ThreadSharedFloatArrayBufferList::Create
 
     buffer->SetData(i, channelData, js_free, channelData);
   }
 
   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_t> 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<SharedBuffer> buffer = SharedBuffer::Create(size.value());
-  aChunk->mDuration = WEBAUDIO_BLOCK_SIZE;
-  aChunk->mChannelData.SetLength(aChannelCount);
-  float* data = static_cast<float*>(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)
 {
   MOZ_ASSERT(aStart + aLength <= WEBAUDIO_BLOCK_SIZE);
   MOZ_ASSERT(!aChunk->IsNull(), "You should pass a non-null chunk");
   if (aLength == 0)
     return;
 
   for (uint32_t i = 0; i < aChunk->mChannelData.Length(); ++i) {
--- a/dom/media/webaudio/AudioNodeEngine.h
+++ b/dom/media/webaudio/AudioNodeEngine.h
@@ -125,22 +125,16 @@ public:
     return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
   }
 
 private:
   nsAutoTArray<Storage, 2> 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.
  */
 void WriteZeroesToAudioBlock(AudioChunk* aChunk, uint32_t aStart, uint32_t aLength);
 
 /**
  * Copy with scale. aScale == 1.0f should be optimized.
  */
 void AudioBufferCopyWithScale(const float* aInput,
--- a/dom/media/webaudio/AudioNodeStream.h
+++ b/dom/media/webaudio/AudioNodeStream.h
@@ -3,17 +3,17 @@
  * 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_AUDIONODESTREAM_H_
 #define MOZILLA_AUDIONODESTREAM_H_
 
 #include "MediaStreamGraph.h"
 #include "mozilla/dom/AudioNodeBinding.h"
-#include "AudioSegment.h"
+#include "AudioBlock.h"
 
 namespace mozilla {
 
 namespace dom {
 struct ThreeDPoint;
 class AudioParamTimeline;
 class AudioContext;
 } // namespace dom
--- a/dom/media/webaudio/blink/Reverb.cpp
+++ b/dom/media/webaudio/blink/Reverb.cpp
@@ -25,16 +25,17 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
 #include "Reverb.h"
 #include "ReverbConvolverStage.h"
 
 #include <math.h>
+#include "AudioBlock.h"
 #include "ReverbConvolver.h"
 #include "mozilla/FloatingPoint.h"
 
 using namespace mozilla;
 
 namespace WebCore {
 
 // Empirical gain calibration tested across many impulse responses to ensure perceived volume is same as dry (unprocessed) signal
--- a/dom/media/webaudio/moz.build
+++ b/dom/media/webaudio/moz.build
@@ -15,16 +15,17 @@ MOCHITEST_MANIFESTS += [
     'test/blink/mochitest.ini',
     'test/mochitest.ini',
 ]
 
 MOCHITEST_CHROME_MANIFESTS += ['test/chrome.ini']
 
 EXPORTS += [
     'AlignedTArray.h',
+    'AudioBlock.h',
     'AudioContext.h',
     'AudioEventTimeline.h',
     'AudioNodeEngine.h',
     'AudioNodeExternalInputStream.h',
     'AudioNodeStream.h',
     'AudioParamTimeline.h',
     'MediaBufferDecoder.h',
     'ThreeDPoint.h',
@@ -62,16 +63,17 @@ EXPORTS.mozilla.dom += [
     'PeriodicWave.h',
     'ScriptProcessorNode.h',
     'StereoPannerNode.h',
     'WaveShaperNode.h',
 ]
 
 UNIFIED_SOURCES += [
     'AnalyserNode.cpp',
+    'AudioBlock.cpp',
     'AudioBuffer.cpp',
     'AudioBufferSourceNode.cpp',
     'AudioContext.cpp',
     'AudioDestinationNode.cpp',
     'AudioListener.cpp',
     'AudioNode.cpp',
     'AudioNodeEngine.cpp',
     'AudioNodeExternalInputStream.cpp',