Ignore:
Timestamp:
Mar 3, 2013, 8:09:48 PM (7 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
Children:
474a573
Parents:
abd326c
Message:

tests/src/: improve examples

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/src/test-mathutils.c

    rabd326c r7e35b37  
    44#include <aubio.h>
    55
    6 int main(){
     6int test_next_power_of_two()
     7{
    78  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);
    811
    9   a = 31; b = aubio_next_power_of_two(a);
    10   fprintf(stdout, "next_power_of_two of %d is %d\n", a, b);
    11   assert(b == 32);
     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);
    1214
    13   a = 32; b = aubio_next_power_of_two(a);
    14   fprintf(stdout, "next_power_of_two of %d is %d\n", a, b);
    15   assert(b == 32);
     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);
    1617
    17   a = 33; b = aubio_next_power_of_two(a);
    18   fprintf(stdout, "next_power_of_two of %d is %d\n", a, b);
    19   assert(b == 64);
     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);
    2023
    2124  return 0;
    2225}
    2326
     27int test_miditofreq()
     28{
     29  smpl_t midi, freq;
     30  for ( midi = 0; midi < 128; midi += 3 ) {
     31    freq = aubio_miditofreq(midi);
     32    fprintf(stdout, "aubio_miditofreq(%.2f) = %.2f\n", midi, freq);
     33  }
     34  midi = 69.5;
     35  freq = aubio_miditofreq(midi);
     36  fprintf(stdout, "aubio_miditofreq(%.2f) = %.2f\n", midi, freq);
     37  midi = -69.5;
     38  freq = aubio_miditofreq(midi);
     39  fprintf(stdout, "aubio_miditofreq(%.2f) = %.2f\n", midi, freq);
     40  midi = -169.5;
     41  freq = aubio_miditofreq(midi);
     42  fprintf(stdout, "aubio_miditofreq(%.2f) = %.2f\n", midi, freq);
     43  midi = 140.;
     44  freq = aubio_miditofreq(midi);
     45  fprintf(stdout, "aubio_miditofreq(%.2f) = %.2f\n", midi, freq);
     46  midi = 0;
     47  freq = aubio_miditofreq(midi);
     48  fprintf(stdout, "aubio_miditofreq(%.2f) = %.2f\n", midi, freq);
     49  midi = 8.2e10;
     50  freq = aubio_miditofreq(midi);
     51  fprintf(stdout, "aubio_miditofreq(%.2f) = %.2f\n", midi, freq);
     52  midi = -5.e10;
     53  freq = aubio_miditofreq(midi);
     54  fprintf(stdout, "aubio_miditofreq(%.2f) = %.2f\n", midi, freq);
     55  return 0;
     56}
     57
     58int test_freqtomidi()
     59{
     60  smpl_t midi, freq;
     61  for ( freq = 0.; freq < 30000.; freq += 440. ) {
     62    midi = aubio_freqtomidi(freq);
     63    fprintf(stdout, "aubio_freqtomidi(%.2f) = %.2f\n", freq, midi);
     64  }
     65  freq = 69.5;
     66  midi = aubio_freqtomidi(freq);
     67  fprintf(stdout, "aubio_freqtomidi(%.2f) = %.2f\n", freq, midi);
     68  freq = -69.5;
     69  midi = aubio_freqtomidi(freq);
     70  fprintf(stdout, "aubio_freqtomidi(%.2f) = %.2f\n", freq, midi);
     71  freq = -169.5;
     72  midi = aubio_freqtomidi(freq);
     73  fprintf(stdout, "aubio_freqtomidi(%.2f) = %.2f\n", freq, midi);
     74  freq = 140.;
     75  midi = aubio_freqtomidi(freq);
     76  fprintf(stdout, "aubio_freqtomidi(%.2f) = %.2f\n", freq, midi);
     77  freq = 0;
     78  midi = aubio_freqtomidi(freq);
     79  fprintf(stdout, "aubio_freqtomidi(%.2f) = %.2f\n", freq, midi);
     80  freq = 8.2e10;
     81  midi = aubio_freqtomidi(freq);
     82  fprintf(stdout, "aubio_freqtomidi(%.2f) = %.2f\n", freq, midi);
     83  freq = -5.;
     84  midi = aubio_freqtomidi(freq);
     85  fprintf(stdout, "aubio_freqtomidi(%.2f) = %.2f\n", freq, midi);
     86  return 0;
     87}
     88
     89int test_aubio_window()
     90{
     91  uint_t window_size = 16;
     92  fvec_t * window = new_aubio_window("default", window_size);
     93  del_fvec(window);
     94
     95  window = new_fvec(window_size);
     96  fvec_set_window(window, "rectangle");
     97  fvec_print(window);
     98
     99  window_size /= 2.;
     100  window = new_aubio_window("triangle", window_size);
     101  fvec_print(window);
     102  del_fvec(window);
     103
     104  window = new_aubio_window("rectangle", 16);
     105  del_fvec (window);
     106  return 0;
     107}
     108
     109int main ()
     110{
     111  test_next_power_of_two();
     112  test_miditofreq();
     113  test_freqtomidi();
     114  return 0;
     115}
Note: See TracChangeset for help on using the changeset viewer.