/**
* Touche Espace = Pause
* Clic souris dans la fenêtre d'abord
* Spectrogram
* Takes successive FFTs and renders them onto the screen as grayscale.
* inspiré de "LiveSpectrogram" from Dan Ellis.
* http://www.ee.columbia.edu/~dpwe/resources/Processing/
*
*/
import ddf.minim.analysis.*; // Pour FFT
import ddf.minim.*; // Pour AudioPlayer
String NomFichierAudio = "missmilsaveur.mp3";
int colmax = 400; // Spectrogram size (pixels)
int rowmax = 300; // Spectrogram size (pixels)
Minim minim;
AudioPlayer MonPlayer;
FFT Mafft;
int col = 0;
float Gris;
boolean ToucheEspace = false;
void setup() {
size(400, 300, P3D); // "The size() function must be the first line in setup()"
// size(400, 300); // Affichage ralenti -> mettre P3D
minim = new Minim(this);
MonPlayer = minim.loadFile(NomFichierAudio, 2048);
MonPlayer.loop(); // Fichier Audio joué en boucle
// setup audio input
// in = minim.getLineIn(Minim.MONO, bufferSize, sampleRate);
Mafft = new FFT(MonPlayer.bufferSize(), MonPlayer.sampleRate());
Mafft.window(FFT.HAMMING);
background(0);
frameRate(30);
}
void draw() {
if (! ToucheEspace) {
Mafft.forward(MonPlayer.mix);
// fill in the new column of spectral values
// println("rowmax = " + rowmax + " Mafft.specSize() = " + Mafft.specSize());
for (int i = 0; i < rowmax; i++) {
Gris = (float)(40*Math.log10(100*Mafft.getBand(i))); // log
// Gris = (float)(30*Mafft.getBand(i)); // lin
if (Gris > 255) Gris = 255;
if (Gris < 0) Gris = 0;
// if (Gris < 100) Gris = Gris/ 2; // Augmentation contraste
// Gris = 255-Gris; // Inversion Noir <-> blanc
stroke(Gris);
point(col, height-i);
}
col = col + 1; // next time will be the next column
if (col == colmax) col = 0; // wrap back to the first column when we get to the end
}
}
void keyPressed() {
if (key == ' ') { // barre d'espace
ToucheEspace = ! ToucheEspace;
if (ToucheEspace) MonPlayer.pause();
else MonPlayer.loop(); // Fichier Audio joué en boucle
}
}
void stop() { // always close Minim audio classes when you finish with them
MonPlayer.close();
minim.stop();
super.stop();
}