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

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since c101fe1 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
RevLine 
[d314636]1#include <stdio.h>
2#include <assert.h>
[7359775]3#define AUBIO_UNSTABLE 1
[d314636]4#include <aubio.h>
5
[7e35b37]6int test_next_power_of_two()
7{
[7359775]8  uint_t a, b;
[7e35b37]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);
[d314636]11
[7e35b37]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);
[d314636]14
[7e35b37]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);
[d314636]17
[7e35b37]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);
[d314636]20
[7e35b37]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{
[df9df98]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);
[7e35b37]34  }
[df9df98]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");
[d314636]55  return 0;
56}
57
[7e35b37]58int test_freqtomidi()
59{
60  smpl_t midi, freq;
[df9df98]61  fprintf(stdout, "b = aubio_freqtomidi(a): [");
[7e35b37]62  for ( freq = 0.; freq < 30000.; freq += 440. ) {
63    midi = aubio_freqtomidi(freq);
[df9df98]64    fprintf(stdout, "(%.2f,  %.2f), ", freq, midi);
[7e35b37]65  }
66  freq = 69.5;
67  midi = aubio_freqtomidi(freq);
[df9df98]68  fprintf(stdout, "(%.2f,  %.2f), ", freq, midi);
[7e35b37]69  freq = -69.5;
70  midi = aubio_freqtomidi(freq);
[df9df98]71  fprintf(stdout, "(%.2f,  %.2f), ", freq, midi);
[7e35b37]72  freq = -169.5;
73  midi = aubio_freqtomidi(freq);
[df9df98]74  fprintf(stdout, "(%.2f,  %.2f), ", freq, midi);
[7e35b37]75  freq = 140.;
76  midi = aubio_freqtomidi(freq);
[df9df98]77  fprintf(stdout, "(%.2f,  %.2f), ", freq, midi);
[7e35b37]78  freq = 0;
79  midi = aubio_freqtomidi(freq);
[df9df98]80  fprintf(stdout, "(%.2f,  %.2f), ", freq, midi);
[7e35b37]81  freq = 8.2e10;
82  midi = aubio_freqtomidi(freq);
[df9df98]83  fprintf(stdout, "(%.2f,  %.2f), ", freq, midi);
[7e35b37]84  freq = -5.;
85  midi = aubio_freqtomidi(freq);
[df9df98]86  fprintf(stdout, "(%.2f,  %.2f)]\n", freq, midi);
[7e35b37]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.