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

87 lines
2.0 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;
int myBeatPrevious = 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.HANN);
// 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);
// send osc
oscSendBeatValue(getBeatDetectNormalized());
// fft processing
}
/*******************************
beat helper functions
********************************/
float getBeatDetectNormalized() {
return (myBeatCurrent / float(myBeatMax));
}
void setBeatDecay(float val) {
gui_beatDecay.setValue(map(val, 0,1, gui_beatDecay.getStartLimit(), gui_beatDecay.getEndLimit()));
}
/********************************
fft helper functions
********************************/
void setAmpBeginFraction(float val) {
gui_fftAmpBeginFrac.setValue(map(val, 0,1, gui_fftAmpBeginFrac.getStartLimit(), gui_fftAmpBeginFrac.getEndLimit()));
}
void setAmpStart(float val) {
gui_ampStart.setValue(map(val, 0,1, gui_ampStart.getStartLimit(), gui_ampStart.getEndLimit()));
}
void setAmpStep(float val) {
gui_ampStep.setValue(map(val, 0,1, gui_ampStep.getStartLimit(), gui_ampStep.getEndLimit()));
}
void drawFFT() {
}
/*
GSlider gui_fftAmpBeginFrac;
GSlider gui_baseAmp;
GSlider gui_ampStart;
GSlider gui_ampStep;