supernova: fix boost.thread move semantics
[supercollider.git] / Help / UGens / MachineListening / BeatTrack.html
blob9e33d1dca1a591d6680781dd95836df5675f958f
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="824.44">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
16 p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #606060}
17 p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
18 p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #007300}
19 span.s1 {color: #000000}
20 span.s2 {color: #0000bf}
21 span.s3 {color: #007300}
22 span.Apple-tab-span {white-space:pre}
23 </style>
24 </head>
25 <body>
26 <p class="p1"><b>BeatTrack<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>autocorrelation beat tracker</b></p>
27 <p class="p2"><br></p>
28 <p class="p3"><b>#quarternotetick, eighthnotetick, sixteenthnotetick, tempo = BeatTrack.kr(chain, lock=0)</b></p>
29 <p class="p2"><br></p>
30 <p class="p3"><b>chain [fft]- </b>Audio input to track, already passed through an FFT UGen; the expected size of FFT is 1024 for 44100 and 48000 sampling rate, and 2048 for double those. No other sampling rates are supported.<span class="Apple-converted-space"> </span></p>
31 <p class="p2"><br></p>
32 <p class="p3"><b>lock [sk]- </b>If this argument is greater than 0.5, the tracker will lock at its current periodicity and continue from the current phase. Whilst it updates the model's phase and period, this is not reflected in the output until lock goes back below 0.5. <span class="Apple-converted-space"> </span></p>
33 <p class="p2"><br></p>
34 <p class="p3">Autocorrelation based beat tracker; the underlying model assumes 4/4, but it should work on any isochronous beat structure, though there are biases to 100-120 bpm; a fast 7/8 may not be tracked in that sense. There are four k-rate outputs, being ticks at quarter, eighth and sixteenth level from the determined beat, and the current detected tempo. Note that the sixteenth note output won't necessarily make much sense if the music being tracked has swing; it is provided just as a convenience.<span class="Apple-converted-space"> </span></p>
35 <p class="p2"><br></p>
36 <p class="p3">This beat tracker determines the beat, biased to the midtempo range by weighting functions. It does not determine the measure level, only a tactus. It is also slow reacting, using a 6 second temporal window for its autocorrelation maneouvres. Don't expect human musician level predictive tracking.<span class="Apple-converted-space"> </span></p>
37 <p class="p2"><br></p>
38 <p class="p3">On the other hand, it is tireless, relatively general (though obviously best at transient 4/4 heavy material without much expressive tempo variation), and can form the basis of computer processing that is decidedly faster than human.<span class="Apple-converted-space"> </span></p>
39 <p class="p2"><br></p>
40 <p class="p4"><br></p>
41 <p class="p5"><br></p>
42 <p class="p6"><span class="s1">b = </span><span class="s2">Buffer</span><span class="s1">.alloc(s,1024,1); </span>//for sampling rates 44100 and 48000</p>
43 <p class="p6">//b = Buffer.alloc(s,2048,1); //for sampling rates 88200 and 96000</p>
44 <p class="p5"><br></p>
45 <p class="p6">//this is a one minute pop song; you should load something equivalent for testing</p>
46 <p class="p7"><span class="s1">d=</span><span class="s2">Buffer</span><span class="s1">.read(s,</span>"/Volumes/data/stevebeattrack/samples/100.wav"<span class="s1">);</span></p>
47 <p class="p5"><br></p>
48 <p class="p5"><br></p>
49 <p class="p6">//you can also test at 48000 and it should work</p>
50 <p class="p8">(</p>
51 <p class="p8">a= <span class="s2">SynthDef</span>(<span class="s3">\help_beattrack</span>,{<span class="s2">arg</span> vol=1.0, beepvol=1.0, lock=0;</p>
52 <p class="p8"><span class="s2">var</span> in, fft, resample;<span class="Apple-converted-space"> </span></p>
53 <p class="p8"><span class="s2">var</span> trackb,trackh,trackq,tempo;</p>
54 <p class="p8"><span class="s2">var</span> bsound,hsound,qsound, beep;</p>
55 <p class="p5"><br></p>
56 <p class="p8">in= <span class="s2">PlayBuf</span>.ar(1,d,<span class="s2">BufRateScale</span>.kr(d),1,0,1);</p>
57 <p class="p6">//in = SoundIn.ar(0);<span class="Apple-converted-space"> </span></p>
58 <p class="p5"><br></p>
59 <p class="p8">fft = <span class="s2">FFT</span>(b, in);</p>
60 <p class="p5"><br></p>
61 <p class="p8">#trackb,trackh,trackq,tempo=<span class="s2">BeatTrack</span>.kr(fft, lock);</p>
62 <p class="p5"><br></p>
63 <p class="p8">beep= <span class="s2">SinOsc</span>.ar(1000,0.0,<span class="s2">Decay</span>.kr(trackb,0.1));</p>
64 <p class="p5"><br></p>
65 <p class="p8"><span class="s2">Out</span>.ar(0,<span class="s2">Pan2</span>.ar((vol*in)+(beepvol*beep),0.0));</p>
66 <p class="p8">}).play</p>
67 <p class="p8">)</p>
68 <p class="p5"><br></p>
69 <p class="p5"><br></p>
70 <p class="p8">a.set(<span class="s3">\vol</span>,0.0);</p>
71 <p class="p8">a.set(<span class="s3">\vol</span>,1.0);</p>
72 <p class="p5"><br></p>
73 <p class="p8">a.set(<span class="s3">\beepvol</span>,1.0);</p>
74 <p class="p8">a.set(<span class="s3">\beepvol</span>,0.0);</p>
75 <p class="p5"><br></p>
76 <p class="p6"><span class="s1">a.set(</span><span class="s3">\lock</span><span class="s1">,1); </span>//fix it rigidly from current phase/period solution</p>
77 <p class="p6"><span class="s1">a.set(</span><span class="s3">\lock</span><span class="s1">,0); </span>//unfix, back to tracking</p>
78 <p class="p5"><br></p>
79 <p class="p5"><br></p>
80 <p class="p5"><br></p>
81 <p class="p5"><br></p>
82 <p class="p5"><br></p>
83 <p class="p5"><br></p>
84 <p class="p5"><br></p>
85 <p class="p6">//track audio in (try clapping a beat or beatboxing, but allow up to 6 seconds for tracking to begin) and spawning stuff at quarters, eighths and sixteenths</p>
86 <p class="p8">(</p>
87 <p class="p9"><span class="s2">SynthDef</span><span class="s1">(</span>\help_beattrack2<span class="s1">,{</span></p>
88 <p class="p8"><span class="s2">var</span> trackb,trackh,trackq,tempo;</p>
89 <p class="p8"><span class="s2">var</span> source;</p>
90 <p class="p8"><span class="s2">var</span> bsound,hsound,qsound;</p>
91 <p class="p5"><br></p>
92 <p class="p8">source= <span class="s2">SoundIn</span>.ar(0);</p>
93 <p class="p5"><br></p>
94 <p class="p8">#trackb,trackh,trackq,tempo=<span class="s2">BeatTrack</span>.kr(<span class="s2">FFT</span>(b, source));</p>
95 <p class="p5"><br></p>
96 <p class="p8">bsound= <span class="s2">Pan2</span>.ar(<span class="s2">LPF</span>.ar(<span class="s2">WhiteNoise</span>.ar*(<span class="s2">Decay</span>.kr(trackb,0.05)),1000),0.0);</p>
97 <p class="p5"><br></p>
98 <p class="p8">hsound= <span class="s2">Pan2</span>.ar(<span class="s2">BPF</span>.ar(<span class="s2">WhiteNoise</span>.ar*(<span class="s2">Decay</span>.kr(trackh,0.05)),3000,0.66),-0.5);</p>
99 <p class="p5"><br></p>
100 <p class="p8">qsound= <span class="s2">Pan2</span>.ar(<span class="s2">HPF</span>.ar(<span class="s2">WhiteNoise</span>.ar*(<span class="s2">Decay</span>.kr(trackq,0.05)),5000),0.5);</p>
101 <p class="p5"><br></p>
102 <p class="p8"><span class="s2">Out</span>.ar(0, bsound+hsound+qsound);</p>
103 <p class="p8">}).play;</p>
104 <p class="p8">)</p>
105 <p class="p5"><br></p>
106 <p class="p4"><br></p>
107 <p class="p4"><br></p>
108 <p class="p4"><br></p>
109 <p class="p3">Research note: This UGen is a derivation following:</p>
110 <p class="p3">Davies, M. E. P.<span class="Apple-converted-space">  </span>and Plumbley, M. D. Beat Tracking With A Two State Model. Proceedings of the IEEE International Conference on Acoustics, Speech and Signal Processing (ICASSP 2005), Philadelphia, USA, March 19-23, 2005</p>
111 <p class="p2"><br></p>
112 <p class="p3">The UGen was converted by Nick Collins for beat tracking research in the course of his PhD and uses an original C implementation of Matthew Davies' MATLAB model. It first appeared as part of BBCut2 as AutoTrack but has now been added to core to enhance SuperCollider's realtime machine listening options.<span class="Apple-converted-space"> </span></p>
113 <p class="p4"><br></p>
114 </body>
115 </html>