source: tests/src/test-mathutils.c @ af27265

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since af27265 was df9df98, checked in by Paul Brossier <piem@piem.org>, 11 years ago

tests/src/test-mathutils.c: improve

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