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 › minim library: create sine wave with new sound
Page Index Toggle Pages: 1
minim library: create sine wave with new sound (Read 1394 times)
minim library: create sine wave with new sound
Jul 6th, 2009, 6:31am
 
Hello, it's me again...
I'm trying to figure out a way to use a sinewave (sine wave because I need to change the frequency by pressure sensors connected to an arduino board) but don't want it to sound like a Sine Wave. I want to add a different wave to make it sound like violins e.g. Just like an sythethizer works with midi data. Is there a software solution? Can I just add something in my processing code?

Thanks in advance, maybe someone has an idea how i can fix that problem or knows where I can get specific information.


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

 frameRate(200);
 myport = new Serial(this, Serial.list()[1], 9600);

 minim = new Minim(this);
 // get a line out from Minim, default bufferSize is 1024, default sample rate is 44100, bit depth is 16
 out = minim.getLineOut(Minim.STEREO);

// create a sine wave Oscillator, set to 440 Hz, at 0.5 amplitude, sample rate from line out
 sine1 = new SineWave(440, 0.5, out.sampleRate());
 sine2 = new SineWave(440, 0.5, out.sampleRate());
 sine3 = new SineWave(440, 0.5, out.sampleRate());
 sine4 = new SineWave(440, 0.5, out.sampleRate());

sine1.portamento(200);
 sine2.portamento(200);
 sine3.portamento(200);
 sine4.portamento(200);
 // add the oscillator to the line out
 out.addSignal(sine1);
 out.addSignal(sine2);
 out.addSignal(sine3);
 out.addSignal(sine4);
 
 int [] Sensorliste={ vala, valb, valc, vald  };

}



void draw()
{


println(Sensorliste);
   float freq1 = map(Sensorliste[0], 0, 1023, 1500, 60);   // Sensorliste ist der array in den ich die vier verschiedenen Werte der Sensoren einspeise
   sine1.setFreq(freq1);
   float freq2 = map(Sensorliste[1], 0, 1023, 1500, 60);
   sine2.setFreq(freq2);
   float freq3 = map(Sensorliste[2], 0, 1023, 1500, 60);
   sine3.setFreq(freq3);
   float freq4 = map(Sensorliste[3], 0, 1023, 1500, 60);
   sine4.setFreq(freq4);
   
// Pan = Ausrichtung: Since Oscillators are MONO signals,
//you can set a pan value for them. This is where “in space” the signal will
// sound between two speakers. -1 is “hard left”, 1 is “hard right”, and 0 is “center”.  
   sine1.setPan(1);
   sine2.setPan(1);
   sine3.setPan(-1);
   sine4.setPan(-1);

   for(int i = 0; i < out.bufferSize() - 1; i++)
   {
     float x1 = map(i, 0, out.bufferSize(), 0, width);
     float x2 = map(i+1, 0, out.bufferSize(), 0, width);
     line(x1, 50 + out.left.get(i)*50, x2, 50 + out.left.get(i+1)*50);
     line(x1, 150 + out.right.get(i)*50, x2, 150 + out.right.get(i+1)*50);
   }

 }
}
Page Index Toggle Pages: 1