class library: SynthDef - replaceUGen fixes
[supercollider.git] / server / plugins / BeatTrack.h
blob289dad5bcd855bd513dae4ae305cc7f5cb2ca80d
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 #define DFFRAMELENGTH 512
23 #define DFSTORE 700
24 //store last 700 to avoid problems during amortisation
25 #define LAGS 128
28 struct BeatTrack : Unit {
30 //corrections for different sampling rates: support 44100 as native, and 48000, 88200, 96000 by frequency domain down sampling
31 //assumes 1024 FFT for first two, 2048 for second two
32 float m_srate;
33 float m_srateconversion;
34 float m_frameperiod;
37 //FFT data
38 //int m_bufWritePos;
39 //float * m_prepareFFTBuf;
40 float * m_FFTBuf;
42 //fftwf_plan planTime2FFT;
44 float * m_prevmag;
45 float * m_prevphase;
46 float * m_predict;
48 //vDSP
49 //unsigned long m_vlog2n;
50 //COMPLEX_SPLIT m_vA;
51 //FFTSetup m_vsetup;
54 //time positions
55 long m_frame;
57 //df
58 float m_df[DFSTORE];
59 int m_dfcounter;
61 //for peak pick scorer
62 int m_dfmemorycounter;
63 float m_dfmemory[15];
66 //autocorrelation results on df
67 float m_acf[DFFRAMELENGTH];
69 //float* m_M;
70 float m_mg[LAGS];
71 float m_besttorsum;
72 int m_bestcolumn;
74 float m_phaseweights[LAGS];
76 float m_tor;
77 int m_torround;
79 float m_periodp;
80 float m_periodg;
82 int m_flagstep;
83 float m_prevperiodp[3];
85 //amortisation search for best phase from 0 to m_torround-1
86 float m_bestphasescore;
87 int m_bestphase;
89 //tempo
90 float m_currtempo;
92 //phase
93 float m_currphase;
95 //phasor, trigger beat and modulo when >1.0
96 float m_phase, m_phaseperblock;
98 //phasor output separate so can have it lock and keep going when don't want to track
99 float m_outputphase, m_outputtempo, m_outputphaseperblock;
101 int halftrig;
102 int q1trig;
103 int q2trig;
105 //amortization - more complex structure to support different rates of work
106 int m_amortisationstate;
107 int m_amortcount;
108 int m_amortlength;
109 int m_amortisationsteps;
111 //model states
112 int m_stateflag;
113 int m_timesig;
115 int m_storedfcounter;
116 int m_storedfcounterend;
123 extern "C"
125 //required interface functions
126 void BeatTrack_next(BeatTrack *unit, int wrongNumSamples);
127 void BeatTrack_Ctor(BeatTrack *unit);
128 void BeatTrack_Dtor(BeatTrack *unit);