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 › Ess problem (change frequency moving mouse)
Page Index Toggle Pages: 1
Ess problem (change frequency moving mouse) (Read 577 times)
Ess problem (change frequency moving mouse)
Mar 25th, 2009, 2:03pm
 
I have a problem using Ess library. I generate a sine and i want to change the frequency while i move the mouse...
There is a row that i don't want to hear... HELP PLEASE

r is the distance (x,y)(0,0)...

//-----------------------------------------------------------------
//first example WITHOUT FADES
//-----------------------------------------------------------------

import krister.Ess.*;
AudioChannel myChannel;
SineWave myWave;

void setup()
{
 size(800,600);
 Ess.start(this);
 myChannel=new AudioChannel();
 myChannel.initChannel(myChannel.frames(25000));
 }
 
void draw()
{
 background(0);
 String s = " " ;
 float r = sqrt(pow((mouseX-0), 2) + pow((mouseY-0), 2));
 s = "r="+r +  " ";
 println(440 + r/10.0);
 
 myWave=new SineWave(440 +r/10.0 , 0.5);
 myWave.generate(myChannel);
 myChannel.play(Ess.FOREVER);
 }
 
 public void stop()
 {
 Ess.stop();
 super.stop();
}

//-----------------------------------------------------------------
//second example using FADES
//-----------------------------------------------------------------

import krister.Ess.*;
AudioChannel myChannel;
SineWave myWave;

AudioStream myStream; // Audio stream to write into
FadeOut myFadeOut; // Amplitude ramp function
FadeIn myFadeIn; // Amplitude ramp function

void setup()
{
 size(800,600);
 Ess.start(this);
 myStream = new AudioStream(); // Create a new AudioStream
 myStream.smoothPan = true;
 myChannel=new AudioChannel();
 myChannel.initChannel(myChannel.frames(25000));
 myWave = new SineWave(440, 0.5); // Initialize the oscillators
 
 
 myFadeOut = new FadeOut(); // Create amplitude ramp
 myFadeIn = new FadeIn(); // Create amplitude ramp
 myStream.start(); // Start audio
 }
 
void draw()
{
 background(0);
 String s = " " ;
 float r = sqrt(pow((mouseX-0), 2) + pow((mouseY-0), 2));
 s = "r="+r +  " ";
 println(440 + r/10.0);

 myWave=new SineWave(440 +r/10.0 , 0.5);
 myWave.generate(myStream); // Generate first sine, replace Stream
 myWave.phase += myStream.size; // Increment the phase
 myWave.phase %= myStream.sampleRate;
 
 myFadeOut.filter(myStream); // Fade down the audio
 myFadeIn.filter(myStream); // Fade up the audio

 }
 
 public void stop()
 {
 Ess.stop();
 super.stop();
}
Page Index Toggle Pages: 1