sheadernanigans/src/2023-06-21.festl_is/processing_sketches/audio_processing_gui/audioAnalysis.pde

52 lines
1.1 KiB
Plaintext

import ddf.minim.*;
import ddf.minim.analysis.*;
Minim minim;
AudioInput myAudio;
// beat detection with sound energy
BeatDetect myBeat;
int myBeatMax = 20; // sync with gui
int myBeatCurrent = 0;
FFT myFFT;
void setupAudioAnalysis() {
minim = new Minim(this);
myAudio = minim.getLineIn(); // Minim.STEREO, bufferSize=1024, sampleRate=44100, int bitDepth=16
// beat detection setup
myBeat = new BeatDetect();
// fft setup
myFFT = new FFT(myAudio.bufferSize(), myAudio.sampleRate());
myFFT.logAverages(22, 12); // (22,12) -> 120 averages
myFFT.window(FFT.NONE);
// debug
println("[debug][audio]: number of fft bins: "+myFFT.avgSize());
}
void drawAudioAnalysis() {
// beat detection processing
if(myBeatCurrent > 0) {
myBeatCurrent--; // linear decay
}
myBeat.detect(myAudio.mix);
if(myBeat.isOnset()) {
myBeatCurrent = myBeatMax;
}
// draw beat detection
fill(0);noStroke();
rect(160,40,40,40);
fill(255);
circle(160+20,40+20,getBeatDetectNormalized()*36);
// fft processing
}
float getBeatDetectNormalized() {
return (myBeatCurrent / float(myBeatMax));
}