forked from LeenkxTeam/LNXSDK
Update Files
This commit is contained in:
42
lib/aura/Tests/auratests/utils/TestCircularBuffer.hx
Normal file
42
lib/aura/Tests/auratests/utils/TestCircularBuffer.hx
Normal file
@ -0,0 +1,42 @@
|
||||
package auratests.utils;
|
||||
|
||||
import utest.Assert;
|
||||
|
||||
import kha.arrays.Float32Array;
|
||||
|
||||
import aura.utils.BufferUtils;
|
||||
import aura.utils.CircularBuffer;
|
||||
|
||||
import Utils;
|
||||
|
||||
@:access(aura.utils.CircularBuffer)
|
||||
class TestCircularBuffer extends utest.Test {
|
||||
var buffer: CircularBuffer;
|
||||
|
||||
function setup() {
|
||||
buffer = new CircularBuffer(8);
|
||||
}
|
||||
|
||||
function teardown() {}
|
||||
|
||||
function test_new_assertThatSizeIsPositiveNumber() {
|
||||
assertRaisesAssertion(() -> {
|
||||
new CircularBuffer(0);
|
||||
});
|
||||
|
||||
assertRaisesAssertion(() -> {
|
||||
new CircularBuffer(-1);
|
||||
});
|
||||
}
|
||||
|
||||
function test_new_dataInitializedToZero() {
|
||||
// Please note that this test always succeeds on JS and has additional
|
||||
// false negatives on other targets, there the test still succeeds if data
|
||||
// is not actively initialized but the values are still 0
|
||||
// TODO If Aura has it's own array types at some point in time, implement
|
||||
// active poisoning of values if unit tests are run
|
||||
|
||||
final compareArray = createEmptyF32Array(buffer.length);
|
||||
assertEqualsFloat32Array(compareArray, buffer.data);
|
||||
}
|
||||
}
|
110
lib/aura/Tests/auratests/utils/TestLinearInterpolator.hx
Normal file
110
lib/aura/Tests/auratests/utils/TestLinearInterpolator.hx
Normal file
@ -0,0 +1,110 @@
|
||||
package auratests.utils;
|
||||
|
||||
import kha.simd.Float32x4;
|
||||
import utest.Assert;
|
||||
|
||||
import aura.types.AudioBuffer.AudioBufferChannelView;
|
||||
import aura.utils.Interpolator.LinearInterpolator;
|
||||
|
||||
class TestLinearInterpolator extends utest.Test {
|
||||
static inline var NUM_SAMPLES = 8;
|
||||
|
||||
function test_isInitializedToTargetValue() {
|
||||
final interp = new LinearInterpolator(0.0);
|
||||
|
||||
Assert.floatEquals(0.0, interp.currentValue);
|
||||
Assert.floatEquals(0.0, interp.lastValue);
|
||||
Assert.floatEquals(0.0, interp.targetValue);
|
||||
}
|
||||
|
||||
function test_stepSizeIsCorrectForPositiveSteps() {
|
||||
final interp = new LinearInterpolator(0.0);
|
||||
interp.targetValue = 4.0;
|
||||
|
||||
final stepSize = interp.getLerpStepSize(NUM_SAMPLES);
|
||||
Assert.floatEquals(0.5, stepSize);
|
||||
}
|
||||
|
||||
function test_stepSizeIsCorrectForNegativeSteps() {
|
||||
final interp = new LinearInterpolator(0.0);
|
||||
interp.targetValue = -4.0;
|
||||
|
||||
final stepSize = interp.getLerpStepSize(NUM_SAMPLES);
|
||||
Assert.floatEquals(-0.5, stepSize);
|
||||
}
|
||||
|
||||
function test_stepsReachTargetValue() {
|
||||
final interp = new LinearInterpolator(0.0);
|
||||
interp.targetValue = 4.0;
|
||||
|
||||
final stepSize = interp.getLerpStepSize(NUM_SAMPLES);
|
||||
|
||||
for (_ in 0...NUM_SAMPLES) {
|
||||
interp.currentValue += stepSize;
|
||||
}
|
||||
|
||||
Assert.floatEquals(interp.targetValue, interp.currentValue);
|
||||
}
|
||||
|
||||
function test_updateLastUpdatesLastAndCurrentValue() {
|
||||
final interp = new LinearInterpolator(0.0);
|
||||
|
||||
interp.targetValue = 4.0;
|
||||
|
||||
interp.updateLast();
|
||||
Assert.floatEquals(interp.targetValue, interp.lastValue);
|
||||
Assert.floatEquals(interp.targetValue, interp.currentValue);
|
||||
}
|
||||
|
||||
function test_getLerpStepSizes32x4IsCorrectForPositiveSteps() {
|
||||
final interp = new LinearInterpolator(0.0);
|
||||
|
||||
interp.targetValue = 4.0;
|
||||
final stepSizes = interp.getLerpStepSizes32x4(NUM_SAMPLES);
|
||||
|
||||
Assert.floatEquals(0.5, Float32x4.getFast(stepSizes, 0));
|
||||
Assert.floatEquals(1.0, Float32x4.getFast(stepSizes, 1));
|
||||
Assert.floatEquals(1.5, Float32x4.getFast(stepSizes, 2));
|
||||
Assert.floatEquals(2.0, Float32x4.getFast(stepSizes, 3));
|
||||
}
|
||||
|
||||
function test_getLerpStepSizes32x4IsCorrectForNegativeSteps() {
|
||||
final interp = new LinearInterpolator(0.0);
|
||||
|
||||
interp.targetValue = -4.0;
|
||||
final stepSizes = interp.getLerpStepSizes32x4(NUM_SAMPLES);
|
||||
|
||||
Assert.floatEquals(-0.5, Float32x4.getFast(stepSizes, 0));
|
||||
Assert.floatEquals(-1.0, Float32x4.getFast(stepSizes, 1));
|
||||
Assert.floatEquals(-1.5, Float32x4.getFast(stepSizes, 2));
|
||||
Assert.floatEquals(-2.0, Float32x4.getFast(stepSizes, 3));
|
||||
}
|
||||
|
||||
function test_applySIMD32x4() {
|
||||
final samples = new AudioBufferChannelView(NUM_SAMPLES);
|
||||
for (i in 0...NUM_SAMPLES) {
|
||||
samples[i] = 1.0;
|
||||
}
|
||||
|
||||
final interp = new LinearInterpolator(0.0);
|
||||
interp.targetValue = 4.0;
|
||||
|
||||
final stepSizes = interp.getLerpStepSizes32x4(NUM_SAMPLES);
|
||||
|
||||
interp.applySIMD32x4(samples, 0, stepSizes);
|
||||
Assert.floatEquals(0.5, samples[0]);
|
||||
Assert.floatEquals(1.0, samples[1]);
|
||||
Assert.floatEquals(1.5, samples[2]);
|
||||
Assert.floatEquals(2.0, samples[3]);
|
||||
|
||||
Assert.floatEquals(2.0, interp.currentValue);
|
||||
|
||||
interp.applySIMD32x4(samples, 4, stepSizes);
|
||||
Assert.floatEquals(2.5, samples[4]);
|
||||
Assert.floatEquals(3.0, samples[5]);
|
||||
Assert.floatEquals(3.5, samples[6]);
|
||||
Assert.floatEquals(4.0, samples[7]);
|
||||
|
||||
Assert.floatEquals(4.0, interp.currentValue);
|
||||
}
|
||||
}
|
26
lib/aura/Tests/auratests/utils/TestMathUtils.hx
Normal file
26
lib/aura/Tests/auratests/utils/TestMathUtils.hx
Normal file
@ -0,0 +1,26 @@
|
||||
package auratests.utils;
|
||||
|
||||
import utest.Assert;
|
||||
|
||||
import aura.utils.MathUtils;
|
||||
|
||||
class TestMathUtils extends utest.Test {
|
||||
|
||||
function test_maxMin() {
|
||||
Assert.equals(18, minI(42, 18));
|
||||
Assert.equals(18, minI(18, 42));
|
||||
Assert.equals(-99, minI(-99, 42));
|
||||
|
||||
Assert.equals(42, maxI(42, 18));
|
||||
Assert.equals(42, maxI(18, 42));
|
||||
Assert.equals(42, maxI(-99, 42));
|
||||
|
||||
Assert.equals(3.14, minF(3.14, 11.11));
|
||||
Assert.equals(3.14, minF(11.11, 3.14));
|
||||
Assert.equals(-28.1, minF(-28.1, 3.07));
|
||||
|
||||
Assert.equals(11.11, maxF(3.14, 11.11));
|
||||
Assert.equals(11.11, maxF(11.11, 3.14));
|
||||
Assert.equals(3.07, maxF(-28.1, 3.07));
|
||||
}
|
||||
}
|
82
lib/aura/Tests/auratests/utils/TestResampler.hx
Normal file
82
lib/aura/Tests/auratests/utils/TestResampler.hx
Normal file
@ -0,0 +1,82 @@
|
||||
package auratests.utils;
|
||||
|
||||
import utest.Assert;
|
||||
|
||||
import kha.arrays.Float32Array;
|
||||
|
||||
import aura.utils.Resampler;
|
||||
|
||||
import Utils;
|
||||
|
||||
class TestResampler extends utest.Test {
|
||||
final sourceData = new Float32Array(4);
|
||||
final sourceSampleRate = 100;
|
||||
|
||||
function setupClass() {
|
||||
sourceData[0] = 0.0;
|
||||
sourceData[1] = 1.0;
|
||||
sourceData[2] = 2.0;
|
||||
sourceData[3] = 3.0;
|
||||
}
|
||||
|
||||
function test_getResampleLength() {
|
||||
Assert.equals(Std.int(sourceData.length / 2), Resampler.getResampleLength(sourceData.length, sourceSampleRate, Std.int(sourceSampleRate / 2)));
|
||||
Assert.equals(sourceData.length * 2, Resampler.getResampleLength(sourceData.length, sourceSampleRate, sourceSampleRate * 2));
|
||||
}
|
||||
|
||||
function test_sourceSamplePosToTargetPos() {
|
||||
Assert.floatEquals(1.0, Resampler.sourceSamplePosToTargetPos(2.0, 100, 50));
|
||||
Assert.floatEquals(4.0, Resampler.sourceSamplePosToTargetPos(2.0, 100, 200));
|
||||
}
|
||||
|
||||
function test_targetSamplePosToSourcePos() {
|
||||
Assert.floatEquals(4.0, Resampler.targetSamplePosToSourcePos(2.0, 100, 50));
|
||||
Assert.floatEquals(1.0, Resampler.targetSamplePosToSourcePos(2.0, 100, 200));
|
||||
}
|
||||
|
||||
function test_sampleAtTargetPositionLerp_SamplesExactValuesAtDiscretePositions() {
|
||||
Assert.floatEquals(0.0, Resampler.sampleAtTargetPositionLerp(sourceData, 0.0, sourceSampleRate, 100));
|
||||
Assert.floatEquals(1.0, Resampler.sampleAtTargetPositionLerp(sourceData, 1.0, sourceSampleRate, 100));
|
||||
}
|
||||
|
||||
function test_sampleAtTargetPositionLerp_InterpolatesLinearlyBetweenDiscreteSamples() {
|
||||
Assert.floatEquals(0.5, Resampler.sampleAtTargetPositionLerp(sourceData, 0.5, sourceSampleRate, 100));
|
||||
Assert.floatEquals(0.3, Resampler.sampleAtTargetPositionLerp(sourceData, 0.3, sourceSampleRate, 100));
|
||||
}
|
||||
|
||||
function test_sampleAtTargetPositionLerp_AssertsSamplePositionNotNegative() {
|
||||
assertRaisesAssertion(() -> {
|
||||
Resampler.sampleAtTargetPositionLerp(sourceData, -1.0, sourceSampleRate, 100);
|
||||
});
|
||||
}
|
||||
|
||||
function test_sampleAtTargetPositionLerp_ClampsValuesOutOfUpperDataBounds() {
|
||||
Assert.floatEquals(3.0, Resampler.sampleAtTargetPositionLerp(sourceData, 3.5, sourceSampleRate, 100));
|
||||
Assert.floatEquals(3.0, Resampler.sampleAtTargetPositionLerp(sourceData, 4.0, sourceSampleRate, 100));
|
||||
}
|
||||
|
||||
function test_sampleAtTargetPositionLerp_DifferentSampleRatesUsed() {
|
||||
Assert.floatEquals(0.0, Resampler.sampleAtTargetPositionLerp(sourceData, 0.0, sourceSampleRate, Std.int(sourceSampleRate / 2)));
|
||||
Assert.floatEquals(1.0, Resampler.sampleAtTargetPositionLerp(sourceData, 0.5, sourceSampleRate, Std.int(sourceSampleRate / 2)));
|
||||
Assert.floatEquals(2.0, Resampler.sampleAtTargetPositionLerp(sourceData, 1.0, sourceSampleRate, Std.int(sourceSampleRate / 2)));
|
||||
|
||||
Assert.floatEquals(0.0, Resampler.sampleAtTargetPositionLerp(sourceData, 0.0, sourceSampleRate, sourceSampleRate * 2));
|
||||
Assert.floatEquals(0.25, Resampler.sampleAtTargetPositionLerp(sourceData, 0.5, sourceSampleRate, sourceSampleRate * 2));
|
||||
Assert.floatEquals(0.5, Resampler.sampleAtTargetPositionLerp(sourceData, 1.0, sourceSampleRate, sourceSampleRate * 2));
|
||||
}
|
||||
|
||||
function test_resampleFloat32Array() {
|
||||
final targetData = new Float32Array(8);
|
||||
|
||||
Resampler.resampleFloat32Array(sourceData, 100, targetData, 200);
|
||||
|
||||
Assert.floatEquals(0.0, targetData[0]);
|
||||
Assert.floatEquals(0.5, targetData[1]);
|
||||
Assert.floatEquals(1.0, targetData[2]);
|
||||
Assert.floatEquals(1.5, targetData[3]);
|
||||
Assert.floatEquals(2.0, targetData[4]);
|
||||
Assert.floatEquals(2.5, targetData[5]);
|
||||
Assert.floatEquals(3.0, targetData[6]);
|
||||
Assert.floatEquals(3.0, targetData[7]); // Don't extrapolate data
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user