source: tests/src/test-mathutils.c @ 4ed4b1f

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

tests/: build with -Wmissing-declarations

  • Property mode set to 100644
File size: 3.1 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 (void);
7int test_miditofreq (void);
8int test_freqtomidi (void);
9int test_aubio_window (void);
10
11int test_next_power_of_two (void)
12{
13  uint_t a, b;
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);
16
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);
19
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);
22
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);
25
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
32int test_miditofreq (void)
33{
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);
39  }
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");
60  return 0;
61}
62
63int test_freqtomidi (void)
64{
65  smpl_t midi, freq;
66  fprintf(stdout, "b = aubio_freqtomidi(a): [");
67  for ( freq = 0.; freq < 30000.; freq += 440. ) {
68    midi = aubio_freqtomidi(freq);
69    fprintf(stdout, "(%.2f,  %.2f), ", freq, midi);
70  }
71  freq = 69.5;
72  midi = aubio_freqtomidi(freq);
73  fprintf(stdout, "(%.2f,  %.2f), ", freq, midi);
74  freq = -69.5;
75  midi = aubio_freqtomidi(freq);
76  fprintf(stdout, "(%.2f,  %.2f), ", freq, midi);
77  freq = -169.5;
78  midi = aubio_freqtomidi(freq);
79  fprintf(stdout, "(%.2f,  %.2f), ", freq, midi);
80  freq = 140.;
81  midi = aubio_freqtomidi(freq);
82  fprintf(stdout, "(%.2f,  %.2f), ", freq, midi);
83  freq = 0;
84  midi = aubio_freqtomidi(freq);
85  fprintf(stdout, "(%.2f,  %.2f), ", freq, midi);
86  freq = 8.2e10;
87  midi = aubio_freqtomidi(freq);
88  fprintf(stdout, "(%.2f,  %.2f), ", freq, midi);
89  freq = -5.;
90  midi = aubio_freqtomidi(freq);
91  fprintf(stdout, "(%.2f,  %.2f)]\n", freq, midi);
92  return 0;
93}
94
95int test_aubio_window (void)
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
115int main (void)
116{
117  test_next_power_of_two();
118  test_miditofreq();
119  test_freqtomidi();
120  return 0;
121}
Note: See TracBrowser for help on using the repository browser.