class library: SynthDef - replaceUGen fixes
[supercollider.git] / server / plugins / BeatTrack2.h
blobe45c7b1f395770a323c745e68bd57652bf1c7bbd
1 /*
2 SuperCollider real time audio synthesis system
3 Copyright (c) 2002 James McCartney. All rights reserved.
4 http://www.audiosynth.com
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.
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.
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
22 //N feature stream inputs, cross correlation with template on each channel
24 //templates- search 120 tempi * 2 groove types (really just /2 and /3 subdivision) and no metrical discernment * a different numbers of phases depending on tempo
26 //assume 4 features * 120 tempi * 2 groove * 20 phase = 19200 per calculation time; say you calculate each 0.5 sec, amortise over (44100/64*0.5 >344.5) control blocks;
27 //calculate over 240 blocks
29 #include "SC_PlugIn.h"
31 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;
41 int m_numfeatures;
42 float * m_features; //pointer to control bus, assumes contiguous busnum for each consecutive feature
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
50 float ** m_pastfeatures; //for each feature, a trail of last m_workingmemorysize values
52 int m_counter, m_startcounter;
54 //time positions
55 float m_calculationschedule;
56 float m_calculationperiod;
58 //tempo
59 float m_period;
60 int m_groove;
61 float m_currtempo;
63 //phase
64 float m_currphase;
66 //phasor, trigger beat and modulo when >1.0
67 float m_phase, m_phaseperblock;
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;
72 float m_predictphase, m_predictperiod;
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;
80 //efficiency trick
81 float * m_scores;
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;
91 //or store all scores and resolve later?
93 int halftrig;
94 int q1trig;
95 int q2trig;
97 SndBuf * m_tempoweights;
98 int m_weightingscheme;
103 extern "C"
105 //required interface functions
106 void BeatTrack2_next(BeatTrack2 *unit, int wrongNumSamples);
107 void BeatTrack2_Ctor(BeatTrack2 *unit);
108 void BeatTrack2_Dtor(BeatTrack2 *unit);