for a schoolproject i want to create a round spectrogram, but I am still kinda new to processing. I created with my teacher this code and I actually want to add a color (or even more) to the spectrogram. It does not work with a simple fill. The next step i want to do is to make it a circular spectrogram like this -> https://vimeo.com/27135957. Does somebody know how?
Thanks!
import ddf.minim.analysis.*;
import ddf.minim.*;
Minim minim;
AudioPlayer song;
FFT fft;
int colmax = 1000;
int rowmax = 500;
int[][] sgram = new int[rowmax][colmax];
int col;
int leftedge;
void setup()
{
size(200, 300, P3D);
minim = new Minim(this);
song = minim.loadFile("sun_sonification.wav");
song.play();
fft = new FFT(song.bufferSize(), song.sampleRate());
fft.window(FFT.HAMMING);
frameRate(40);
}
void draw()
{
background(0);
stroke(255);
// perform a forward FFT on the samples in the input buffer
fft.forward(song.mix);
for (int i = 0; i < rowmax /* fft.specSize() */; i++)
{
// fill in the new column of spectral values
sgram[i][col] = (int)Math.round(Math.max(0, 2*70*Math.log10(1000*fft.getBand(i))));
}
col = col + 1;
if (col == colmax) {
col = 100;
}
for (int i = 0; i < colmax-leftedge; i++) {
for (int j = 0; j < rowmax; j++) {
stroke(sgram[j][i+leftedge]);
point((i*PI), height-j);
}
}
//Draw the rest of the image as the beginning of the array (up to leftedge)
for (int i = 0; i < leftedge; i++) {
for (int j = 0; j < rowmax; j++) {
stroke(sgram[j][i]);
point(i+colmax-leftedge, height-j*sin(height/2));
}
}
}
void stop()
{
song.close();
minim.stop();
super.stop();
}
Wow thanks! I do not really know what you mean by frequency (radius) vs time (angle). It looks very nice and yes that something I want to create. Hope you want to help me further!
int time;
float angle;
void setup()
{
size(500, 500);
background(0);
//angle = TAU/360; // this is 1 deg
angle = TAU/90; // this is 4 deg
}
void draw()
{
translate(width/2, height/2);
rotate(time*angle); //Increase angle with each increment of time
strokeWeight(3);
for(int rad = 0; rad<255; rad++) //Think of each step along radius as frequency
{
// if each frequency has an amplitude in an array you can use that for color!
//float col = 128;
int col = int(128 + 128*cos(rad*TAU/255)); // This was just for fun!
//println(col);
//stroke(col);
stroke(255 - col, 255-col, 0);
point(rad, 0);
}
time++; //time increases with each frame
if (time >= 90) noLoop();
}
I will leave the rest with you!
Lots of good resources here at the processing.org website!
A common format is a graph with two geometric dimensions: one axis represents time, and the other axis represents frequency; a third dimension indicating the amplitude of a particular frequency at a particular time is represented by the intensity or color of each point in the image.
When doing a polar plot\sweep the radius is the frequency, the angle sweeps with the passage of time and the amplitude of a particular frequency can be represented with a color.
Hi, can you share the code if you make it a circular spectrogram like this Musical spectrum analysis on Vimeo
pls share code so i can also have look thx