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 › Help please -- Intermittent sound with minim
Page Index Toggle Pages: 1
Help please -- Intermittent sound with minim (Read 286 times)
Help please -- Intermittent sound with minim
Dec 5th, 2008, 6:11am
 
I've been working for an embarrassingly long time on this simple adaptation of the SineWave example. I want to have the sound heard for only a certain duration of the program. I'm gonna implement this code with visuals, so I'm using frameCount for a timer:

Code:

import processing.opengl.*;
import ddf.minim.*;
import ddf.minim.signals.*;

Minim minim;
AudioOutput out;
SineWave sound1;
SineWave sound2;
SineWave sound3;
int hertz;

void setup()
{
size(512, 200, OPENGL);
frameRate(30);

if (frameCount < 80) {
hertz = 0;
} else if (frameCount >= 80 && frameCount < 160) {
hertz = 440;
} else {
hertz = 220;
}
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
sound1 = new SineWave(hertz, 0.5, out.sampleRate());
sound2 = new SineWave(hertz, 0.5, out.sampleRate());
sound3 = new SineWave(hertz, 0.5, out.sampleRate());
// set the portamento speed on the oscillator to 200 milliseconds
sound1.portamento(200);
sound2.portamento(200);
sound3.portamento(200);
// add the oscillator to the line out
sound1.setFreq(0.4);
sound1.setFreq(0.5);
sound1.setFreq(0.6);
sound1.setPan(285);
sound1.setPan(285);
sound1.setPan(285);
out.addSignal(sound1);
out.addSignal(sound2);
out.addSignal(sound3);
}

void draw()
{
background(0);

}

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

super.stop();
}


This producing no (audible) sound. Without the if statement, hard coding the hertz as 440, plays the chord continuously. Do I need to do something in draw()? Or perhaps have a separate method? Any help ASAP will be appreciated.
Page Index Toggle Pages: 1