diff --git a/README.md b/README.md index 6e179dd..a2ef166 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -This is a simple beat detector. ```beatTap.ck``` contains a class ```BeatDetector``` that exposes an event method. ```BeatDetector``` measures the time between subsequent calls to event and takes a windowed average of the last *n* events. +There are a few useful beat detection files in here. -```BeatTapper``` ties the detector to a keyboard, but *any* source of events could be used to drive the Detector. +Running ```chuck rundetect.ck``` will launch a ChucK program that plays a sample WAV file and "clicks" (and prints) where it detects a beat in that input. It works okay, but could probably use some tuning. The code for beat detection lives in ```beatDetect.ck``` -```taponbeat.ck``` is little more than a driver for simple synthesis to prove the detector/tapper works. \ No newline at end of file +Running ```chuck runtap.ck``` launches a program that listens for keystrokes, and averages the time between strokes to find a beat. The main logic for that lives in ```beatTap.ck```. \ No newline at end of file diff --git a/beatDetect.ck b/beatDetect.ck index 26e2a9d..4d8a947 100644 --- a/beatDetect.ck +++ b/beatDetect.ck @@ -9,7 +9,7 @@ public class ListenForBeat { 64 => int bands; fun int numBands() { return bands; } fun int numBands(int bnds) { if (!running) bnds => bands; return bands;} - 16 => int bandThreshold; + 40 => int bandThreshold; 0.000005 => float threshold; 2048 => int size; 3 => int cooldown; @@ -21,6 +21,15 @@ public class ListenForBeat { RMS rmses[256]; float runningMeans[256]; + /* + Breaks the input signal up into bands using a BPF, then + connects each band into an FFT, so that we can find the power + on that band. + + In the listen function, we'll grab the RMSes and find the ones + that are higher than their average power. If enough bands are "high" + at the same time, we'll call that a beat. + */ fun void build() { (high - low) / bands => step; for (0 => int i; i < bands; i++) { diff --git a/initialize.ck b/rundetect.ck similarity index 52% rename from initialize.ck rename to rundetect.ck index 5ffbe96..d649fac 100644 --- a/initialize.ck +++ b/rundetect.ck @@ -1,4 +1,2 @@ -Machine.add(me.dir() + "/beatTap.ck"); Machine.add(me.dir() + "/beatDetect.ck"); -//Machine.add(me.dir() + "/taponbeat.ck"); Machine.add(me.dir() + "/beatDetectTester.ck"); \ No newline at end of file diff --git a/runtap.ck b/runtap.ck new file mode 100644 index 0000000..279c6c3 --- /dev/null +++ b/runtap.ck @@ -0,0 +1,2 @@ +Machine.add(me.dir() + "/beatTap.ck"); +Machine.add(me.dir() + "/tapTester.ck"); \ No newline at end of file diff --git a/taponbeat.ck b/tapTester.ck similarity index 100% rename from taponbeat.ck rename to tapTester.ck