зеркало из https://github.com/mozilla/gecko-dev.git
bug 1391482 accept int16_t-sample initialization of AudioBuffer r=padenot
MozReview-Commit-ID: 5UaVZYneN2b --HG-- extra : rebase_source : b6a5e28572c44f14a1bcdb13a950e78bb46eda41
This commit is contained in:
Родитель
be26c78f56
Коммит
9a6e4c2741
|
@ -271,6 +271,22 @@ AudioBuffer::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
||||||
return AudioBufferBinding::Wrap(aCx, this, aGivenProto);
|
return AudioBufferBinding::Wrap(aCx, this, aGivenProto);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
CopyChannelDataToFloat(const AudioChunk& aChunk, uint32_t aChannel,
|
||||||
|
uint32_t aSrcOffset, float* aOutput, uint32_t aLength)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(aChunk.mVolume == 1.0f);
|
||||||
|
if (aChunk.mBufferFormat == AUDIO_FORMAT_FLOAT32) {
|
||||||
|
mozilla::PodCopy(aOutput,
|
||||||
|
aChunk.ChannelData<float>()[aChannel] + aSrcOffset,
|
||||||
|
aLength);
|
||||||
|
} else {
|
||||||
|
MOZ_ASSERT(aChunk.mBufferFormat == AUDIO_FORMAT_S16);
|
||||||
|
ConvertAudioSamples(aChunk.ChannelData<int16_t>()[aChannel] + aSrcOffset,
|
||||||
|
aOutput, aLength);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
AudioBuffer::RestoreJSChannelData(JSContext* aJSContext)
|
AudioBuffer::RestoreJSChannelData(JSContext* aJSContext)
|
||||||
{
|
{
|
||||||
|
@ -291,13 +307,11 @@ AudioBuffer::RestoreJSChannelData(JSContext* aJSContext)
|
||||||
if (!mSharedChannels.IsNull()) {
|
if (!mSharedChannels.IsNull()) {
|
||||||
// "4. Attach ArrayBuffers containing copies of the data to the
|
// "4. Attach ArrayBuffers containing copies of the data to the
|
||||||
// AudioBuffer, to be returned by the next call to getChannelData."
|
// AudioBuffer, to be returned by the next call to getChannelData."
|
||||||
MOZ_ASSERT(mSharedChannels.mVolume == 1.0f);
|
|
||||||
const float* data = mSharedChannels.ChannelData<float>()[i];
|
|
||||||
JS::AutoCheckCannotGC nogc;
|
JS::AutoCheckCannotGC nogc;
|
||||||
bool isShared;
|
bool isShared;
|
||||||
mozilla::PodCopy(JS_GetFloat32ArrayData(array, &isShared, nogc),
|
float* jsData = JS_GetFloat32ArrayData(array, &isShared, nogc);
|
||||||
data, Length());
|
|
||||||
MOZ_ASSERT(!isShared); // Was created as unshared above
|
MOZ_ASSERT(!isShared); // Was created as unshared above
|
||||||
|
CopyChannelDataToFloat(mSharedChannels, i, 0, jsData, Length());
|
||||||
}
|
}
|
||||||
mJSChannels[i] = array;
|
mJSChannels[i] = array;
|
||||||
}
|
}
|
||||||
|
@ -325,7 +339,6 @@ AudioBuffer::CopyFromChannel(const Float32Array& aDestination, uint32_t aChannel
|
||||||
|
|
||||||
JS::AutoCheckCannotGC nogc;
|
JS::AutoCheckCannotGC nogc;
|
||||||
JSObject* channelArray = mJSChannels[aChannelNumber];
|
JSObject* channelArray = mJSChannels[aChannelNumber];
|
||||||
const float* sourceData = nullptr;
|
|
||||||
if (channelArray) {
|
if (channelArray) {
|
||||||
if (JS_GetTypedArrayLength(channelArray) != Length()) {
|
if (JS_GetTypedArrayLength(channelArray) != Length()) {
|
||||||
// The array's buffer was detached.
|
// The array's buffer was detached.
|
||||||
|
@ -334,20 +347,22 @@ AudioBuffer::CopyFromChannel(const Float32Array& aDestination, uint32_t aChannel
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isShared = false;
|
bool isShared = false;
|
||||||
sourceData = JS_GetFloat32ArrayData(channelArray, &isShared, nogc);
|
const float* sourceData =
|
||||||
|
JS_GetFloat32ArrayData(channelArray, &isShared, nogc);
|
||||||
// The sourceData arrays should all have originated in
|
// The sourceData arrays should all have originated in
|
||||||
// RestoreJSChannelData, where they are created unshared.
|
// RestoreJSChannelData, where they are created unshared.
|
||||||
MOZ_ASSERT(!isShared);
|
MOZ_ASSERT(!isShared);
|
||||||
} else if (!mSharedChannels.IsNull()) {
|
PodMove(aDestination.Data(), sourceData + aStartInChannel, length);
|
||||||
MOZ_ASSERT(mSharedChannels.mVolume == 1.0f);
|
return;
|
||||||
sourceData = mSharedChannels.ChannelData<float>()[aChannelNumber];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sourceData) {
|
if (!mSharedChannels.IsNull()) {
|
||||||
PodMove(aDestination.Data(), sourceData + aStartInChannel, length);
|
CopyChannelDataToFloat(mSharedChannels, aChannelNumber, aStartInChannel,
|
||||||
} else {
|
aDestination.Data(), length);
|
||||||
PodZero(aDestination.Data(), length);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PodZero(aDestination.Data(), length);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Загрузка…
Ссылка в новой задаче