2013-01-14 02:46:57 +04:00
|
|
|
/* -*- 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"
|
2016-12-08 11:00:12 +03:00
|
|
|
|
|
|
|
#include "mozilla/AbstractThread.h"
|
2019-01-11 17:39:51 +03:00
|
|
|
#ifdef USE_NEON
|
2013-09-06 00:25:17 +04:00
|
|
|
# include "mozilla/arm.h"
|
2023-01-16 14:05:20 +03:00
|
|
|
# include "AudioNodeEngineGeneric.h"
|
2013-08-13 13:30:18 +04:00
|
|
|
#endif
|
2016-03-18 23:24:02 +03:00
|
|
|
#ifdef USE_SSE2
|
2016-04-22 18:31:09 +03:00
|
|
|
# include "mozilla/SSE.h"
|
2023-01-16 14:05:20 +03:00
|
|
|
# include "AudioNodeEngineGeneric.h"
|
2023-01-13 16:31:44 +03:00
|
|
|
#endif
|
2023-01-16 14:05:20 +03:00
|
|
|
#if defined(USE_SSE42) && defined(USE_FMA3)
|
|
|
|
# include "mozilla/SSE.h"
|
|
|
|
# include "AudioNodeEngineGeneric.h"
|
|
|
|
#endif
|
2017-08-08 06:38:02 +03:00
|
|
|
#include "AudioBlock.h"
|
2022-08-23 12:25:55 +03:00
|
|
|
#include "Tracing.h"
|
2013-01-14 02:46:57 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2015-08-27 11:35:43 +03:00
|
|
|
already_AddRefed<ThreadSharedFloatArrayBufferList>
|
|
|
|
ThreadSharedFloatArrayBufferList::Create(uint32_t aChannelCount, size_t aLength,
|
|
|
|
const mozilla::fallible_t&) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ThreadSharedFloatArrayBufferList> buffer =
|
2015-08-27 11:35:43 +03:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2015-09-03 10:01:50 +03:00
|
|
|
void WriteZeroesToAudioBlock(AudioBlock* aChunk, uint32_t aStart,
|
|
|
|
uint32_t aLength) {
|
2013-01-14 02:46:57 +04:00
|
|
|
MOZ_ASSERT(aStart + aLength <= WEBAUDIO_BLOCK_SIZE);
|
2013-04-08 19:20:46 +04:00
|
|
|
MOZ_ASSERT(!aChunk->IsNull(), "You should pass a non-null chunk");
|
2020-04-30 01:39:15 +03:00
|
|
|
if (aLength == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2015-07-22 08:59:21 +03:00
|
|
|
|
2015-09-03 08:30:16 +03:00
|
|
|
for (uint32_t i = 0; i < aChunk->ChannelCount(); ++i) {
|
2015-07-22 08:59:21 +03:00
|
|
|
PodZero(aChunk->ChannelFloatsForWrite(i) + aStart, aLength);
|
2013-01-14 02:46:57 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-26 05:35:22 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-11 00:09:01 +04:00
|
|
|
void AudioBufferAddWithScale(const float* aInput, float aScale, float* aOutput,
|
|
|
|
uint32_t aSize) {
|
2019-01-11 17:39:51 +03:00
|
|
|
#ifdef USE_NEON
|
2013-08-13 13:30:18 +04:00
|
|
|
if (mozilla::supports_neon()) {
|
2023-01-16 14:05:20 +03:00
|
|
|
Engine<xsimd::neon>::AudioBufferAddWithScale(aInput, aScale, aOutput,
|
|
|
|
aSize);
|
2013-08-13 13:30:18 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2016-03-18 23:24:02 +03:00
|
|
|
|
|
|
|
#ifdef USE_SSE2
|
2016-04-29 15:35:30 +03:00
|
|
|
if (mozilla::supports_sse2()) {
|
2023-01-16 14:05:20 +03:00
|
|
|
# if defined(USE_SSE42) && defined(USE_FMA3)
|
|
|
|
if (mozilla::supports_fma3() && mozilla::supports_sse4_2()) {
|
|
|
|
Engine<xsimd::fma3<xsimd::sse4_2>>::AudioBufferAddWithScale(
|
|
|
|
aInput, aScale, aOutput, aSize);
|
|
|
|
} else
|
|
|
|
# endif
|
|
|
|
{
|
|
|
|
Engine<xsimd::sse2>::AudioBufferAddWithScale(aInput, aScale, aOutput,
|
|
|
|
aSize);
|
|
|
|
}
|
2023-01-16 14:05:20 +03:00
|
|
|
return;
|
2016-03-18 23:24:02 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-01-14 02:46:57 +04:00
|
|
|
if (aScale == 1.0f) {
|
2013-06-11 00:09:01 +04:00
|
|
|
for (uint32_t i = 0; i < aSize; ++i) {
|
2013-01-14 02:46:57 +04:00
|
|
|
aOutput[i] += aInput[i];
|
|
|
|
}
|
|
|
|
} else {
|
2013-06-11 00:09:01 +04:00
|
|
|
for (uint32_t i = 0; i < aSize; ++i) {
|
2013-01-14 02:46:57 +04:00
|
|
|
aOutput[i] += aInput[i] * aScale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-11 00:09:01 +04:00
|
|
|
void AudioBlockAddChannelWithScale(const float aInput[WEBAUDIO_BLOCK_SIZE],
|
|
|
|
float aScale,
|
|
|
|
float aOutput[WEBAUDIO_BLOCK_SIZE]) {
|
|
|
|
AudioBufferAddWithScale(aInput, aScale, aOutput, WEBAUDIO_BLOCK_SIZE);
|
|
|
|
}
|
|
|
|
|
2013-04-23 05:59:51 +04:00
|
|
|
void AudioBlockCopyChannelWithScale(const float* aInput, float aScale,
|
|
|
|
float* aOutput) {
|
2013-01-14 02:46:57 +04:00
|
|
|
if (aScale == 1.0f) {
|
|
|
|
memcpy(aOutput, aInput, WEBAUDIO_BLOCK_SIZE * sizeof(float));
|
|
|
|
} else {
|
2019-01-11 17:39:51 +03:00
|
|
|
#ifdef USE_NEON
|
2013-08-13 13:30:18 +04:00
|
|
|
if (mozilla::supports_neon()) {
|
2023-01-16 14:05:20 +03:00
|
|
|
Engine<xsimd::neon>::AudioBlockCopyChannelWithScale(aInput, aScale,
|
|
|
|
aOutput);
|
2013-08-13 13:30:18 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2016-03-18 23:24:02 +03:00
|
|
|
|
|
|
|
#ifdef USE_SSE2
|
2016-04-29 15:35:30 +03:00
|
|
|
if (mozilla::supports_sse2()) {
|
2023-01-16 14:05:20 +03:00
|
|
|
Engine<xsimd::sse2>::AudioBlockCopyChannelWithScale(aInput, aScale,
|
|
|
|
aOutput);
|
2016-04-20 18:54:50 +03:00
|
|
|
return;
|
|
|
|
}
|
2016-03-18 23:24:02 +03:00
|
|
|
#endif
|
|
|
|
|
2013-01-14 02:46:57 +04:00
|
|
|
for (uint32_t i = 0; i < WEBAUDIO_BLOCK_SIZE; ++i) {
|
|
|
|
aOutput[i] = aInput[i] * aScale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-11 00:08:21 +04:00
|
|
|
void BufferComplexMultiply(const float* aInput, const float* aScale,
|
|
|
|
float* aOutput, uint32_t aSize) {
|
2023-01-16 14:05:20 +03:00
|
|
|
#ifdef USE_NEON
|
|
|
|
if (mozilla::supports_neon()) {
|
|
|
|
Engine<xsimd::neon>::BufferComplexMultiply(aInput, aScale, aOutput, aSize);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2016-04-14 15:57:21 +03:00
|
|
|
#ifdef USE_SSE2
|
|
|
|
if (mozilla::supports_sse()) {
|
2023-01-16 14:05:20 +03:00
|
|
|
# if defined(USE_SSE42) && defined(USE_FMA3)
|
|
|
|
if (mozilla::supports_fma3() && mozilla::supports_sse4_2()) {
|
|
|
|
Engine<xsimd::fma3<xsimd::sse4_2>>::BufferComplexMultiply(aInput, aScale,
|
|
|
|
aOutput, aSize);
|
|
|
|
} else
|
|
|
|
# endif
|
|
|
|
{
|
|
|
|
Engine<xsimd::sse2>::BufferComplexMultiply(aInput, aScale, aOutput,
|
|
|
|
aSize);
|
|
|
|
}
|
2016-04-14 15:57:21 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-06-11 00:08:21 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-10 21:54:17 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-01-30 03:37:51 +04:00
|
|
|
void AudioBlockCopyChannelWithScale(const float aInput[WEBAUDIO_BLOCK_SIZE],
|
|
|
|
const float aScale[WEBAUDIO_BLOCK_SIZE],
|
|
|
|
float aOutput[WEBAUDIO_BLOCK_SIZE]) {
|
2019-01-11 17:39:51 +03:00
|
|
|
#ifdef USE_NEON
|
2013-08-13 13:30:18 +04:00
|
|
|
if (mozilla::supports_neon()) {
|
2023-01-16 14:05:20 +03:00
|
|
|
Engine<xsimd::neon>::AudioBlockCopyChannelWithScale(aInput, aScale,
|
|
|
|
aOutput);
|
2013-08-13 13:30:18 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2016-03-18 23:24:02 +03:00
|
|
|
|
|
|
|
#ifdef USE_SSE2
|
|
|
|
if (mozilla::supports_sse2()) {
|
2023-01-16 14:05:20 +03:00
|
|
|
Engine<xsimd::sse2>::AudioBlockCopyChannelWithScale(aInput, aScale,
|
|
|
|
aOutput);
|
2016-03-18 23:24:02 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-01-30 03:37:51 +04:00
|
|
|
for (uint32_t i = 0; i < WEBAUDIO_BLOCK_SIZE; ++i) {
|
|
|
|
aOutput[i] = aInput[i] * aScale[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-08 07:57:26 +04:00
|
|
|
void AudioBlockInPlaceScale(float aBlock[WEBAUDIO_BLOCK_SIZE], float aScale) {
|
2014-01-28 09:14:25 +04:00
|
|
|
AudioBufferInPlaceScale(aBlock, aScale, WEBAUDIO_BLOCK_SIZE);
|
2013-06-11 00:09:01 +04:00
|
|
|
}
|
|
|
|
|
2018-07-06 16:18:06 +03:00
|
|
|
void AudioBlockInPlaceScale(float aBlock[WEBAUDIO_BLOCK_SIZE],
|
|
|
|
float aScale[WEBAUDIO_BLOCK_SIZE]) {
|
|
|
|
AudioBufferInPlaceScale(aBlock, aScale, WEBAUDIO_BLOCK_SIZE);
|
|
|
|
}
|
|
|
|
|
2013-06-11 00:09:01 +04:00
|
|
|
void AudioBufferInPlaceScale(float* aBlock, float aScale, uint32_t aSize) {
|
2013-03-21 20:45:53 +04:00
|
|
|
if (aScale == 1.0f) {
|
|
|
|
return;
|
|
|
|
}
|
2019-01-11 17:39:51 +03:00
|
|
|
#ifdef USE_NEON
|
2013-08-13 13:30:18 +04:00
|
|
|
if (mozilla::supports_neon()) {
|
2023-01-16 14:05:20 +03:00
|
|
|
Engine<xsimd::neon>::AudioBufferInPlaceScale(aBlock, aScale, aSize);
|
2013-08-13 13:30:18 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2016-03-18 23:24:02 +03:00
|
|
|
|
|
|
|
#ifdef USE_SSE2
|
|
|
|
if (mozilla::supports_sse2()) {
|
2023-01-16 14:05:20 +03:00
|
|
|
Engine<xsimd::sse2>::AudioBufferInPlaceScale(aBlock, aScale, aSize);
|
2016-03-18 23:24:02 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-01-08 07:57:53 +04:00
|
|
|
for (uint32_t i = 0; i < aSize; ++i) {
|
2013-03-21 20:45:53 +04:00
|
|
|
*aBlock++ *= aScale;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-06 16:18:06 +03:00
|
|
|
void AudioBufferInPlaceScale(float* aBlock, float* aScale, uint32_t aSize) {
|
2019-01-11 17:39:51 +03:00
|
|
|
#ifdef USE_NEON
|
2018-07-06 16:18:06 +03:00
|
|
|
if (mozilla::supports_neon()) {
|
2023-01-16 14:05:20 +03:00
|
|
|
Engine<xsimd::neon>::AudioBufferInPlaceScale(aBlock, aScale, aSize);
|
2018-07-06 16:18:06 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_SSE2
|
|
|
|
if (mozilla::supports_sse2()) {
|
2023-01-16 14:05:20 +03:00
|
|
|
Engine<xsimd::sse2>::AudioBufferInPlaceScale(aBlock, aScale, aSize);
|
2018-07-06 16:18:06 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
for (uint32_t i = 0; i < aSize; ++i) {
|
|
|
|
*aBlock++ *= *aScale++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-19 20:15:13 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2013-03-21 20:45:53 +04:00
|
|
|
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]) {
|
2019-01-11 17:39:51 +03:00
|
|
|
#ifdef USE_NEON
|
2013-08-13 13:30:18 +04:00
|
|
|
if (mozilla::supports_neon()) {
|
2023-01-16 14:05:20 +03:00
|
|
|
Engine<xsimd::neon>::AudioBlockPanStereoToStereo(
|
|
|
|
aInputL, aInputR, aGainL, aGainR, aIsOnTheLeft, aOutputL, aOutputR);
|
2013-08-13 13:30:18 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2016-03-18 23:24:02 +03:00
|
|
|
#ifdef USE_SSE2
|
|
|
|
if (mozilla::supports_sse2()) {
|
2023-01-16 14:05:20 +03:00
|
|
|
# if defined(USE_SSE42) && defined(USE_FMA3)
|
|
|
|
if (mozilla::supports_fma3() && mozilla::supports_sse4_2()) {
|
|
|
|
Engine<xsimd::fma3<xsimd::sse4_2>>::AudioBlockPanStereoToStereo(
|
|
|
|
aInputL, aInputR, aGainL, aGainR, aIsOnTheLeft, aOutputL, aOutputR);
|
|
|
|
} else
|
|
|
|
# endif
|
|
|
|
{
|
|
|
|
Engine<xsimd::sse2>::AudioBlockPanStereoToStereo(
|
|
|
|
aInputL, aInputR, aGainL, aGainR, aIsOnTheLeft, aOutputL, aOutputR);
|
|
|
|
}
|
2016-03-18 23:24:02 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-03-21 20:45:53 +04:00
|
|
|
uint32_t i;
|
|
|
|
|
|
|
|
if (aIsOnTheLeft) {
|
|
|
|
for (i = 0; i < WEBAUDIO_BLOCK_SIZE; ++i) {
|
2014-11-19 20:15:13 +03:00
|
|
|
aOutputL[i] = aInputL[i] + aInputR[i] * aGainL;
|
|
|
|
aOutputR[i] = aInputR[i] * aGainR;
|
2013-03-21 20:45:53 +04:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < WEBAUDIO_BLOCK_SIZE; ++i) {
|
2014-11-19 20:15:13 +03:00
|
|
|
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],
|
2020-04-30 01:39:15 +03:00
|
|
|
const float aGainL[WEBAUDIO_BLOCK_SIZE],
|
|
|
|
const float aGainR[WEBAUDIO_BLOCK_SIZE],
|
|
|
|
const bool aIsOnTheLeft[WEBAUDIO_BLOCK_SIZE],
|
2014-11-19 20:15:13 +03:00
|
|
|
float aOutputL[WEBAUDIO_BLOCK_SIZE],
|
|
|
|
float aOutputR[WEBAUDIO_BLOCK_SIZE]) {
|
2019-01-11 17:39:51 +03:00
|
|
|
#ifdef USE_NEON
|
2015-12-17 21:15:54 +03:00
|
|
|
if (mozilla::supports_neon()) {
|
2023-01-16 14:05:20 +03:00
|
|
|
Engine<xsimd::neon>::AudioBlockPanStereoToStereo(
|
|
|
|
aInputL, aInputR, aGainL, aGainR, aIsOnTheLeft, aOutputL, aOutputR);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef USE_SSE2
|
|
|
|
if (mozilla::supports_sse2()) {
|
2023-01-16 14:05:20 +03:00
|
|
|
# if defined(USE_SSE42) && defined(USE_FMA3)
|
|
|
|
if (mozilla::supports_fma3() && mozilla::supports_sse4_2()) {
|
|
|
|
Engine<xsimd::fma3<xsimd::sse2>>::AudioBlockPanStereoToStereo(
|
|
|
|
aInputL, aInputR, aGainL, aGainR, aIsOnTheLeft, aOutputL, aOutputR);
|
|
|
|
} else
|
|
|
|
# endif
|
|
|
|
{
|
|
|
|
Engine<xsimd::sse2>::AudioBlockPanStereoToStereo(
|
|
|
|
aInputL, aInputR, aGainL, aGainR, aIsOnTheLeft, aOutputL, aOutputR);
|
|
|
|
}
|
2015-12-17 21:15:54 +03:00
|
|
|
return;
|
|
|
|
}
|
2014-11-19 20:15:13 +03:00
|
|
|
#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];
|
2013-03-21 20:45:53 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-06-11 00:09:01 +04:00
|
|
|
|
|
|
|
float AudioBufferSumOfSquares(const float* aInput, uint32_t aLength) {
|
2023-01-16 14:05:20 +03:00
|
|
|
#ifdef USE_NEON
|
|
|
|
if (mozilla::supports_neon()) {
|
|
|
|
return Engine<xsimd::neon>::AudioBufferSumOfSquares(aInput, aLength);
|
|
|
|
}
|
|
|
|
#endif
|
2016-04-14 15:57:21 +03:00
|
|
|
|
|
|
|
#ifdef USE_SSE2
|
|
|
|
if (mozilla::supports_sse()) {
|
2023-01-16 14:05:20 +03:00
|
|
|
# if defined(USE_SSE42) && defined(USE_FMA3)
|
|
|
|
if (mozilla::supports_fma3() && mozilla::supports_sse4_2()) {
|
|
|
|
return Engine<xsimd::fma3<xsimd::sse4_2>>::AudioBufferSumOfSquares(
|
|
|
|
aInput, aLength);
|
|
|
|
} else
|
|
|
|
# endif
|
|
|
|
{
|
|
|
|
return Engine<xsimd::sse2>::AudioBufferSumOfSquares(aInput, aLength);
|
|
|
|
}
|
2016-04-14 15:57:21 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-01-16 14:05:20 +03:00
|
|
|
float sum = 0.f;
|
2013-06-11 00:09:01 +04:00
|
|
|
while (aLength--) {
|
|
|
|
sum += *aInput * *aInput;
|
|
|
|
++aInput;
|
|
|
|
}
|
|
|
|
return sum;
|
|
|
|
}
|
|
|
|
|
2020-05-02 02:57:30 +03:00
|
|
|
void NaNToZeroInPlace(float* aSamples, size_t aCount) {
|
|
|
|
#ifdef USE_SSE2
|
|
|
|
if (mozilla::supports_sse2()) {
|
2023-01-16 14:05:20 +03:00
|
|
|
Engine<xsimd::sse2>::NaNToZeroInPlace(aSamples, aCount);
|
2020-05-02 02:57:30 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
for (size_t i = 0; i < aCount; i++) {
|
|
|
|
if (aSamples[i] != aSamples[i]) {
|
|
|
|
aSamples[i] = 0.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-08 11:00:12 +03:00
|
|
|
AudioNodeEngine::AudioNodeEngine(dom::AudioNode* aNode)
|
|
|
|
: mNode(aNode),
|
|
|
|
mNodeType(aNode ? aNode->NodeType() : nullptr),
|
|
|
|
mInputCount(aNode ? aNode->NumberOfInputs() : 1),
|
Bug 1624819 - Remove TaskCategory and other quantum dom remnants. r=smaug,media-playback-reviewers,credential-management-reviewers,cookie-reviewers,places-reviewers,win-reviewers,valentin,mhowell,sgalich,alwu
Sorry this is not a particularly easy patch to review. But it should be
mostly straight-forward.
I kept Document::Dispatch mostly for convenience, but could be
cleaned-up too / changed by SchedulerGroup::Dispatch. Similarly maybe
that can just be NS_DispatchToMainThread if we add an NS_IsMainThread
check there or something (to preserve shutdown semantics).
Differential Revision: https://phabricator.services.mozilla.com/D190450
2023-10-10 11:51:12 +03:00
|
|
|
mOutputCount(aNode ? aNode->NumberOfOutputs() : 0) {
|
2016-12-08 11:00:12 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
MOZ_COUNT_CTOR(AudioNodeEngine);
|
|
|
|
}
|
|
|
|
|
2019-10-02 13:23:02 +03:00
|
|
|
void AudioNodeEngine::ProcessBlock(AudioNodeTrack* aTrack, GraphTime aFrom,
|
2015-09-03 10:01:50 +03:00
|
|
|
const AudioBlock& aInput,
|
|
|
|
AudioBlock* aOutput, bool* aFinished) {
|
|
|
|
MOZ_ASSERT(mInputCount <= 1 && mOutputCount <= 1);
|
2022-08-23 12:25:55 +03:00
|
|
|
TRACE("AudioNodeEngine::ProcessBlock");
|
2015-09-03 10:01:50 +03:00
|
|
|
*aOutput = aInput;
|
|
|
|
}
|
|
|
|
|
2019-10-02 13:23:02 +03:00
|
|
|
void AudioNodeEngine::ProcessBlocksOnPorts(AudioNodeTrack* aTrack,
|
2020-03-04 18:21:28 +03:00
|
|
|
GraphTime aFrom,
|
2019-06-14 19:06:22 +03:00
|
|
|
Span<const AudioBlock> aInput,
|
|
|
|
Span<AudioBlock> aOutput,
|
2015-09-03 10:01:50 +03:00
|
|
|
bool* aFinished) {
|
|
|
|
MOZ_ASSERT(mInputCount > 1 || mOutputCount > 1);
|
2022-08-23 12:25:55 +03:00
|
|
|
TRACE("AudioNodeEngine::ProcessBlocksOnPorts");
|
2015-09-03 10:01:50 +03:00
|
|
|
// Only produce one output port, and drop all other input ports.
|
|
|
|
aOutput[0] = aInput[0];
|
|
|
|
}
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace mozilla
|