[d314636] | 1 | #include <stdio.h> |
---|
| 2 | #include <assert.h> |
---|
[7359775] | 3 | #define AUBIO_UNSTABLE 1 |
---|
[d314636] | 4 | #include <aubio.h> |
---|
| 5 | |
---|
[0546c1f3] | 6 | int test_next_power_of_two (void); |
---|
| 7 | int test_miditofreq (void); |
---|
| 8 | int test_freqtomidi (void); |
---|
| 9 | int test_aubio_window (void); |
---|
| 10 | |
---|
[158e031] | 11 | int test_next_power_of_two (void) |
---|
[7e35b37] | 12 | { |
---|
[7359775] | 13 | uint_t a, b; |
---|
[7e35b37] | 14 | a = 15; b = aubio_next_power_of_two(a); assert(b == 16); |
---|
| 15 | fprintf(stdout, "aubio_next_power_of_two(%d) = %d\n", a, b); |
---|
[d314636] | 16 | |
---|
[7e35b37] | 17 | a = 17; b = aubio_next_power_of_two(a); assert(b == 32); |
---|
| 18 | fprintf(stdout, "aubio_next_power_of_two(%d) = %d\n", a, b); |
---|
[d314636] | 19 | |
---|
[7e35b37] | 20 | a = 31; b = aubio_next_power_of_two(a); assert(b == 32); |
---|
| 21 | fprintf(stdout, "aubio_next_power_of_two(%d) = %d\n", a, b); |
---|
[d314636] | 22 | |
---|
[7e35b37] | 23 | a = 32; b = aubio_next_power_of_two(a); assert(b == 32); |
---|
| 24 | fprintf(stdout, "aubio_next_power_of_two(%d) = %d\n", a, b); |
---|
[d314636] | 25 | |
---|
[7e35b37] | 26 | a = 33; b = aubio_next_power_of_two(a); assert(b == 64); |
---|
| 27 | fprintf(stdout, "aubio_next_power_of_two(%d) = %d\n", a, b); |
---|
| 28 | |
---|
| 29 | return 0; |
---|
| 30 | } |
---|
| 31 | |
---|
[158e031] | 32 | int test_miditofreq (void) |
---|
[7e35b37] | 33 | { |
---|
[df9df98] | 34 | smpl_t a, b; |
---|
| 35 | fprintf(stdout, "b = aubio_miditofreq(a): ["); |
---|
| 36 | for ( a = -123.; a < 400.; a += 20. ) { |
---|
| 37 | b = aubio_miditofreq(a); |
---|
| 38 | fprintf(stdout, "(%.2f, %.2f), ", a, b); |
---|
[7e35b37] | 39 | } |
---|
[df9df98] | 40 | b = aubio_miditofreq(a); |
---|
| 41 | fprintf(stdout, "(%.2f, %.2f), ", a, b); |
---|
| 42 | a = -69.5; |
---|
| 43 | b = aubio_miditofreq(a); |
---|
| 44 | fprintf(stdout, "(%.2f, %.2f), ", a, b); |
---|
| 45 | a = -169.5; |
---|
| 46 | b = aubio_miditofreq(a); |
---|
| 47 | fprintf(stdout, "(%.2f, %.2f), ", a, b); |
---|
| 48 | a = 140.; |
---|
| 49 | b = aubio_miditofreq(a); |
---|
| 50 | fprintf(stdout, "(%.2f, %.2f), ", a, b); |
---|
| 51 | a = 0; |
---|
| 52 | b = aubio_miditofreq(a); |
---|
| 53 | fprintf(stdout, "(%.2f, %.2f), ", a, b); |
---|
| 54 | a = 8.2e10; |
---|
| 55 | b = aubio_miditofreq(a); |
---|
| 56 | fprintf(stdout, "(%.2f, %.2f), ", a, b); |
---|
| 57 | a = -5.e10; |
---|
| 58 | fprintf(stdout, "(%.2f, %.2f)", a, b); |
---|
| 59 | fprintf(stdout, "]\n"); |
---|
[d314636] | 60 | return 0; |
---|
| 61 | } |
---|
| 62 | |
---|
[158e031] | 63 | int test_freqtomidi (void) |
---|
[7e35b37] | 64 | { |
---|
| 65 | smpl_t midi, freq; |
---|
[df9df98] | 66 | fprintf(stdout, "b = aubio_freqtomidi(a): ["); |
---|
[7e35b37] | 67 | for ( freq = 0.; freq < 30000.; freq += 440. ) { |
---|
| 68 | midi = aubio_freqtomidi(freq); |
---|
[df9df98] | 69 | fprintf(stdout, "(%.2f, %.2f), ", freq, midi); |
---|
[7e35b37] | 70 | } |
---|
| 71 | freq = 69.5; |
---|
| 72 | midi = aubio_freqtomidi(freq); |
---|
[df9df98] | 73 | fprintf(stdout, "(%.2f, %.2f), ", freq, midi); |
---|
[7e35b37] | 74 | freq = -69.5; |
---|
| 75 | midi = aubio_freqtomidi(freq); |
---|
[df9df98] | 76 | fprintf(stdout, "(%.2f, %.2f), ", freq, midi); |
---|
[7e35b37] | 77 | freq = -169.5; |
---|
| 78 | midi = aubio_freqtomidi(freq); |
---|
[df9df98] | 79 | fprintf(stdout, "(%.2f, %.2f), ", freq, midi); |
---|
[7e35b37] | 80 | freq = 140.; |
---|
| 81 | midi = aubio_freqtomidi(freq); |
---|
[df9df98] | 82 | fprintf(stdout, "(%.2f, %.2f), ", freq, midi); |
---|
[7e35b37] | 83 | freq = 0; |
---|
| 84 | midi = aubio_freqtomidi(freq); |
---|
[df9df98] | 85 | fprintf(stdout, "(%.2f, %.2f), ", freq, midi); |
---|
[7e35b37] | 86 | freq = 8.2e10; |
---|
| 87 | midi = aubio_freqtomidi(freq); |
---|
[df9df98] | 88 | fprintf(stdout, "(%.2f, %.2f), ", freq, midi); |
---|
[7e35b37] | 89 | freq = -5.; |
---|
| 90 | midi = aubio_freqtomidi(freq); |
---|
[df9df98] | 91 | fprintf(stdout, "(%.2f, %.2f)]\n", freq, midi); |
---|
[7e35b37] | 92 | return 0; |
---|
| 93 | } |
---|
| 94 | |
---|
[158e031] | 95 | int test_aubio_window (void) |
---|
[7e35b37] | 96 | { |
---|
| 97 | uint_t window_size = 16; |
---|
| 98 | fvec_t * window = new_aubio_window("default", window_size); |
---|
| 99 | del_fvec(window); |
---|
| 100 | |
---|
| 101 | window = new_fvec(window_size); |
---|
| 102 | fvec_set_window(window, "rectangle"); |
---|
| 103 | fvec_print(window); |
---|
| 104 | |
---|
| 105 | window_size /= 2.; |
---|
| 106 | window = new_aubio_window("triangle", window_size); |
---|
| 107 | fvec_print(window); |
---|
| 108 | del_fvec(window); |
---|
| 109 | |
---|
| 110 | window = new_aubio_window("rectangle", 16); |
---|
| 111 | del_fvec (window); |
---|
| 112 | return 0; |
---|
| 113 | } |
---|
| 114 | |
---|
[158e031] | 115 | int main (void) |
---|
[7e35b37] | 116 | { |
---|
| 117 | test_next_power_of_two(); |
---|
| 118 | test_miditofreq(); |
---|
| 119 | test_freqtomidi(); |
---|
| 120 | return 0; |
---|
| 121 | } |
---|