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
This commit is contained in:
Karl Tomlinson 2015-09-03 19:05:02 +12:00
Родитель 408a08ba14
Коммит 68df460f8c
7 изменённых файлов: 68 добавлений и 39 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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_

Просмотреть файл

@ -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_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)
{

Просмотреть файл

@ -129,12 +129,6 @@ 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.
*/

Просмотреть файл

@ -8,7 +8,7 @@
#include "MediaStreamGraph.h"
#include "mozilla/dom/AudioNodeBinding.h"
#include "AudioSegment.h"
#include "AudioBlock.h"
namespace mozilla {

Просмотреть файл

@ -30,6 +30,7 @@
#include "ReverbConvolverStage.h"
#include <math.h>
#include "AudioBlock.h"
#include "ReverbConvolver.h"
#include "mozilla/FloatingPoint.h"

Просмотреть файл

@ -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',