We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSound,  Music Libraries › Need help with audio visualization
Page Index Toggle Pages: 1
Need help with audio visualization (Read 2883 times)
Need help with audio visualization
Sep 25th, 2009, 3:00am
 
Hi,

I am trying to make some changes in this Processing program. This is what I want to do:

1. I would like the program to be resized to cover the whole screen (600*800 pixels)
2. I would like the red line in the bottom left corner to emerge from the entire bottom line (from left to right) as the white lines does.

---------------------------------------------------

CODE:

---------------------------------------------------

import ddf.minim.*;
import ddf.minim.analysis.*;

Minim minim;
AudioInput in;
FFT fft;

void setup()
{
 size(512, 200, P3D);

 minim = new Minim(this);
 minim.debugOn();
 
 // get a line in from Minim, default bit depth is 16
 in = minim.getLineIn(Minim.STEREO, 512);
 
 fft = new FFT(in.bufferSize(), in.sampleRate());
}

void draw()
{
 background(0);
 stroke(255);
 
 // draw the waveforms
 for(int i = 0; i < in.bufferSize() - 1; i++)
 {
   line(i, 50 + in.left.get(i)*50, i+1, 50 + in.left.get(i+1)*50);
   line(i, 150 + in.right.get(i)*50, i+1, 150 + in.right.get(i+1)*50);
 }
 
 // Calculate & draw FFT spectrum
 
 stroke(255,0,0);
 fft.forward(in.mix);
 for(int i = 0; i < fft.specSize(); i++)
 {
   // draw the line for frequency band i, scaling it by 4 so we can see it a bit better
   line(i, height, i, height - fft.getBand(i)*4);
 }

}


void stop()
{
 // always close Minim audio classes when you are done with them
 in.close();
 minim.stop();
 
 super.stop();
}


--------------------------------
I hope someone can help me!

Best,
Celia
Re: Need help with audio visualization
Reply #1 - Sep 25th, 2009, 3:53am
 
i can at least help with the first problem... change size(600,800);
maybe you should read the "Getting started" tutorial to learn some of the basics : http://processing.org/learning/gettingstarted/


BTW, 600x800 ?! fullscreen? are you serious?
Re: Need help with audio visualization
Reply #2 - Sep 26th, 2009, 1:14am
 
Thank you. Yes, I know how to change the size of the whole screen, but the lines are not following. What I need is for the whole program and graphics to cover the screen.

The prgram is for an art installation and is planned to be shown on an old computerscreen: 800*600 in fact I think maybe it can go up to 1024*768.

I still need some guidance on this.

Best,
Celia
Re: Need help with audio visualization
Reply #3 - Sep 26th, 2009, 3:31am
 
ah ok, now as i started the sketch, i get it.
Sorry. I will take a look at it.

hmm i dont get a read line though, only 2 white ones
Re: Need help with audio visualization
Reply #4 - Sep 26th, 2009, 3:40am
 
it's these bits that do the drawing

this bit is drawing the waveform and is limited by in.buffersize in the x direction.

for(int i = 0; i < in.bufferSize() - 1; i++)
{
  line(i, 50 + in.left.get(i)*50, i+1, 50 + in.left.get(i+1)*50);
  line(i, 150 + in.right.get(i)*50, i+1, 150 + in.right.get(i+1)*50);
}

and this is drawing the bars, this time limited by fft.specSize in the x direction.

stroke(255,0,0);
fft.forward(in.mix);
for(int i = 0; i < fft.specSize(); i++)
{
  // draw the line for frequency band i, scaling it by 4 so we can see it a bit better
  line(i, height, i, height - fft.getBand(i)*4);
}

you can't really change these two values without changing the way it looks. but you can mutliply both x and y arguments in the line() calls to match the new screen size.

alternatively, pushMatrix() and scale() at the start of the draw() and popMatrix() at the end as a quick and dirty way to scale the entire thing.
Re: Need help with audio visualization
Reply #5 - Sep 26th, 2009, 4:21am
 
alright,
the sketch width is set to the buffer Size, that means it always has to be a power of 2. 512 or 1024. 1024 would be ok so, if you want anything else like 800x600 keep 1024 as buffer size and then simple translate your lines, translate((width-in.bufferSize()),0);
so some of them get drawn offscreen but thats ok.  you can improve that though if you change the for loop.

and the red line now is drawn like the other ones too...
hope that helps


import ddf.minim.*;
import ddf.minim.analysis.*;

Minim minim;
AudioInput in;


FFT fft;

void setup()
{
 size(800, 600, P3D);

 minim = new Minim(this);
 minim.debugOn();

 // get a line in from Minim, default bit depth is 16
 in = minim.getLineIn(Minim.STEREO, 1024);

 fft = new FFT(in.bufferSize(), in.sampleRate());


}

void draw()
{
 background(0);
 stroke(255);

 // draw the waveforms
 pushMatrix();
 translate((width-in.bufferSize()),0);
 for(int i = 0; i < in.bufferSize() -1; i++)
 {
   line(i, 50 + in.left.get(i)*50, i+1, 50 + in.left.get(i+1)*50);
   line(i, 150 + in.right.get(i)*50, i+1, 150 + in.right.get(i+1)*50);
 }
 popMatrix();


 // Calculate & draw FFT spectrum

 stroke(255,0,0);
 fft.forward(in.mix);

 println(fft.specSize());
 for(int i = 0; i < width; i++)
 {
   line(i, 450 + fft.getBand(i)*-2, i+1, 450 + fft.getBand(i+1)*-2);

 }

}


void stop()
{
 // always close Minim audio classes when you are done with them
 in.close();
 minim.stop();

 super.stop();
}




Re: Need help with audio visualization
Reply #6 - Sep 27th, 2009, 12:50am
 
Thank you both: Cedric and koogy. Now the program works perfectly, and I understand a lot more about how it is built.
Smiley

Thank you for sharing your knowledge, and helping me solve the issue.

Best,
Celia

Re: Need help with audio visualization
Reply #7 - Oct 9th, 2009, 8:21pm
 
Nice. Helped me out also
Page Index Toggle Pages: 1