Changeset f69e3bd
- Timestamp:
- Oct 15, 2013, 10:46:18 PM (11 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- 69c39ca
- Parents:
- 47e067b
- Location:
- tests/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/src/onset/test-onset.c
r47e067b rf69e3bd 1 1 #include <aubio.h> 2 #include "utils_tests.h" 2 3 3 int main ( )4 int main (int argc, char **argv) 4 5 { 5 // 1. allocate some memory 6 uint_t n = 0; // frame counter 6 uint_t err = 0; 7 if (argc < 2) { 8 err = 2; 9 PRINT_ERR("not enough arguments\n"); 10 PRINT_MSG("read a wave file as a mono vector\n"); 11 PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]); 12 return err; 13 } 14 uint_t samplerate = 0; 7 15 uint_t win_s = 1024; // window size 8 uint_t hop_s = win_s / 4; // hop size 9 uint_t samplerate = 44100; // samplerate 16 uint_t hop_size = win_s / 4; 17 uint_t n_frames = 0, read = 0; 18 if ( argc == 3 ) samplerate = atoi(argv[2]); 19 if ( argc == 4 ) hop_size = atoi(argv[3]); 20 21 char_t *source_path = argv[1]; 22 aubio_source_t * source = new_aubio_source(source_path, samplerate, hop_size); 23 if (!source) { err = 1; goto beach; } 24 25 if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(source); 26 10 27 // create some vectors 11 fvec_t * input = new_fvec (win_s/4); // input buffer 12 fvec_t * out = new_fvec (2); // input buffer 28 fvec_t * in = new_fvec (hop_size); // input audio buffer 29 fvec_t * out = new_fvec (2); // output position 30 13 31 // create onset object 14 aubio_onset_t * o nset = new_aubio_onset("complex", win_s, hop_s, samplerate);32 aubio_onset_t * o = new_aubio_onset("default", win_s, hop_size, samplerate); 15 33 16 // 2. do something with it 17 while (n < 10) { 18 // get `hop_s` new samples into `input` 19 // ... 20 // exectute onset detection 21 aubio_onset_do (onset, input, out); 22 // do something with output candidates 23 // ... 24 n++; 25 }; 34 do { 35 // put some fresh data in input vector 36 aubio_source_do(source, in, &read); 37 // execute onset 38 aubio_onset_do(o,in,out); 39 // do something with the onsets 40 if (out->data[0] != 0) { 41 PRINT_MSG("onset at %.3fms, %.3fs, frame %d\n", 42 aubio_onset_get_last_ms(o), aubio_onset_get_last_s(o), 43 aubio_onset_get_last(o)); 44 } 45 n_frames += read; 46 } while ( read == hop_size ); 26 47 27 // 3. clean up memory 28 del_aubio_onset(onset); 29 del_fvec(input); 48 PRINT_MSG("read %.2fs, %d frames at %dHz (%d blocks) from %s\n", 49 n_frames * 1. / samplerate, 50 n_frames, samplerate, 51 n_frames / hop_size, source_path); 52 53 // clean up memory 54 del_aubio_onset(o); 55 del_fvec(in); 30 56 del_fvec(out); 57 beach: 31 58 aubio_cleanup(); 32 59 33 return 0;60 return err; 34 61 } -
tests/src/tempo/test-tempo.c
r47e067b rf69e3bd 1 1 #include <aubio.h> 2 #include "utils_tests.h" 2 3 3 int main ( )4 int main (int argc, char **argv) 4 5 { 5 uint_t i = 0; 6 uint_t err = 0; 7 if (argc < 2) { 8 err = 2; 9 PRINT_ERR("not enough arguments\n"); 10 PRINT_MSG("read a wave file as a mono vector\n"); 11 PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]); 12 return err; 13 } 14 uint_t samplerate = 0; 6 15 uint_t win_s = 1024; // window size 7 fvec_t * in = new_fvec (win_s); // input vector 8 fvec_t * out = new_fvec (2); // output beat position 16 uint_t hop_size = win_s / 4; 17 uint_t n_frames = 0, read = 0; 18 if ( argc == 3 ) samplerate = atoi(argv[2]); 19 if ( argc == 4 ) hop_size = atoi(argv[3]); 20 21 char_t *source_path = argv[1]; 22 aubio_source_t * source = new_aubio_source(source_path, samplerate, hop_size); 23 if (!source) { err = 1; goto beach; } 24 25 if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(source); 26 27 // create some vectors 28 fvec_t * in = new_fvec (hop_size); // input audio buffer 29 fvec_t * out = new_fvec (2); // output position 9 30 10 31 // create tempo object 11 aubio_tempo_t * o = new_aubio_tempo(" complex", win_s, win_s/4, 44100.);32 aubio_tempo_t * o = new_aubio_tempo("default", win_s, hop_size, samplerate); 12 33 13 smpl_t bpm, confidence; 14 15 while (i < 1000) { 34 do { 16 35 // put some fresh data in input vector 17 // ... 18 36 aubio_source_do(source, in, &read); 19 37 // execute tempo 20 38 aubio_tempo_do(o,in,out); 21 39 // do something with the beats 22 // ... 40 if (out->data[0] != 0) { 41 PRINT_MSG("beat at %.3fms, %.3fs, frame %d, %.2fbpm with confidence %.2f\n", 42 aubio_tempo_get_last_ms(o), aubio_tempo_get_last_s(o), 43 aubio_tempo_get_last(o), aubio_tempo_get_bpm(o), aubio_tempo_get_confidence(o)); 44 } 45 n_frames += read; 46 } while ( read == hop_size ); 23 47 24 // get bpm and confidence 25 bpm = aubio_tempo_get_bpm(o); 26 confidence = aubio_tempo_get_confidence(o); 48 PRINT_MSG("read %.2fs, %d frames at %dHz (%d blocks) from %s\n", 49 n_frames * 1. / samplerate, 50 n_frames, samplerate, 51 n_frames / hop_size, source_path); 27 52 28 i++; 29 }; 30 53 // clean up memory 31 54 del_aubio_tempo(o); 32 55 del_fvec(in); 33 56 del_fvec(out); 57 del_aubio_source(source); 58 beach: 34 59 aubio_cleanup(); 35 60 36 return 0;61 return err; 37 62 }
Note: See TracChangeset
for help on using the changeset viewer.