From: Paul Brossier Date: Fri, 15 Apr 2016 18:26:57 +0000 (+0200) Subject: test.js: use aubio_tempo rather than directly beattracking X-Git-Tag: v0.0.1~3^2~2 X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=7ebae1f92807435ba2ec3384b5fffef7038de76b;p=node-aubio.git test.js: use aubio_tempo rather than directly beattracking --- diff --git a/test.js b/test.js index 9168ceb..8fae5a6 100644 --- a/test.js +++ b/test.js @@ -11,24 +11,27 @@ var get_file_bpm = function(path, params) { var test_fvec = aubio.new_fvec(params.hop_s); var out_fvec = aubio.new_fvec(params.hop_s); var tmp_read = ref.alloc('int'); - var tempo = aubio.new_aubio_beattracking(params.hop_s, params.hop_s, params.samplerate); + var tempo = aubio.new_aubio_tempo('default', params.win_s, params.hop_s, params.samplerate); var total_bpm = 0; var count = 0; while(true) { aubio.aubio_source_do(source, test_fvec, tmp_read); - aubio.aubio_beattracking_do(tempo, test_fvec, out_fvec); - var test_sample = aubio.fvec_get_sample(test_fvec, 1); - console.log('test sample: ' + test_sample); + aubio.aubio_tempo_do(tempo, test_fvec, out_fvec); + var is_beat = aubio.fvec_get_sample(out_fvec, 0); + if (is_beat) { + var last_beat = aubio.aubio_tempo_get_last_s(tempo); + var last_bpm = aubio.aubio_tempo_get_bpm(tempo); + console.log('found beat at %d, %d bpm', last_beat, last_bpm); + } var read = tmp_read.deref(); total_frames += read; - count = count + 1; - total_bpm += aubio.aubio_beattracking_get_bpm(tempo); if(read != params.hop_s) { break; } } - console.log('total' + total_frames); - console.log('bpm: ' + total_bpm / count); + console.log('total time : %d seconds (%d frames)', (total_frames / samplerate), total_frames); + aubio.del_aubio_source(source); + aubio.del_aubio_tempo(tempo); } get_file_bpm('holden.mp3', { @@ -36,23 +39,3 @@ get_file_bpm('holden.mp3', { win_s : 1024, hop_s : 512, }); - -/*var in_fvec = aubio.new_fvec(16); -var out_fvec = aubio.new_fvec(4); -aubio.fvec_ones(out_fvec); -aubio.fvec_print(in_fvec); -aubio.fvec_print(out_fvec); - -var tempo = aubio.new_aubio_beattracking(16, 256, 44100); - -var i = 0; - -while(i < 10) { - aubio.aubio_beattracking_do(tempo, in_fvec, out_fvec); - console.log(aubio.aubio_beattracking_get_bpm(tempo)); - i++ -} - -//var test_filt = aubio.new_aubio_filter_a_weighting(44100); -//aubio.aubio_filter_do(test_fvec, test_filt); -//*/