1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
package se.lublin.humla.test;
import junit.framework.TestCase;
import java.util.ArrayList;
import java.util.List;
import se.lublin.humla.audio.BasicClippingShortMixer;
import se.lublin.humla.audio.IAudioMixer;
import se.lublin.humla.audio.IAudioMixerSource;
/**
* Created by andrew on 16/07/15.
*/
public class MixerTest extends TestCase {
/**
* Tests that mixing order should not affect the output.
*/
public void testMixerCommutativity(IAudioMixer<float[], short[]> mixer) {
BasicSource<float[]> pcmA = new BasicSource<>(new float[] { 0.2f, 0.5f, 0.7f }, 3);
BasicSource<float[]> pcmB = new BasicSource<>(new float[] { 0.3f, 0.5f, 0.5f }, 3);
BasicSource<float[]> pcmC = new BasicSource<>(new float[] { 0.0f, 0.0f, -0.5f }, 3);
final short[] outputABC = new short[3];
final short[] outputCBA = new short[3];
List<IAudioMixerSource<float[]>> sourcesABC = new ArrayList<>();
sourcesABC.add(pcmA);
sourcesABC.add(pcmB);
sourcesABC.add(pcmC);
List<IAudioMixerSource<float[]>> sourcesCBA = new ArrayList<>();
sourcesCBA.add(pcmC);
sourcesCBA.add(pcmB);
sourcesCBA.add(pcmA);
mixer.mix(sourcesABC, outputABC, 0, 3);
mixer.mix(sourcesCBA, outputCBA, 0, 3);
for (int i = 0; i < 3; i++) {
assertEquals("Mixing should be commutative.", outputABC[i], outputCBA[i]);
}
}
public void testBasicClippingShortMixer() {
testMixerCommutativity(new BasicClippingShortMixer());
}
private static class BasicSource<T> implements IAudioMixerSource<T> {
private T mSamples;
private int mLength;
public BasicSource(T samples, int length) {
mSamples = samples;
mLength = length;
}
@Override
public T getSamples() {
return mSamples;
}
@Override
public int getNumSamples() {
return mLength;
}
}
}
|