File: BeatTrack.h

package info (click to toggle)
supercollider 1%3A3.13.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 80,292 kB
  • sloc: cpp: 476,363; lisp: 84,680; ansic: 77,685; sh: 25,509; python: 7,909; makefile: 3,440; perl: 1,964; javascript: 974; xml: 826; java: 677; yacc: 314; lex: 175; objc: 152; ruby: 136
file content (124 lines) | stat: -rw-r--r-- 3,053 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/*
    SuperCollider real time audio synthesis system
    Copyright (c) 2002 James McCartney. All rights reserved.
    http://www.audiosynth.com

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
*/


#define DFFRAMELENGTH 512
#define DFSTORE 700
// store last 700 to avoid problems during amortisation
#define LAGS 128


struct BeatTrack : Unit {
    // corrections for different sampling rates: support 44100 as native, and 48000, 88200, 96000 by frequency domain
    // down sampling assumes 1024 FFT for first two, 2048 for second two
    float m_srate;
    float m_srateconversion;
    float m_frameperiod;


    // FFT data
    // int m_bufWritePos;
    // float * m_prepareFFTBuf;
    float* m_FFTBuf;

    // fftwf_plan planTime2FFT;

    float* m_prevmag;
    float* m_prevphase;
    float* m_predict;

    // vDSP
    // unsigned long m_vlog2n;
    // COMPLEX_SPLIT m_vA;
    // FFTSetup m_vsetup;


    // time positions
    long m_frame;

    // df
    float m_df[DFSTORE];
    int m_dfcounter;

    // for peak pick scorer
    int m_dfmemorycounter;
    float m_dfmemory[15];


    // autocorrelation results on df
    float m_acf[DFFRAMELENGTH];

    // float* m_M;
    float m_mg[LAGS];
    float m_besttorsum;
    int m_bestcolumn;

    float m_phaseweights[LAGS];

    float m_tor;
    int m_torround;

    float m_periodp;
    float m_periodg;

    int m_flagstep;
    float m_prevperiodp[3];

    // amortisation search for best phase from 0 to m_torround-1
    float m_bestphasescore;
    int m_bestphase;

    // tempo
    float m_currtempo;

    // phase
    float m_currphase;

    // phasor, trigger beat and modulo when >1.0
    float m_phase, m_phaseperblock;

    // phasor output separate so can have it lock and keep going when don't want to track
    float m_outputphase, m_outputtempo, m_outputphaseperblock;

    int halftrig;
    int q1trig;
    int q2trig;

    // amortization - more complex structure to support different rates of work
    int m_amortisationstate;
    int m_amortcount;
    int m_amortlength;
    int m_amortisationsteps;

    // model states
    int m_stateflag;
    int m_timesig;

    int m_storedfcounter;
    int m_storedfcounterend;
};


extern "C" {
// required interface functions
void BeatTrack_next(BeatTrack* unit, int wrongNumSamples);
void BeatTrack_Ctor(BeatTrack* unit);
void BeatTrack_Dtor(BeatTrack* unit);
}