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 › control frequency with minim
Page Index Toggle Pages: 1
control frequency with minim (Read 2046 times)
control frequency with minim
Jul 5th, 2009, 9:02am
 
Hej,

I started programming couple weeks ago and getting really into it. But for a few days now I ve been trying  to figure out a way to control the frequency of a soundfile by analog input of pressure sensors. I'm using arduino and processing. (My soundfile is not a regular sine/saw wave, but an existing peace of sound which Iwant to loop the whole time)
I'm building on this example code on minim, but simply exchanging the sine wave with a Snippet just won't work... Probably its a typical beginner's question... but if anyone would care to answer I'd be soooo happy to hear from anyone!

Amelie

import ddf.minim.*;
import ddf.minim.signals.*;

Minim minim;
AudioOutput out;
SineWave sine;

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

 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
 sine = new SineWave(440, 0.5, out.sampleRate());
 // set the portamento speed on the oscillator to 200 milliseconds
 sine.portamento(200);
 // add the oscillator to the line out
 out.addSignal(sine);
}

void draw()
{
 background(0);
 stroke(255);
 // draw the waveforms
 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);
 }
}

void mouseMoved()
{
 // with portamento on the frequency will change smoothly
 float freq = map(mouseY, 0, height, 1500, 60);
 sine.setFreq(freq);
 // pan always changes smoothly to avoid crackles getting into the signal
 // note that we could call setPan on out, instead of on sine
 // this would sound the same, but the waveforms in out would not reflect the panning
 float pan = map(mouseX, 0, width, -1, 1);
 sine.setPan(pan);
}

void stop()
{
 out.close();
 minim.stop();

 super.stop();
}


Re: control frequency with minim
Reply #1 - Jul 5th, 2009, 9:35am
 
Hello

I'm newbie as well but I think that oscillator generates it's own signal.

Try IIRFilter to work from your own audio file:
http://code.compartmental.net/tools/minim/manual-iirfilter/

Re: control frequency with minim
Reply #2 - Jul 5th, 2009, 10:36am
 
sounds definitly like an interesting option, which totally got out of my sight. Thanks!
Re: control frequency with minim
Reply #3 - Apr 13th, 2010, 2:20am
 
amelie wrote on Jul 5th, 2009, 9:02am:
Hej,

I started programming couple weeks ago and getting really into it. But for a few days now I ve been trying  to figure out a way to control the frequency of a soundfile by analog input of pressure sensors. I'm using arduino and processing. (My soundfile is not a regular sine/saw wave, but an existing peace of sound which Iwant to loop the whole time)
I'm building on this example code on minim, but simply exchanging the sine wave with a Snippet just won't work...


if you wanna change a samples playback rate i recommend sonia (or beads if you wanna play sounds backwards too). i find sonia http://sonia.pitaru.com/ more easy to use.

also, minims sine wave generator generates it's own sound an you can't just exchange this with an audio sample/snippet but would have to use AudioSample or AudioPlayer and it's methods. however minims sample rate control doesn't seem to work. see: http://processing.org/discourse/yabb2/num_1263411934.html

cheers,
jns
Page Index Toggle Pages: 1