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 › Making Particle System react to Sound
Page Index Toggle Pages: 1
Making Particle System react to Sound (Read 1058 times)
Making Particle System react to Sound
Jun 2nd, 2007, 1:10am
 
Just trying to do something that should be rather simple but I'm having a hell of a time getting it to function. I have 7 days before it needs to be displayed. I am trying to have smoke be pushed around by sound. Basically, have the input for the Particle System change from the mouse to the  microphone.  I have the sets of code that I want to blend. I know this is vague but anything will help.

SET ONE:::: The Particle system
import traer.physics.*;
//import processing.pdf.*;
//import pitaru.sonia_v2_9.*;

Particle mouse, b, c;
Particle[] others;
ParticleSystem physics;

PImage img;

void setup()
{
 size( 500, 500 );
 frameRate( 24 );
 cursor( CROSS );
 
 // sprite mask thing stolen from dan shiffman
 PImage msk = loadImage("texture.gif");
 img = new PImage( msk.width, msk.height );
 for ( int i = 0; i < img.pixels.length; i++ )
   img.pixels[i] = color(255);
 img.mask(msk);
 imageMode(CORNER);
 tint( 0, 225 );
 
 physics = new ParticleSystem( 0, 0.1 );
 mouse = physics.makeParticle();
 mouse.makeFixed();
 
 others = new Particle[1500];
 for ( int i = 0; i < others.length; i++ )
 {
   others[i] = physics.makeParticle( 1.0, random( 0, width ), random( 0, height ), 0 );
   physics.makeAttraction( mouse, others[i], 4000, 50 );
 }
}

void draw()
{
 mouse.moveTo( mouseX, mouseY, 0 );
 physics.tick();

 background( 245 );
 
 for ( int i = 0; i < others.length; i++ )
 {
    Particle p = others[i];
    image(img,p.position().x()-img.width/2,p.position().y()-img.height/2);
 }
}


SET TWO:::::: The Sound System
import processing.pdf.*;

import pitaru.sonia_v2_9.*;

int xpos = 5;
float a = 0.0;
float inc = PI/0.3;
float[]spectrum;
float x,y,px,py;

void setup(){
 size(1000,800);
 spectrum = new float[1024];
 Sonia.start(this);
 LiveInput.start(1024);
 ellipseMode(CENTER);
 colorMode(RGB, 256);
 smooth();
 background(255);
 
}

void draw(){
 
 getSpectrum();
 
}

void getSpectrum(){
 noStroke();
 spectrum = LiveInput.getSpectrum();
 float v = LiveInput.getLevel() * 10;
 for ( int i = 0; i < spectrum.length/4; i++){
   float r = (400.0/1000.0) * spectrum[i];
   float r1 = (400.0/1000.0) * spectrum[i+1];
   fill(i*5, xpos, 0,150);
   float w = (10.0/400.0) * r;
   ellipse((width/2)+sin(a)*xpos,(height/2)+cos(a)*xpos,w,w);
   inc = PI/r1;
   a += inc;
   xpos += r/100.0;
 }
 a = 0.0;
 xpos = 1;
}

void mousePressed(){
 background(255);
}

void keyPressed(){
 exit();
 
}

public void stop(){
 Sonia.stop();
 super.stop();


}
Re: Making Particle System react to Sound
Reply #1 - Jun 9th, 2007, 6:00pm
 
it depends on how you want the particle system to react to sound..

on the sketch there using sonia, you can see you get an array of values (spectrum)

for a simple example you can accelerate particles motion on the y axis by using a frequency bar..

just do sumtin like


int frequency = 32;
p.vel.y = some_value * spectrum[frequency];

this is a very simple and might be ugly, but you get the idea.
you can use it to change position, acceleration, forces, gravity, whatever you feel like..

http://www.nothing.scene.org/p5/

check this out.. ive release few effects that use sonia and react to input sound.. it might help
Re: Making Particle System react to Sound
Reply #2 - Jun 10th, 2007, 3:08am
 
thx for ur link, lots of great examples in there.  your waves sketch was exactly what I was after to clear up some question marks on Additive Blending.

thx again!
Page Index Toggle Pages: 1