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.
Page Index Toggle Pages: 1
sound generated wave (Read 486 times)
sound generated wave
Nov 3rd, 2008, 12:12pm
 
hello, i am trying to generate a simple scrolling white wave against a black background. the wave should respond to input sound from the microphone. i am actually hoping to generate the sound from an mp3 file later.
i can't seem to make it work. here is the code i have been using.
its a combination of the NoiseWave tutorial and the Example 20-5: Live Input with Sonia, both by by Daniel Shiffman.

i think iv'e just made a mess of it. there is something i don't understand.

any help greatly apprieciated.
dove


int xspacing = 16;   // How far apart should each horizontal location be spaced
int w;    // Width of entire wave

float yoff = 0.0f;   // 2nd dimension of perlin noise
float[] yvalues;     // Using an array to store height values for the wave (not entirely necessary)

import pitaru.sonia_v2_9.*;
import processing.video.*;

void setup() {
 size(1024,768);
 Sonia.start(this); // Start Sonia engine.
 LiveInput.start(); // Start listening to the microphone
   frameRate(30);
 colorMode(RGB,255,255,255,100);
 smooth();
 w = width+16;
 yvalues = new float[w/xspacing];
 smooth();
 background(0);
}

void draw() {
 // Get the overall volume (between 0 and 1.0)
 float vol = LiveInput.getLevel();
  calcWave();
 renderWave();
}

void calcWave() {
 float dx = 0.06f;
 float dy = 0.02f; //speed of scroll
 float amplitude = 100.0f;
 
   // Increment y ('time')
 yoff += dy;
 
   float xoff = yoff;

 for (int i = 0; i < yvalues.length; i++) {
   yvalues[i] = (2*vol(xoff)-1)*amplitude;    
   xoff+=dx;
 }

}
 
 void renderWave() {
 
for (int x = 0; x < yvalues.length-1; x++) {
 stroke(255);
 strokeWeight(3);
 line(x*xspacing,width/2+yvalues[x],(x-1)*xspacing,width/2+yvalues[x+1]);
}
// Close the sound engine
public void stop() {
 Sonia.stop();
 super.stop();
}
 }

Re: sound generated wave
Reply #1 - Nov 7th, 2008, 6:03pm
 
You might look at the Minim library examples. Just download the latest version of Processing and open the example "Get Line In." For Mp3 you could modify the code, the line drawn comes from the in variable.
Page Index Toggle Pages: 1