To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Revision:

root / src / may / stream / test / test_waves.yeti @ 600:956074cc1f7c

History | View | Annotate | Download (2.58 KB)

1

    
2
module may.stream.test.test_waves;
3

    
4
wav = load may.stream.waves;
5
mat = load may.matrix;
6
vec = load may.vector;
7

    
8
plt = load may.plot;
9

    
10
{ compare, compareUsing, compareMatrices, assert } = load may.test;
11

    
12
compareApprox eps =
13
    compareUsing do v1 v2: all id (map2 do f1 f2: abs (f1 - f2) < eps done v1 v2) done;
14

    
15
epsilon = 0.000001;
16

    
17
[
18

    
19
"square": \(
20
    compareMatrices 1e-8 ((wav.square 4 1).read 10)
21
       (mat.newRowVector (vec.fromList
22
           [0,1,0,-1,0,1,0,-1,0,1])) and
23
    compareMatrices 1e-6 ((wav.square 8 1).read 14)
24
       (mat.newRowVector (vec.fromList
25
           [0, 0.942809, 0.666666, 0.942809,
26
            0,-0.942809,-0.666666,-0.942809,
27
            0, 0.942809, 0.666666, 0.942809,
28
            0,-0.942809]))
29
),
30

    
31
"impulseTrain-naive": \(
32
    // 2 pulses a second sampled 8 times a second (naive pulse train)
33
    str = wav.impulseTrain 8 2;
34
    compare str.position 0 and
35
        compare str.channels 1 and
36
        compare str.sampleRate 8 and
37
        compare str.available (Infinite ()) and
38
        compare str.finished? false and
39
        compareApprox epsilon (vec.list (mat.getRow 0 (str.read 9))) [ 0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5 ] and
40
        compare str.position 9
41
),
42

    
43
"impulseTrain-naive-frac": \(
44
    // 2.5 pulses a second sampled 10 times a second (still a naive
45
    // pulse train even though the pulse rate is non-integer)
46
    str = wav.impulseTrain 10 2.5;
47
    compare str.position 0 and
48
        compare str.channels 1 and
49
        compare str.sampleRate 10 and
50
        compare str.available (Infinite ()) and
51
        compare str.finished? false and
52
        compareApprox epsilon (vec.list (mat.getRow 0 (str.read 11))) [ 0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0 ] and
53
        compare str.position 11
54
),
55
/*
56
"impulseTrain-bandlimited": \(
57
    // 3 pulses a second sampled 10 times a second
58
    str = wav.impulseTrain 100 3;
59

    
60
    x = mat.getRow 0 (str.read 200);
61
false; //!!! todo
62
*/
63
/*
64
    compare str.position 0 and
65
        compare str.channels 1 and
66
        compare str.sampleRate 8 and
67
        compare str.available (Infinite ()) and
68
        compare str.finished? false and
69
        compareApprox epsilon (vec.list (mat.getRow 0 (str.read 14)))
70
            [ 0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0, 0, 0, 0.5, 0 ] and
71
        compare str.position 14
72
*/
73
//),
74

    
75
"cycleLengthFor": \(
76
    compare (wav.cycleLengthFor 48000 1000) 48 and
77
    compare (wav.cycleLengthFor 44100 1000) 441 and
78
    compare (wav.cycleLengthFor 48000 1) 48000 and
79
    compare (wav.cycleLengthFor 48000 0.5) 96000 and
80
    compare (wav.cycleLengthFor 3 2) 3 and
81
    compare (wav.cycleLengthFor 2.5 1) 5
82
),
83

    
84
] is hash<string, () -> boolean>;
85