1 /* 2 Rakarrack Guitar FX 3 4 beattracker.h - Detect beats and compute tempo 5 Copyright (C) 2010 Ryan Billing 6 Author: Ryan Billing & Josep Andreu 7 8 This program is free software; you can redistribute it and/or modify 9 it under the terms of version 3 of the GNU General Public License 10 as published by the Free Software Foundation. 11 12 This program is distributed in the hope that it will be useful, 13 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 GNU General Public License (version 2) for more details. 16 17 You should have received a copy of the GNU General Public License (version 2) 18 along with this program; if not, write to the Free Software Foundation, 19 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 20 21 */ 22 23 #ifndef BEAT_H 24 #define BEAT_H 25 26 #include "global.h" 27 #include "RBFilter.h" 28 29 30 /* 31 Using beattracker: 32 Call detect() function on a set of samples. 33 The array, index[], returns a number of samples processed before finding the beat onset. 34 35 For example, if after processing 20 samples into the stream it finds a beat, then index[0] will have the number 20. 36 Then if it finds another beat at 67 samples into the stream, then index[1] will be 67. 37 38 So you loop through index[] until index[n] = 0. 39 40 These numbers may be used directly to index the onset of a beat in the audio stream. 41 42 index[] is initialized to the length of PERIOD, but it is unlikely that more than 1 beat per PERIOD will ever be found, so maybe 43 I need to change the design...for now it will do the job. 44 45 Next is the tempo calculator, but that code has not yet been started. The plan is: 46 call beattracker 47 call get_tempo() whenever you want the most current tempo calculation. 48 49 */ 50 51 class beattracker 52 { 53 public: 54 beattracker (double sample_rate, uint32_t intermediate_bufsize); 55 ~beattracker (); 56 void cleanup (); 57 void detect (float * smpsl, float * smpsr, uint32_t period); 58 float get_tempo(); //returns tempo in float beats per minute 59 int *index; 60 61 private: 62 63 long timeseries[20]; 64 int tsidx; 65 long tscntr; 66 //Variables for TrigStepper detecting trigger state. 67 float peakpulse, peak, envrms, peakdecay, trigthresh; 68 int trigtimeout, trigtime, onset, atk; 69 float targatk, lmod, rmod; 70 71 class RBFilter *rmsfilter, *peaklpfilter, *peakhpfilter, *peaklpfilter2; 72 73 float oldbpm, oldmost; 74 float avbpm[17], statsbin[17]; 75 int maxptr; 76 int bpm_change_cntr; 77 78 float fSAMPLE_RATE; 79 float* interpbuf;//buffer for filters 80 81 void calc_tempo(); //called by detect() on every beat detected 82 }; 83 84 85 #endif 86