To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / yetilab / stream / test / test_audiofile.yeti @ 225:8e04d298741b
History | View | Annotate | Download (1.74 KB)
| 1 |
|
|---|---|
| 2 |
module yetilab.stream.test.test_audiofile; |
| 3 |
|
| 4 |
af = load yetilab.stream.audiofile; |
| 5 |
vec = load yetilab.vector.vector; |
| 6 |
mat = load yetilab.matrix.matrix; |
| 7 |
|
| 8 |
ref = load yetilab.stream.test.audiofile_reference; |
| 9 |
|
| 10 |
{ compare, compareUsing } = load yetilab.test.test;
|
| 11 |
|
| 12 |
testfile name = "yetilab/test/data/\(name).wav"; |
| 13 |
|
| 14 |
float n is number -> number = |
| 15 |
// round number to float precision (for comparison with floats) |
| 16 |
(arr = new float[1]; |
| 17 |
arr[0] := n; |
| 18 |
arr[0]); |
| 19 |
|
| 20 |
readAll stream = |
| 21 |
case stream.available of |
| 22 |
Known n: stream.read n; |
| 23 |
_: failWith "Known-duration stream required"; |
| 24 |
esac; |
| 25 |
|
| 26 |
testReferenceFile rate channels bitdepth = |
| 27 |
(test = readAll (af.open (testfile "\(rate)-\(channels)-\(bitdepth)")); |
| 28 |
ref = readAll (ref.afReference rate channels); |
| 29 |
compareUsing mat.equal test ref); |
| 30 |
|
| 31 |
[ |
| 32 |
|
| 33 |
"20samples-open": \( |
| 34 |
f = af.open (testfile "20samples"); |
| 35 |
compare f.position 0 and |
| 36 |
compare f.channels 1 and |
| 37 |
compare f.sampleRate 44100 and |
| 38 |
compare f.available (Known 20) and |
| 39 |
compare f.finished? false and |
| 40 |
( f.close () ; true ) |
| 41 |
), |
| 42 |
|
| 43 |
"20samples-read": \( |
| 44 |
all id (map do opener: |
| 45 |
f = opener (testfile "20samples"); |
| 46 |
first15 = f.read 15; |
| 47 |
last5 = f.read 10; |
| 48 |
compare (mat.size first15) { rows = 1, columns = 15 } and
|
| 49 |
compare (mat.size last5) { rows = 1, columns = 5 } and
|
| 50 |
compare (vec.list (mat.getRow 0 first15)) |
| 51 |
[ float (32767/32768),0,0,0,0,0,0,0,0,0,0,0,0,0,0 ] and |
| 52 |
compare (vec.list (mat.getRow 0 last5)) [ 0,0,0,0,-1 ] and |
| 53 |
( f.close () ; true ) |
| 54 |
done [ af.open, af.openMono ]); |
| 55 |
), |
| 56 |
|
| 57 |
"8000-1-8": \( |
| 58 |
testReferenceFile 8000 1 8; |
| 59 |
), |
| 60 |
|
| 61 |
"44100-2-16": \( |
| 62 |
testReferenceFile 44100 2 16; |
| 63 |
), |
| 64 |
|
| 65 |
] is hash<string, () -> boolean> |
| 66 |
|