forked from LeenkxTeam/LNXSDK
Update Files
This commit is contained in:
126
lib/aura/Tests/auratests/dsp/TestFFTConvolver.hx
Normal file
126
lib/aura/Tests/auratests/dsp/TestFFTConvolver.hx
Normal file
@ -0,0 +1,126 @@
|
||||
package auratests.dsp;
|
||||
|
||||
import utest.Assert;
|
||||
|
||||
import kha.arrays.Float32Array;
|
||||
|
||||
import aura.Aura;
|
||||
import aura.dsp.FFTConvolver;
|
||||
import aura.types.AudioBuffer;
|
||||
import aura.types.Complex;
|
||||
import aura.utils.MathUtils;
|
||||
import aura.utils.TestSignals;
|
||||
|
||||
@:access(aura.dsp.FFTConvolver)
|
||||
class TestFFTConvolver extends utest.Test {
|
||||
var audioBuffer: AudioBuffer;
|
||||
var fftConvolver: FFTConvolver;
|
||||
|
||||
function setup() {
|
||||
audioBuffer = new AudioBuffer(2, FFTConvolver.FFT_SIZE);
|
||||
fftConvolver = new FFTConvolver();
|
||||
}
|
||||
|
||||
function test_process_noFadeIfTemporalInterpLengthIsZero() {
|
||||
fftConvolver.temporalInterpolationLength = 0;
|
||||
|
||||
for (i in 0...audioBuffer.channelLength) {
|
||||
audioBuffer.getChannelView(0)[i] = Math.sin(i * 4 * Math.PI / audioBuffer.channelLength);
|
||||
audioBuffer.getChannelView(1)[i] = Math.sin(i * 4 * Math.PI / audioBuffer.channelLength);
|
||||
}
|
||||
|
||||
setImpulseFreqsToConstant(new Complex(1.0, 0.0));
|
||||
fftConvolver.process(audioBuffer);
|
||||
discardOverlapForNextProcess();
|
||||
for (i in 0...FFTConvolver.FFT_SIZE) {
|
||||
Assert.floatEquals(Math.sin(i * 4 * Math.PI / audioBuffer.channelLength), audioBuffer.getChannelView(0)[i]);
|
||||
Assert.floatEquals(Math.sin(i * 4 * Math.PI / audioBuffer.channelLength), audioBuffer.getChannelView(1)[i]);
|
||||
}
|
||||
|
||||
setImpulseFreqsToConstant(new Complex(0.0, 0.0));
|
||||
fftConvolver.process(audioBuffer);
|
||||
for (i in 0...FFTConvolver.FFT_SIZE) {
|
||||
Assert.floatEquals(0, audioBuffer.getChannelView(0)[i]);
|
||||
Assert.floatEquals(0, audioBuffer.getChannelView(1)[i]);
|
||||
}
|
||||
}
|
||||
|
||||
function test_process_crossfadeIfTemporalInterpLengthIsLargerZero() {
|
||||
fftConvolver.temporalInterpolationLength = 20;
|
||||
|
||||
for (i in 0...audioBuffer.channelLength) {
|
||||
audioBuffer.getChannelView(0)[i] = Math.sin(i * 4 * Math.PI / audioBuffer.channelLength);
|
||||
audioBuffer.getChannelView(1)[i] = Math.sin(i * 4 * Math.PI / audioBuffer.channelLength);
|
||||
}
|
||||
setImpulseFreqsToConstant(new Complex(1.0, 0.0));
|
||||
fftConvolver.process(audioBuffer);
|
||||
discardOverlapForNextProcess();
|
||||
for (i in 0...FFTConvolver.FFT_SIZE) {
|
||||
final t = minF(i, fftConvolver.temporalInterpolationLength) / fftConvolver.temporalInterpolationLength;
|
||||
Assert.floatEquals(lerp(0.0, Math.sin(i * 4 * Math.PI / audioBuffer.channelLength), t), audioBuffer.getChannelView(0)[i]);
|
||||
Assert.floatEquals(lerp(0.0, Math.sin(i * 4 * Math.PI / audioBuffer.channelLength), t), audioBuffer.getChannelView(1)[i]);
|
||||
}
|
||||
|
||||
for (i in 0...audioBuffer.channelLength) {
|
||||
audioBuffer.getChannelView(0)[i] = Math.sin(i * 8 * Math.PI / audioBuffer.channelLength);
|
||||
audioBuffer.getChannelView(1)[i] = Math.sin(i * 8 * Math.PI / audioBuffer.channelLength);
|
||||
}
|
||||
setImpulseFreqsToConstant(new Complex(0.0, 0.0));
|
||||
fftConvolver.process(audioBuffer);
|
||||
for (i in 0...FFTConvolver.FFT_SIZE) {
|
||||
final t = minF(i, fftConvolver.temporalInterpolationLength) / fftConvolver.temporalInterpolationLength;
|
||||
Assert.floatEquals(lerp(Math.sin(i * 8 * Math.PI / audioBuffer.channelLength), 0.0, t), audioBuffer.getChannelView(0)[i]);
|
||||
Assert.floatEquals(lerp(Math.sin(i * 8 * Math.PI / audioBuffer.channelLength), 0.0, t), audioBuffer.getChannelView(1)[i]);
|
||||
}
|
||||
}
|
||||
|
||||
function test_process_crossfadeEntireChunkSize() {
|
||||
fftConvolver.temporalInterpolationLength = -1;
|
||||
|
||||
for (i in 0...audioBuffer.channelLength) {
|
||||
audioBuffer.getChannelView(0)[i] = Math.sin(i * 4 * Math.PI / audioBuffer.channelLength);
|
||||
audioBuffer.getChannelView(1)[i] = Math.sin(i * 4 * Math.PI / audioBuffer.channelLength);
|
||||
}
|
||||
setImpulseFreqsToConstant(new Complex(1.0, 0.0));
|
||||
fftConvolver.process(audioBuffer);
|
||||
discardOverlapForNextProcess();
|
||||
for (i in 0...FFTConvolver.FFT_SIZE) {
|
||||
final t = minF(i, FFTConvolver.CHUNK_SIZE) / FFTConvolver.CHUNK_SIZE;
|
||||
Assert.floatEquals(lerp(0.0, Math.sin(i * 4 * Math.PI / audioBuffer.channelLength), t), audioBuffer.getChannelView(0)[i]);
|
||||
Assert.floatEquals(lerp(0.0, Math.sin(i * 4 * Math.PI / audioBuffer.channelLength), t), audioBuffer.getChannelView(1)[i]);
|
||||
}
|
||||
|
||||
for (i in 0...audioBuffer.channelLength) {
|
||||
audioBuffer.getChannelView(0)[i] = Math.sin(i * 8 * Math.PI / audioBuffer.channelLength);
|
||||
audioBuffer.getChannelView(1)[i] = Math.sin(i * 8 * Math.PI / audioBuffer.channelLength);
|
||||
}
|
||||
setImpulseFreqsToConstant(new Complex(0.0, 0.0));
|
||||
fftConvolver.process(audioBuffer);
|
||||
for (i in 0...FFTConvolver.FFT_SIZE) {
|
||||
final t = minF(i, FFTConvolver.CHUNK_SIZE) / FFTConvolver.CHUNK_SIZE;
|
||||
Assert.floatEquals(lerp(Math.sin(i * 8 * Math.PI / audioBuffer.channelLength), 0.0, t), audioBuffer.getChannelView(0)[i]);
|
||||
Assert.floatEquals(lerp(Math.sin(i * 8 * Math.PI / audioBuffer.channelLength), 0.0, t), audioBuffer.getChannelView(1)[i]);
|
||||
}
|
||||
}
|
||||
|
||||
function setImpulseFreqsToConstant(value: Complex) {
|
||||
for (i in 0...FFTConvolver.FFT_SIZE) {
|
||||
fftConvolver.impulseFFT.getOutput(0 + fftConvolver.currentImpulseAlternationIndex)[i] = value;
|
||||
fftConvolver.impulseFFT.getOutput(2 + fftConvolver.currentImpulseAlternationIndex)[i] = value;
|
||||
}
|
||||
fftConvolver.currentImpulseAlternationIndex = 1 - fftConvolver.currentImpulseAlternationIndex;
|
||||
|
||||
fftConvolver.overlapLength[0] = FFTConvolver.CHUNK_SIZE;
|
||||
fftConvolver.overlapLength[1] = FFTConvolver.CHUNK_SIZE;
|
||||
fftConvolver.prevImpulseLengths[0] = FFTConvolver.CHUNK_SIZE;
|
||||
fftConvolver.prevImpulseLengths[1] = FFTConvolver.CHUNK_SIZE;
|
||||
}
|
||||
|
||||
function discardOverlapForNextProcess() {
|
||||
for (c in 0...FFTConvolver.NUM_CHANNELS) {
|
||||
for (i in 0...fftConvolver.overlapPrev[c].length) {
|
||||
fftConvolver.overlapPrev[c][i] = 0.0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
67
lib/aura/Tests/auratests/dsp/TestFractionalDelayLine.hx
Normal file
67
lib/aura/Tests/auratests/dsp/TestFractionalDelayLine.hx
Normal file
@ -0,0 +1,67 @@
|
||||
package auratests.dsp;
|
||||
|
||||
import utest.Assert;
|
||||
|
||||
import aura.Aura;
|
||||
import aura.dsp.FractionalDelayLine;
|
||||
import aura.types.AudioBuffer;
|
||||
import aura.utils.TestSignals;
|
||||
|
||||
@:access(aura.dsp.FractionalDelayLine)
|
||||
class TestFractionalDelayLine extends utest.Test {
|
||||
var audioBuffer: AudioBuffer;
|
||||
var delayLine: FractionalDelayLine;
|
||||
|
||||
function setup() {
|
||||
audioBuffer = new AudioBuffer(2, 8);
|
||||
delayLine = new FractionalDelayLine(2, 8);
|
||||
}
|
||||
|
||||
function test_zeroDelayTime_noDelay() {
|
||||
TestSignals.fillUnitImpulse(audioBuffer.getChannelView(0));
|
||||
TestSignals.fillUnitImpulse(audioBuffer.getChannelView(1));
|
||||
|
||||
delayLine.at_setDelayLength(Left, 0.0);
|
||||
delayLine.at_setDelayLength(Right, 0.0);
|
||||
|
||||
delayLine.process(audioBuffer);
|
||||
|
||||
Assert.floatEquals(1.0, audioBuffer.getChannelView(0)[0]);
|
||||
Assert.floatEquals(0.0, audioBuffer.getChannelView(0)[1]);
|
||||
|
||||
Assert.floatEquals(1.0, audioBuffer.getChannelView(1)[0]);
|
||||
Assert.floatEquals(0.0, audioBuffer.getChannelView(1)[1]);
|
||||
}
|
||||
|
||||
function test_integralDelayTime_independentChannels() {
|
||||
TestSignals.fillUnitImpulse(audioBuffer.getChannelView(0));
|
||||
TestSignals.fillUnitImpulse(audioBuffer.getChannelView(1));
|
||||
|
||||
delayLine.at_setDelayLength(Left, 1.0);
|
||||
delayLine.at_setDelayLength(Right, 3.0);
|
||||
|
||||
delayLine.process(audioBuffer);
|
||||
|
||||
Assert.floatEquals(0.0, audioBuffer.getChannelView(0)[0]);
|
||||
Assert.floatEquals(1.0, audioBuffer.getChannelView(0)[1]);
|
||||
|
||||
Assert.floatEquals(0.0, audioBuffer.getChannelView(1)[0]);
|
||||
Assert.floatEquals(1.0, audioBuffer.getChannelView(1)[3]);
|
||||
}
|
||||
|
||||
function test_floatDelayTime_independentChannels() {
|
||||
TestSignals.fillUnitImpulse(audioBuffer.getChannelView(0));
|
||||
TestSignals.fillUnitImpulse(audioBuffer.getChannelView(1));
|
||||
|
||||
delayLine.at_setDelayLength(Left, 0.8);
|
||||
delayLine.at_setDelayLength(Right, 3.4);
|
||||
|
||||
delayLine.process(audioBuffer);
|
||||
|
||||
Assert.floatEquals(0.2, audioBuffer.getChannelView(0)[0]);
|
||||
Assert.floatEquals(0.8, audioBuffer.getChannelView(0)[1]);
|
||||
|
||||
Assert.floatEquals(0.6, audioBuffer.getChannelView(1)[3]);
|
||||
Assert.floatEquals(0.4, audioBuffer.getChannelView(1)[4]);
|
||||
}
|
||||
}
|
102
lib/aura/Tests/auratests/dsp/TestSparseConvolver.hx
Normal file
102
lib/aura/Tests/auratests/dsp/TestSparseConvolver.hx
Normal file
@ -0,0 +1,102 @@
|
||||
package auratests.dsp;
|
||||
|
||||
import utest.Assert;
|
||||
|
||||
import kha.arrays.Float32Array;
|
||||
|
||||
import aura.Aura;
|
||||
import aura.dsp.SparseConvolver;
|
||||
import aura.types.AudioBuffer;
|
||||
import aura.utils.TestSignals;
|
||||
|
||||
@:access(aura.dsp.SparseConvolver)
|
||||
class TestSparseConvolver extends utest.Test {
|
||||
var audioBuffer: AudioBuffer;
|
||||
var sparseConvolver: SparseConvolver;
|
||||
|
||||
function setup() {
|
||||
audioBuffer = new AudioBuffer(2, 512);
|
||||
sparseConvolver = new SparseConvolver(1, 4);
|
||||
}
|
||||
|
||||
function test_simpleDelay() {
|
||||
for (i in 0...audioBuffer.channelLength) {
|
||||
audioBuffer.getChannelView(0)[i] = Math.sin(i * 2 * Math.PI / audioBuffer.channelLength);
|
||||
audioBuffer.getChannelView(1)[i] = Math.cos(i * 2 * Math.PI / audioBuffer.channelLength);
|
||||
}
|
||||
|
||||
final impulse = sparseConvolver.impulseBuffer;
|
||||
impulse.setImpulsePos(0, 3);
|
||||
impulse.setImpulseMagnitude(0, 1.0);
|
||||
|
||||
sparseConvolver.process(audioBuffer);
|
||||
|
||||
final wanted = new AudioBuffer(2, audioBuffer.channelLength);
|
||||
for (i in 0...wanted.channelLength) {
|
||||
wanted.getChannelView(0)[i] = Math.sin((i - 3) * 2 * Math.PI / wanted.channelLength);
|
||||
wanted.getChannelView(1)[i] = Math.cos((i - 3) * 2 * Math.PI / wanted.channelLength);
|
||||
}
|
||||
|
||||
for (i in 0...3) {
|
||||
Assert.floatEquals(0, audioBuffer.getChannelView(0)[i]);
|
||||
Assert.floatEquals(0, audioBuffer.getChannelView(1)[i]);
|
||||
}
|
||||
|
||||
for (i in 3...wanted.channelLength) {
|
||||
Assert.floatEquals(wanted.getChannelView(0)[i], audioBuffer.getChannelView(0)[i]);
|
||||
Assert.floatEquals(wanted.getChannelView(1)[i], audioBuffer.getChannelView(1)[i]);
|
||||
}
|
||||
|
||||
// Overlap
|
||||
audioBuffer.clear();
|
||||
sparseConvolver.process(audioBuffer);
|
||||
for (i in 0...3) {
|
||||
Assert.floatEquals(wanted.getChannelView(0)[i], audioBuffer.getChannelView(0)[i]);
|
||||
Assert.floatEquals(wanted.getChannelView(1)[i], audioBuffer.getChannelView(1)[i]);
|
||||
}
|
||||
for (i in 3...wanted.channelLength) {
|
||||
Assert.floatEquals(0, audioBuffer.getChannelView(0)[i]);
|
||||
Assert.floatEquals(0, audioBuffer.getChannelView(1)[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@:access(aura.dsp.SparseConvolver.SparseImpulseBuffer)
|
||||
class TestSparseImpulseBuffer extends utest.Test {
|
||||
var buffer: SparseImpulseBuffer;
|
||||
|
||||
function setup() {
|
||||
buffer = new SparseImpulseBuffer(4);
|
||||
}
|
||||
|
||||
function test_length() {
|
||||
Assert.equals(1, new SparseImpulseBuffer(1).length);
|
||||
Assert.equals(2, new SparseImpulseBuffer(2).length);
|
||||
Assert.equals(3, new SparseImpulseBuffer(3).length);
|
||||
Assert.equals(1024, new SparseImpulseBuffer(1024).length);
|
||||
}
|
||||
|
||||
function test_impulsePos_notOverwrittenByOtherImpulses() {
|
||||
buffer.setImpulsePos(0, 3);
|
||||
buffer.setImpulsePos(1, 9);
|
||||
buffer.setImpulsePos(2, 17);
|
||||
buffer.setImpulsePos(3, 42);
|
||||
|
||||
Assert.equals(3, buffer.getImpulsePos(0));
|
||||
Assert.equals(9, buffer.getImpulsePos(1));
|
||||
Assert.equals(17, buffer.getImpulsePos(2));
|
||||
Assert.equals(42, buffer.getImpulsePos(3));
|
||||
}
|
||||
|
||||
function test_impulseMagnitude_notOverwrittenByOtherImpulses() {
|
||||
buffer.setImpulseMagnitude(0, 0.3);
|
||||
buffer.setImpulseMagnitude(1, 0.9);
|
||||
buffer.setImpulseMagnitude(2, 0.17);
|
||||
buffer.setImpulseMagnitude(3, 0.42);
|
||||
|
||||
Assert.floatEquals(0.3, buffer.getImpulseMagnitude(0));
|
||||
Assert.floatEquals(0.9, buffer.getImpulseMagnitude(1));
|
||||
Assert.floatEquals(0.17, buffer.getImpulseMagnitude(2));
|
||||
Assert.floatEquals(0.42, buffer.getImpulseMagnitude(3));
|
||||
}
|
||||
}
|
283
lib/aura/Tests/auratests/dsp/panner/TestPanner.hx
Normal file
283
lib/aura/Tests/auratests/dsp/panner/TestPanner.hx
Normal file
@ -0,0 +1,283 @@
|
||||
package auratests.dsp.panner;
|
||||
|
||||
import utest.Assert;
|
||||
|
||||
import aura.Aura;
|
||||
import aura.Time;
|
||||
import aura.dsp.panner.Panner;
|
||||
import aura.math.Vec3;
|
||||
import aura.types.AudioBuffer;
|
||||
|
||||
import Utils;
|
||||
|
||||
private class NonAbstractPanner extends Panner {
|
||||
public function process(buffer: AudioBuffer) {}
|
||||
}
|
||||
|
||||
@:access(aura.channels.BaseChannel)
|
||||
@:access(aura.channels.BaseChannelHandle)
|
||||
@:access(aura.dsp.panner.Panner)
|
||||
class TestPanner extends utest.Test {
|
||||
var handle: BaseChannelHandle;
|
||||
var panner: Panner;
|
||||
|
||||
function setup() {
|
||||
handle = Utils.createDummyHandle();
|
||||
panner = new NonAbstractPanner(handle);
|
||||
}
|
||||
|
||||
function teardown() {
|
||||
Time.overrideTime = null;
|
||||
}
|
||||
|
||||
function test_setLocation_multipleCallsOnFirstTimestep() {
|
||||
Time.overrideTime = 0.0;
|
||||
panner.setLocation(new Vec3(0.5, 0.6, 0.7));
|
||||
|
||||
Assert.floatEquals(0.5, panner.location.x);
|
||||
Assert.floatEquals(0.6, panner.location.y);
|
||||
Assert.floatEquals(0.7, panner.location.z);
|
||||
|
||||
Assert.floatEquals(0.0, panner.velocity.x);
|
||||
Assert.floatEquals(0.0, panner.velocity.y);
|
||||
Assert.floatEquals(0.0, panner.velocity.z);
|
||||
|
||||
Time.overrideTime = 0.0;
|
||||
panner.setLocation(new Vec3(1.0, 2.0, 3.0));
|
||||
|
||||
Assert.floatEquals(1.0, panner.location.x);
|
||||
Assert.floatEquals(2.0, panner.location.y);
|
||||
Assert.floatEquals(3.0, panner.location.z);
|
||||
|
||||
Assert.floatEquals(0.0, panner.velocity.x);
|
||||
Assert.floatEquals(0.0, panner.velocity.y);
|
||||
Assert.floatEquals(0.0, panner.velocity.z);
|
||||
}
|
||||
|
||||
function test_setLocation_firstCall_timeDeltaZero() {
|
||||
Time.overrideTime = 0.0;
|
||||
panner.setLocation(new Vec3(0.5, 0.6, 0.7));
|
||||
|
||||
Assert.floatEquals(0.5, panner.location.x);
|
||||
Assert.floatEquals(0.6, panner.location.y);
|
||||
Assert.floatEquals(0.7, panner.location.z);
|
||||
|
||||
Assert.floatEquals(0.0, panner.velocity.x);
|
||||
Assert.floatEquals(0.0, panner.velocity.y);
|
||||
Assert.floatEquals(0.0, panner.velocity.z);
|
||||
}
|
||||
|
||||
function test_setLocation_firstCall_timeDeltaPositive() {
|
||||
Time.overrideTime = 2.0;
|
||||
panner.setLocation(new Vec3(0.5, 0.6, 0.7));
|
||||
|
||||
Assert.floatEquals(0.5, panner.location.x);
|
||||
Assert.floatEquals(0.6, panner.location.y);
|
||||
Assert.floatEquals(0.7, panner.location.z);
|
||||
|
||||
Assert.floatEquals(0.0, panner.velocity.x);
|
||||
Assert.floatEquals(0.0, panner.velocity.y);
|
||||
Assert.floatEquals(0.0, panner.velocity.z);
|
||||
}
|
||||
|
||||
function test_setLocation_subsequentCalls_timeDeltaZero() {
|
||||
// Regression test for https://github.com/MoritzBrueckner/aura/pull/8
|
||||
|
||||
Time.overrideTime = 1.0;
|
||||
panner.setLocation(new Vec3(0.0, 0.0, 0.0));
|
||||
|
||||
Time.overrideTime = 3.0;
|
||||
panner.setLocation(new Vec3(1.0, 2.0, 3.0));
|
||||
|
||||
Time.overrideTime = 3.0;
|
||||
panner.setLocation(new Vec3(2.0, 4.0, 6.0));
|
||||
|
||||
Assert.floatEquals(2.0, panner.location.x);
|
||||
Assert.floatEquals(4.0, panner.location.y);
|
||||
Assert.floatEquals(6.0, panner.location.z);
|
||||
|
||||
// Compute velocity based on timestep 1.0
|
||||
Assert.floatEquals(1.0, panner.velocity.x);
|
||||
Assert.floatEquals(2.0, panner.velocity.y);
|
||||
Assert.floatEquals(3.0, panner.velocity.z);
|
||||
}
|
||||
|
||||
function test_update3D_noDopplerJumpIfLocationWasUninitialized() {
|
||||
Time.overrideTime = 0.0;
|
||||
panner.setLocation(new Vec3(20.0, 0.0, 0.0));
|
||||
panner.update3D();
|
||||
|
||||
handle.channel.synchronize();
|
||||
Assert.floatEquals(1.0, handle.channel.pDopplerRatio.targetValue);
|
||||
}
|
||||
|
||||
function test_noDopplerEffect_ifNoMovement() {
|
||||
Time.overrideTime = 0.0;
|
||||
aura.Aura.listener.setLocation(new Vec3(0.0, 0.0, 0.0));
|
||||
panner.setLocation(new Vec3(5.0, 4.0, 3.0));
|
||||
panner.update3D();
|
||||
|
||||
Time.overrideTime = 0.5;
|
||||
aura.Aura.listener.setLocation(new Vec3(0.0, 0.0, 0.0));
|
||||
panner.setLocation(new Vec3(5.0, 4.0, 3.0));
|
||||
panner.update3D();
|
||||
|
||||
handle.channel.synchronize();
|
||||
Assert.floatEquals(1.0, handle.channel.pDopplerRatio.targetValue);
|
||||
}
|
||||
|
||||
function test_calculateDoppler_physicallyCorrectValues_pannerMovesAway() {
|
||||
Time.overrideTime = 0.0;
|
||||
aura.Aura.listener.setLocation(new Vec3(0.0, 0.0, 0.0));
|
||||
panner.setLocation(new Vec3(0.0, 0.0, 0.0));
|
||||
panner.update3D();
|
||||
|
||||
Time.overrideTime = 0.5;
|
||||
aura.Aura.listener.setLocation(new Vec3(0.0, 0.0, 0.0));
|
||||
panner.setLocation(new Vec3(2.0, 0.0, 0.0));
|
||||
panner.update3D();
|
||||
|
||||
Assert.floatEquals(4.0, @:privateAccess panner.velocity.length);
|
||||
Assert.floatEquals(0.0, @:privateAccess aura.Aura.listener.velocity.length);
|
||||
|
||||
handle.channel.synchronize();
|
||||
|
||||
// Values calculated at
|
||||
// https://www.omnicalculator.com/physics/doppler-effect?c=EUR&v=f0:5000!Hz,v:343.4!ms,vs:2!ms,vr:0!ms
|
||||
// Assuming that their implementation is correct
|
||||
Assert.floatEquals(4942.43 / 5000, handle.channel.pDopplerRatio.targetValue);
|
||||
}
|
||||
|
||||
function test_calculateDoppler_physicallyCorrectValues_listenerMovesAway() {
|
||||
Time.overrideTime = 0.0;
|
||||
aura.Aura.listener.setLocation(new Vec3(0.0, 0.0, 0.0));
|
||||
panner.setLocation(new Vec3(0.0, 0.0, 0.0));
|
||||
panner.update3D();
|
||||
|
||||
Time.overrideTime = 0.5;
|
||||
aura.Aura.listener.setLocation(new Vec3(2.0, 0.0, 0.0));
|
||||
panner.setLocation(new Vec3(0.0, 0.0, 0.0));
|
||||
panner.update3D();
|
||||
|
||||
Assert.floatEquals(4.0, @:privateAccess aura.Aura.listener.velocity.length);
|
||||
Assert.floatEquals(0.0, @:privateAccess panner.velocity.length);
|
||||
|
||||
handle.channel.synchronize();
|
||||
|
||||
Assert.floatEquals(4941.76 / 5000, handle.channel.pDopplerRatio.targetValue);
|
||||
}
|
||||
|
||||
function test_calculateDoppler_physicallyCorrectValues_pannerMovesCloser() {
|
||||
Time.overrideTime = 0.0;
|
||||
aura.Aura.listener.setLocation(new Vec3(0.0, 0.0, 0.0));
|
||||
panner.setLocation(new Vec3(4.0, 0.0, 0.0));
|
||||
panner.update3D();
|
||||
|
||||
Time.overrideTime = 0.5;
|
||||
aura.Aura.listener.setLocation(new Vec3(0.0, 0.0, 0.0));
|
||||
panner.setLocation(new Vec3(2.0, 0.0, 0.0));
|
||||
panner.update3D();
|
||||
|
||||
Assert.floatEquals(4.0, @:privateAccess panner.velocity.length);
|
||||
Assert.floatEquals(0.0, @:privateAccess aura.Aura.listener.velocity.length);
|
||||
|
||||
handle.channel.synchronize();
|
||||
|
||||
Assert.floatEquals(5058.93 / 5000, handle.channel.pDopplerRatio.targetValue);
|
||||
}
|
||||
|
||||
function test_calculateDoppler_physicallyCorrectValues_listenerMovesCloser() {
|
||||
Time.overrideTime = 0.0;
|
||||
aura.Aura.listener.setLocation(new Vec3(4.0, 0.0, 0.0));
|
||||
panner.setLocation(new Vec3(0.0, 0.0, 0.0));
|
||||
panner.update3D();
|
||||
|
||||
Time.overrideTime = 0.5;
|
||||
aura.Aura.listener.setLocation(new Vec3(2.0, 0.0, 0.0));
|
||||
panner.setLocation(new Vec3(0.0, 0.0, 0.0));
|
||||
panner.update3D();
|
||||
|
||||
Assert.floatEquals(4.0, @:privateAccess aura.Aura.listener.velocity.length);
|
||||
Assert.floatEquals(0.0, @:privateAccess panner.velocity.length);
|
||||
|
||||
handle.channel.synchronize();
|
||||
|
||||
Assert.floatEquals(5058.24 / 5000, handle.channel.pDopplerRatio.targetValue);
|
||||
}
|
||||
|
||||
function test_calculateDoppler_noDopplerEffectIfNoRadialVelocity() {
|
||||
Time.overrideTime = 0.0;
|
||||
aura.Aura.listener.setLocation(new Vec3(0.0, 0.0, 0.0));
|
||||
panner.setLocation(new Vec3(2.0, 0.0, 0.0));
|
||||
panner.update3D();
|
||||
|
||||
Time.overrideTime = 0.5;
|
||||
aura.Aura.listener.setLocation(new Vec3(0.0, 0.0, 0.0));
|
||||
panner.setLocation(new Vec3(0.0, 0.0, 0.0));
|
||||
panner.update3D();
|
||||
|
||||
handle.channel.synchronize();
|
||||
|
||||
Assert.floatEquals(1, handle.channel.pDopplerRatio.targetValue);
|
||||
}
|
||||
|
||||
function test_calculateDoppler_noDopplerEffectIfNoRadialVelocity2() {
|
||||
Time.overrideTime = 0.0;
|
||||
aura.Aura.listener.setLocation(new Vec3(5.0, 0.0, 0.0));
|
||||
panner.setLocation(new Vec3(5.0, 0.0, 0.0));
|
||||
panner.update3D();
|
||||
|
||||
Time.overrideTime = 0.5;
|
||||
aura.Aura.listener.setLocation(new Vec3(5.0, 0.0, 0.0));
|
||||
panner.setLocation(new Vec3(5.0, 0.0, 0.0));
|
||||
panner.update3D();
|
||||
|
||||
handle.channel.synchronize();
|
||||
|
||||
Assert.floatEquals(1, handle.channel.pDopplerRatio.targetValue);
|
||||
}
|
||||
|
||||
function test_calculateDoppler_noDopplerEffectIfNoRadialVelocity3() {
|
||||
Time.overrideTime = 0.0;
|
||||
aura.Aura.listener.setLocation(new Vec3(0.0, 0.0, 0.0));
|
||||
panner.setLocation(new Vec3(2.0, 2.0, 0.0));
|
||||
panner.update3D();
|
||||
|
||||
Time.overrideTime = 0.5;
|
||||
aura.Aura.listener.setLocation(new Vec3(0.0, 0.0, 0.0));
|
||||
panner.setLocation(new Vec3(0.0, 2.0, 0.0));
|
||||
panner.update3D();
|
||||
|
||||
handle.channel.synchronize();
|
||||
|
||||
Assert.floatEquals(1, handle.channel.pDopplerRatio.targetValue);
|
||||
}
|
||||
|
||||
function test_dopplerEffect_isZeroIfPannerMovesCloserAtSpeedOfSound() {
|
||||
Time.overrideTime = 0.0;
|
||||
panner.setLocation(new Vec3(Panner.SPEED_OF_SOUND + 1, 0.0, 0.0));
|
||||
panner.update3D();
|
||||
|
||||
Time.overrideTime = 1.0;
|
||||
panner.setLocation(new Vec3(1, 0.0, 0.0));
|
||||
panner.update3D();
|
||||
|
||||
handle.channel.synchronize();
|
||||
|
||||
Assert.floatEquals(0, handle.channel.pDopplerRatio.targetValue);
|
||||
}
|
||||
|
||||
function test_dopplerEffect_pannerMovesCloserAboveSpeedOfSound() {
|
||||
Time.overrideTime = 0.0;
|
||||
panner.setLocation(new Vec3(Panner.SPEED_OF_SOUND + 5, 0.0, 0.0));
|
||||
panner.update3D();
|
||||
|
||||
Time.overrideTime = 1.0;
|
||||
panner.setLocation(new Vec3(1, 0.0, 0.0));
|
||||
panner.update3D();
|
||||
|
||||
handle.channel.synchronize();
|
||||
|
||||
Assert.floatEquals(-85.85, handle.channel.pDopplerRatio.targetValue);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user