1 /* 2 SuperCollider real time audio synthesis system 3 Copyright (c) 2002 James McCartney. All rights reserved. 4 http://www.audiosynth.com 5 6 This program is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with this program; if not, write to the Free Software 18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 19 */ 20 21 22 // N feature stream inputs, cross correlation with template on each channel 23 24 // templates- search 120 tempi * 2 groove types (really just /2 and /3 subdivision) and no metrical discernment * a 25 // different numbers of phases depending on tempo 26 27 // assume 4 features * 120 tempi * 2 groove * 20 phase = 19200 per calculation time; say you calculate each 0.5 sec, 28 // amortise over (44100/64*0.5 >344.5) control blocks; calculate over 240 blocks 29 30 #include "SC_PlugIn.h" 31 32 struct BeatTrack2 : Unit { 33 // adjust for any sampling rate by calculating factors; runs off of k rate inputs 34 float m_srate; 35 float m_phaseaccuracy; // probably 8 control blocks! 36 int m_numtempi; //= 120; 37 // float * m_tempi; 38 int* m_numphases; 39 // float ** m_phases; 40 41 int m_numfeatures; 42 float* m_features; // pointer to control bus, assumes contiguous busnum for each consecutive feature 43 44 // 45 float m_temporalwindowsize; // typically small, 2 seconds for fast reactions compared to 6 secs for BeatTrack 46 float m_fullwindowsize; 47 float m_krlength; 48 int m_buffersize; // in control blocks 49 50 float** m_pastfeatures; // for each feature, a trail of last m_workingmemorysize values 51 52 int m_counter, m_startcounter; 53 54 // time positions 55 float m_calculationschedule; 56 float m_calculationperiod; 57 58 // tempo 59 float m_period; 60 int m_groove; 61 float m_currtempo; 62 63 // phase 64 float m_currphase; 65 66 // phasor, trigger beat and modulo when >1.0 67 float m_phase, m_phaseperblock; 68 69 // phasor output separate so can have it lock and keep going when don't want to track 70 float m_outputphase, m_outputtempo, m_outputgroove, m_outputphaseperblock; 71 72 float m_predictphase, m_predictperiod; 73 74 // amortization - more complex structure to support different rates of work 75 int m_amortisationstate; 76 int m_amortcount; 77 int m_amortlength; 78 int m_amortisationsteps; 79 80 // efficiency trick 81 float* m_scores; 82 83 // tracking best results for each feature 84 // also storing second best and previous best and second best? 85 // thus keep best from previous round too for additional vote/consistency check 86 float* bestscore; 87 int* bestphase; 88 int* besttempo; 89 int* bestgroove; 90 91 // or store all scores and resolve later? 92 93 int halftrig; 94 int q1trig; 95 int q2trig; 96 97 SndBuf* m_tempoweights; 98 int m_weightingscheme; 99 }; 100 101 102 extern "C" { 103 // required interface functions 104 void BeatTrack2_next(BeatTrack2* unit, int wrongNumSamples); 105 void BeatTrack2_Ctor(BeatTrack2* unit); 106 void BeatTrack2_Dtor(BeatTrack2* unit); 107 } 108