source: tests/src/test-mathutils.c @ 332487b

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

tests/src: clean up includes

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