Files
palemoon27/dom/media/webaudio/AudioNodeEngine.cpp
T
roytam1 22d3be643b import changes from `dev' branch of rmottola/Arctic-Fox:
- fix mac build (11ff07d07d)
- Merge branch 'dev' of https://github.com/rmottola/Arctic-Fox into dev (b1d5bda99a)
- Bug 1171682 - Disable WebGL in safemode. r=jgilbert (4b388af71d)
- Bug 1212724 - Fix compile error in non-unified mode. r=nical (a089c1d600)
- bug 1210266 remove unused AudioNode::Callback() r=padenot (7cf3b8ac8d)
- bug 1210266 unfriend AudioBufferSourceNode from AudioNode r=padenot (91055f431b)
- bug 1210267 use DOMEventTargetHelper::LastRelease instead of custom Release r=baku (f81093ce16)
- bug 1179662 call DisconnectFromGraph once only during unlink r=padenot (d95a512d7c)
- Bug 1189506. Give AudioContext non-owning pointers to all its AudioNodes. r=karl (f9c2505e25)
- bug 1197028 move AllocateAudioBlock to AudioBlock.h r=padenot (59e140347f)
- bug 1197028 introduce AudioBlockBuffer r=padenot (bc33ccfc7f)
- bug 1199559 write offline buffer in a format suitable for direct use by AudioBuffer r=padenot (69fd69c667)
- bug 1199560 finish offline audio context processing even when allocation fails r=padenot (5863c0a56a)
- Bug 1140448 - Improving the performances of how AudioEventTimeline calculates values, r=padenot (1a239c48e7)
- bug 1191648 don't keep ScriptProcessorNode alive when it has no audioprocess listener r=padenot (8e1e5eb67d)
- bug 1191649 determine ScriptProcessor connected status on main thread r=padenot (a919a422c4)
- bug 1191648 don't create audioprocess event when there is no listener r=padenot (98ed82f86a)
- bug 1199559 write audioprocess input buffer in a format suitable for direct use by AudioBuffer r=padenot (9ffcb9c64d)
- bug 1197028 use AudioChunk::ChannelCount() r=padenot (1cf63e9959)
- Bug 1148230 - Eliminate the duplicate subexpression (0f1ad073ff)
- bug 1197028 use AudioChunk::GetDuration() r=padenot (b9c30d524c)
- bug 1197028 introduce AudioBlock to keep track of downstream references to AudioBlockBuffer r=padenot (dfe5d1cb2f)
- bug 1199559 add a helper to fallibly allocate ThreadSharedFloatArrayBufferList with buffers r=padenot (4e0c756087)
- bug 1197028 use AudioBlock for web audio processing to reuse buffers shared downstream r=padenot (bf12911645)
- bug 1201854 handle stop time precisely even when resampling r=padenot (8901626678)
- back out part of bug 1197028 (d5d5bfc98a)
- Bug 1189506. Put AudioContext::State inline. r=karl (ded4e9a6c0)
- bug 916387 keep ScriptProcessorNode alive after input is GCed r=padenot (9430a56c6a)
- Bug 1157137 - Fix WebAudio ScriptProcessorNode sometimes gaining high latency. r=padenot (32eadcafaf)
- Bug 1189506. Pass AudioContext to AudioNodeStream::Create. r=karlt (8446b0d16d)
- bug 1205558 remove unnecessary ScriptProcessorNodeEngine::mSource r=padenot (1e058b4390)
- bug 1053011 align "extra" time on AudioContext with processing block size r=padenot (afeb49adbb)
- Bug 1188099 - (Part 3) Introduce [ChromeOnly] SpeechSynthesis.forceEnd for tests. r=smaug r=kdavis (53d765144f)
- Bug 1189506. Convert ChangeExplicitBlockerCount to MediaStream::Suspend/Resume. r=padenot (cb074a339e)
- bug 1205540 don't send more null chunks than necessary to AnalyserNode r=padenot (d382e1f4ae)
- bug 1205540 provide querying whether engines need to continue processing even without input r=padenot (36e44cb77b)
- bug 1203380 destroy AudioBlocks on AudioNodeStream on graph thread r=padenot (777e68da76)
- Bug 1201393. Create an iterator for MediaStreamGraph to iterate over all its streams. r=karlt (3fe295d8c4)
- Bug 1195051 - Part 1: Do not unmute the destination node as soon as the AudioContext is constructed; r=padenot (4243840184)
- Bug 1195051 - Part 2: Mute the destination node when the AudioContext is suspended, and unmute when resumed; r=padenot (e07d9e3268)
- Bug 1201393. Make suspended MediaStreams implicitly always block. r=padenot (d4557acf43)
- Bug 1189506. Make AudioContext responsible for tracking all nodes which need to be suspended and resumed. r=padenot (04410070e7)
- Bug 1189506. Make suspending/resuming streams more reusable. r=padenot (503052804e)
- bug 1201855 rearrange CopyFromBuffer to separate code using numFrames r=padenot (9e2147d19c)
- revert blocked to finished (2bed009b25)
- bug 1205540 account for active inputs and skip processing when streams are inactive r=padenot (a20049ae19)
- bug 864171 move "extra" time accounting for AudioContext with no nodes to destination stream r=padenot (8ef43b8f25)
- bug 1208327 make enum AudioContextOperation strongly typed and forward declare instead of including AudioContext.h r=roc (35cc6748c6)
- Bug 1201393. Remove usage of FLAG_BLOCK_OUTPUT from MediaRecorder. r=jwwang (d7ddf40ba2)
- Bug 1201393. Remove usage of FLAG_BLOCK_INPUT from MediaRecorder. r=jwwang (587979ca8a)
- Bug 1189506. Remove usage of FLAG_BLOCK_OUTPUT from MediaManager. r=jesup (d2cb000648)
- Bug 1201393. Remove usage of FLAG_BLOCK_* from OutputStreamData::Connect. r=jwwang (e31f1effc4)
- Bug 1189506. Don't bother blocking captured media-element MediaStreams while we're not decoding. r=jwwang (c7240f6fc3)
- Bug 1201393. Remove usage of FLAG_BLOCK_INPUT from AudioParam/AudioNode. r=padenot (57a3e05283)
- bug 1191649 add notification of input node changes r=padenot (752ae93e82)
- bug 916387 add a notification of garbage collected input node r=padenot (6336b50f51)
- Bug 1201393. Remove usage of FLAG_BLOCK_INPUT from MediaStreamAudioSourceNode. r=jwwang (df4d77f09a)
- Bug 1189506. Remove aFlags parameter from AllocateInputPort. r=karlt (b62e152ec3)
- bug 1205540 make source stream available during RemoveInput r=padenot (45341fac7f)
- Bug 1189506. Remove MediaInputPort::mFlags. r=karlt (61cb5dce71)
- Bug 1170958 - Allow MediaInputPort to lock to a specific input track. r=roc (a5ba676c3d)
- Bug 1200579 - Stop copying AudioParam timelines. r=karlt (0720f80914)
- bug 1209286 remove now unnecessary StreamTimeToDOMTime and DOMTimeToStreamTime r=padenot (ff93dd9d3a)
- Bug 1140450 - Lower speex_resampler quality for Web Audio API. r=padenot (2f34f0b90c)
- bug 1201855 keep track of buffer position even when there are no channels r=padenot (f3cdcd3bfc)
- bug 1201855 send ended event even when the buffer has no channel data r=padenot (5175efcf0a)
- backout from from bug 1197028 (ab2235c6b9)
- Bug 1163958 - Reduce the allocation in MediaStreamGraph - patch 2, r=padenot (0b00b72341)
- Bug 1189506. Fix multi-track MediaStream audio output. r=karlt (b136e91cc5)
- Bug 1189506. Simplify PlayAudio based on the fact that track time units == stream time units. r=karlt (e3a164170c)
- Bug 1189506. Remove misleading comment. r=karlt (f491ee4f02)
- Bug 1189506. Simplify blocking code now that stream blocking decision are always independent of other streams. r=karlt (646ee9a8da)
- Bug 1189506. Remove MediaStream::mBlockInThisPhase. r=karlt (4cfc75216f)
- Bug 1189506. Remove mExplicitBlockerCount and related code since it's always zero now. r=karlt (1d45b877fc)
- Bug 1189506. Remove unused MediaStreamGraph::GetBufferedTicks. r=karlt (5f90c53e87)
- Bug 1189506. Simplify blocking calculations based on the observation that once a stream starts blocking in a given processing interval, it must stay blocked. r=karlt (bd1d2a90d0)
- Bug 1189506. Replace MediaStream::mBlocked with simpler MediaStream::mStartBlocking. r=karlt (215bacd2fd)
- Bug 1189506. Inline RecomputeBlocking. r=karlt (336a6ab1e9)
- Bug 1189506. Inline ComputeStreamBlockTime. r=karlt (0b0256bb64)
- Bug 1189506. Remove unused NotifyConsumptionChanged. r=karlt (c9f1250b34)
- Bug 1189506. Remove unused mFlushSourcesNow/mFlushSourcesOnNextIteration. r=karlt (734d5fff71)
- Bug 1189506. Factor out code from OneIteration into helper methods. r=karlt (52b5030073)
- Bug 1189506. Move setting of mStateComputedTime to OneIteration so it's near setting mProcessedTime. r=karlt (c3507aaa84)
- Bug 1189506. No need to pass aNextCurrentTime to UpdateCurrentTimeForStreams. r=karlt (1c6141e03e)
- Bug 1189506. Inline StreamNotifyOutput/StreamNotifyFinished. r=karlt (cdac2c6405)
- Bug 1189506. Rename StreamTimeToGraphTime/GraphTimeToStreamTime to ...WithBlocking. r=karlt (e61ffd53a4)
- bug 1199559 permit writing to ThreadSharedFloatArrayBufferList when not shared r=padenot (4eaa511691)
- bug 1199559 add a factory method to accept generated buffer contents in a format suitable for direct use r=padenot (801f9c6c35)
- Bug 1170958 - Add input stream and track as args to NotifyQueuedTrackChanges. r=roc (b3677c801a)
- bug 1196111 don't keep AudioContext alive from AudioBuffer r=baku (f1b113c655)
- bug 1207003 fetch stream position once instead of three times r=padenot (2cef872dc0)
- bug 1207003 remove unused aStream parameter r=padenot (8c3fa1ee88)
- bug 1207003 add GraphTime parameter to ProcessBlock() and remove GetCurrentPosition() r=padenot (5f442537a2)
- bug 1206362 be careful about double -> int conversion r=padenot (956051f9f1)
- Bug 1189506. Remove invalid assertion. r=karlt (4fa8b5a7b1)
- Bug 1189506. Create StreamTimeToGraphTime/GraphTimeToStreamTime that don't take account of blocking, and call them from AudioNodeStream. r=karlt (d10f5b1b62)
- bug 1205558 use destination stream for audio node engine time r=padenot (a9361c32ac)
- bug 1205558 remove unused AudioNodeStream* aSource parameter r=padenot (7667751920)
- Bug 1189506. Use mProcessedTime in some places instead of passing aFrm. r=karlt (c5537555e5)
- Bug 1189506. Use mStateComputedTime in some places instead of passing aTo. r=karlt (69ed378a74)
- Bug 1189506. Use mProcessedTime/mStateComputedTime in ProduceDataForStreamsBlockByBlock. karlt (bc1c49c537)
- bug 1214493 restore fractional start time accidentally rounded in 13e85dc6b41b r=padenot (87b7b5de82)
- missing bit of 1205558 (a46dbdc0de)
- Bug 1185176 - Account for the fact that it is possible for nodes to not have streams. r=karlt (1b5729312b)
- Bug 1210266 use parameter index instead of node callback for sending timeline events r=padenot (6501350f34)
- remove blocked for finished (89fcb0509c)
- bug 1215096 correct off-by-one error in playback position of resampled buffers r=padenot (38c7351675)
- bug 1020370 adjust assert to tolerate large skipFracNum r=padenot (f4f5c7f10f)
- bug 1020370 use int64_t to avoid overflow in subsample calcs r=padenot (9ec82a2c36)
- missing bit of bug 1201855 use unsigned integers for buffer positions (7e83ff4598)
- bug 1179662 call UnregisterAudioBufferSourceNode only once r=padenot (40a5d8ab9a)
- bug 1205558 introduce SecondsToNearestStreamTime r=padenot (719acd8bc2)
- missing bits of Bug 1189506. Make AudioContext responsible (8bd5a1044d)
- Bug 1189506. Call GraphTimeToStreamTime in ExtractPendingInput since we know no blocking time has been determined yet. r=karlt (bab799c1d0)
2022-10-18 16:11:45 +08:00

297 lines
8.3 KiB
C++

/* -*- 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 "AudioNodeEngine.h"
#ifdef BUILD_ARM_NEON
#include "mozilla/arm.h"
#include "AudioNodeEngineNEON.h"
#endif
namespace mozilla {
already_AddRefed<ThreadSharedFloatArrayBufferList>
ThreadSharedFloatArrayBufferList::Create(uint32_t aChannelCount,
size_t aLength,
const mozilla::fallible_t&)
{
RefPtr<ThreadSharedFloatArrayBufferList> buffer =
new ThreadSharedFloatArrayBufferList(aChannelCount);
for (uint32_t i = 0; i < aChannelCount; ++i) {
float* channelData = js_pod_malloc<float>(aLength);
if (!channelData) {
return nullptr;
}
buffer->SetData(i, channelData, js_free, channelData);
}
return buffer.forget();
}
void
WriteZeroesToAudioBlock(AudioBlock* 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->ChannelCount(); ++i) {
PodZero(aChunk->ChannelFloatsForWrite(i) + aStart, aLength);
}
}
void AudioBufferCopyWithScale(const float* aInput,
float aScale,
float* aOutput,
uint32_t aSize)
{
if (aScale == 1.0f) {
PodCopy(aOutput, aInput, aSize);
} else {
for (uint32_t i = 0; i < aSize; ++i) {
aOutput[i] = aInput[i]*aScale;
}
}
}
void AudioBufferAddWithScale(const float* aInput,
float aScale,
float* aOutput,
uint32_t aSize)
{
#ifdef BUILD_ARM_NEON
if (mozilla::supports_neon()) {
AudioBufferAddWithScale_NEON(aInput, aScale, aOutput, aSize);
return;
}
#endif
if (aScale == 1.0f) {
for (uint32_t i = 0; i < aSize; ++i) {
aOutput[i] += aInput[i];
}
} else {
for (uint32_t i = 0; i < aSize; ++i) {
aOutput[i] += aInput[i]*aScale;
}
}
}
void
AudioBlockAddChannelWithScale(const float aInput[WEBAUDIO_BLOCK_SIZE],
float aScale,
float aOutput[WEBAUDIO_BLOCK_SIZE])
{
AudioBufferAddWithScale(aInput, aScale, aOutput, WEBAUDIO_BLOCK_SIZE);
}
void
AudioBlockCopyChannelWithScale(const float* aInput,
float aScale,
float* aOutput)
{
if (aScale == 1.0f) {
memcpy(aOutput, aInput, WEBAUDIO_BLOCK_SIZE*sizeof(float));
} else {
#ifdef BUILD_ARM_NEON
if (mozilla::supports_neon()) {
AudioBlockCopyChannelWithScale_NEON(aInput, aScale, aOutput);
return;
}
#endif
for (uint32_t i = 0; i < WEBAUDIO_BLOCK_SIZE; ++i) {
aOutput[i] = aInput[i]*aScale;
}
}
}
void
BufferComplexMultiply(const float* aInput,
const float* aScale,
float* aOutput,
uint32_t aSize)
{
for (uint32_t i = 0; i < aSize * 2; i += 2) {
float real1 = aInput[i];
float imag1 = aInput[i + 1];
float real2 = aScale[i];
float imag2 = aScale[i + 1];
float realResult = real1 * real2 - imag1 * imag2;
float imagResult = real1 * imag2 + imag1 * real2;
aOutput[i] = realResult;
aOutput[i + 1] = imagResult;
}
}
float
AudioBufferPeakValue(const float *aInput, uint32_t aSize)
{
float max = 0.0f;
for (uint32_t i = 0; i < aSize; i++) {
float mag = fabs(aInput[i]);
if (mag > max) {
max = mag;
}
}
return max;
}
void
AudioBlockCopyChannelWithScale(const float aInput[WEBAUDIO_BLOCK_SIZE],
const float aScale[WEBAUDIO_BLOCK_SIZE],
float aOutput[WEBAUDIO_BLOCK_SIZE])
{
#ifdef BUILD_ARM_NEON
if (mozilla::supports_neon()) {
AudioBlockCopyChannelWithScale_NEON(aInput, aScale, aOutput);
return;
}
#endif
for (uint32_t i = 0; i < WEBAUDIO_BLOCK_SIZE; ++i) {
aOutput[i] = aInput[i]*aScale[i];
}
}
void
AudioBlockInPlaceScale(float aBlock[WEBAUDIO_BLOCK_SIZE],
float aScale)
{
AudioBufferInPlaceScale(aBlock, aScale, WEBAUDIO_BLOCK_SIZE);
}
void
AudioBufferInPlaceScale(float* aBlock,
float aScale,
uint32_t aSize)
{
if (aScale == 1.0f) {
return;
}
#ifdef BUILD_ARM_NEON
if (mozilla::supports_neon()) {
AudioBufferInPlaceScale_NEON(aBlock, aScale, aSize);
return;
}
#endif
for (uint32_t i = 0; i < aSize; ++i) {
*aBlock++ *= aScale;
}
}
void
AudioBlockPanMonoToStereo(const float aInput[WEBAUDIO_BLOCK_SIZE],
float aGainL[WEBAUDIO_BLOCK_SIZE],
float aGainR[WEBAUDIO_BLOCK_SIZE],
float aOutputL[WEBAUDIO_BLOCK_SIZE],
float aOutputR[WEBAUDIO_BLOCK_SIZE])
{
AudioBlockCopyChannelWithScale(aInput, aGainL, aOutputL);
AudioBlockCopyChannelWithScale(aInput, aGainR, aOutputR);
}
void
AudioBlockPanMonoToStereo(const float aInput[WEBAUDIO_BLOCK_SIZE],
float aGainL, float aGainR,
float aOutputL[WEBAUDIO_BLOCK_SIZE],
float aOutputR[WEBAUDIO_BLOCK_SIZE])
{
AudioBlockCopyChannelWithScale(aInput, aGainL, aOutputL);
AudioBlockCopyChannelWithScale(aInput, aGainR, aOutputR);
}
void
AudioBlockPanStereoToStereo(const float aInputL[WEBAUDIO_BLOCK_SIZE],
const float aInputR[WEBAUDIO_BLOCK_SIZE],
float aGainL, float aGainR, bool aIsOnTheLeft,
float aOutputL[WEBAUDIO_BLOCK_SIZE],
float aOutputR[WEBAUDIO_BLOCK_SIZE])
{
#ifdef BUILD_ARM_NEON
if (mozilla::supports_neon()) {
AudioBlockPanStereoToStereo_NEON(aInputL, aInputR,
aGainL, aGainR, aIsOnTheLeft,
aOutputL, aOutputR);
return;
}
#endif
uint32_t i;
if (aIsOnTheLeft) {
for (i = 0; i < WEBAUDIO_BLOCK_SIZE; ++i) {
aOutputL[i] = aInputL[i] + aInputR[i] * aGainL;
aOutputR[i] = aInputR[i] * aGainR;
}
} else {
for (i = 0; i < WEBAUDIO_BLOCK_SIZE; ++i) {
aOutputL[i] = aInputL[i] * aGainL;
aOutputR[i] = aInputR[i] + aInputL[i] * aGainR;
}
}
}
void
AudioBlockPanStereoToStereo(const float aInputL[WEBAUDIO_BLOCK_SIZE],
const float aInputR[WEBAUDIO_BLOCK_SIZE],
float aGainL[WEBAUDIO_BLOCK_SIZE],
float aGainR[WEBAUDIO_BLOCK_SIZE],
bool aIsOnTheLeft[WEBAUDIO_BLOCK_SIZE],
float aOutputL[WEBAUDIO_BLOCK_SIZE],
float aOutputR[WEBAUDIO_BLOCK_SIZE])
{
#ifdef BUILD_ARM_NEON
// No NEON version yet: bug 1105513
#endif
uint32_t i;
for (i = 0; i < WEBAUDIO_BLOCK_SIZE; i++) {
if (aIsOnTheLeft[i]) {
aOutputL[i] = aInputL[i] + aInputR[i] * aGainL[i];
aOutputR[i] = aInputR[i] * aGainR[i];
} else {
aOutputL[i] = aInputL[i] * aGainL[i];
aOutputR[i] = aInputR[i] + aInputL[i] * aGainR[i];
}
}
}
float
AudioBufferSumOfSquares(const float* aInput, uint32_t aLength)
{
float sum = 0.0f;
while (aLength--) {
sum += *aInput * *aInput;
++aInput;
}
return sum;
}
void
AudioNodeEngine::ProcessBlock(AudioNodeStream* aStream,
GraphTime aFrom,
const AudioBlock& aInput,
AudioBlock* aOutput,
bool* aFinished)
{
MOZ_ASSERT(mInputCount <= 1 && mOutputCount <= 1);
*aOutput = aInput;
}
void
AudioNodeEngine::ProcessBlocksOnPorts(AudioNodeStream* aStream,
const OutputChunks& aInput,
OutputChunks& aOutput,
bool* aFinished)
{
MOZ_ASSERT(mInputCount > 1 || mOutputCount > 1);
// Only produce one output port, and drop all other input ports.
aOutput[0] = aInput[0];
}
} // namespace mozilla