minim change frequency
in
Core Library Questions
•
1 year ago
import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.effects.*;
Minim minim;
AudioOutput out;
SineWave square;
LowPassSP lowpass;
void setup()
{
size(512, 200);
minim = new Minim(this);
// get a stereo line out with a sample buffer of 512 samples
out = minim.getLineOut(Minim.STEREO,512);
// create a SquareWave with a frequency of 440 Hz,
// an amplitude of 1 and the same sample rate as out
square = new SineWave(440, 1, 44100);
// create a LowPassSP filter with a cutoff frequency of 200 Hz
// that expects audio with the same sample rate as out
lowpass = new LowPassSP(200, 44100);
// now we can attach the square wave and the filter to our output
out.addSignal(square);
out.addEffect(lowpass);
}
void draw()
{
background(0);
stroke(255);
// we draw the waveform by connecting neighbor values with a line
// we multiply each of the values by 50
// because the values in the buffers are normalized
// this means that they have values between -1 and 1.
// If we don’t scale them up our waveform
// will look more or less like a straight line.
for(int i = 0; i < out.bufferSize() - 1; i++)
{
line(i, 50 + out.left.get(i)*50, i+1, 50 + out.left.get(i+1)*50);
line(i, 150 + out.right.get(i)*50, i+1, 150 + out.right.get(i+1)*50);
}
}
// here we provide a way to mute out
// because, let's face it, it's not a very pleasant sound
void keyPressed()
{
if ( key == 'm' )
{
if ( out.isMuted() )
{
out.unmute();
}
else
{
out.mute();
}
}
}
void stop()
{
out.close();
minim.stop();
super.stop();
}
i have this and i have some questions:
1why do we put the sound thing in the setup section?
2the draw section does loops. the setup section doesnt. so if i want to do loops with the sound: for example choose random numbers for the frequencies if i write the random function it just plays only one random waveform and it doesnt change the frequency value in relation with a frame rate. can somebody help me?
import ddf.minim.signals.*;
import ddf.minim.effects.*;
Minim minim;
AudioOutput out;
SineWave square;
LowPassSP lowpass;
void setup()
{
size(512, 200);
minim = new Minim(this);
// get a stereo line out with a sample buffer of 512 samples
out = minim.getLineOut(Minim.STEREO,512);
// create a SquareWave with a frequency of 440 Hz,
// an amplitude of 1 and the same sample rate as out
square = new SineWave(440, 1, 44100);
// create a LowPassSP filter with a cutoff frequency of 200 Hz
// that expects audio with the same sample rate as out
lowpass = new LowPassSP(200, 44100);
// now we can attach the square wave and the filter to our output
out.addSignal(square);
out.addEffect(lowpass);
}
void draw()
{
background(0);
stroke(255);
// we draw the waveform by connecting neighbor values with a line
// we multiply each of the values by 50
// because the values in the buffers are normalized
// this means that they have values between -1 and 1.
// If we don’t scale them up our waveform
// will look more or less like a straight line.
for(int i = 0; i < out.bufferSize() - 1; i++)
{
line(i, 50 + out.left.get(i)*50, i+1, 50 + out.left.get(i+1)*50);
line(i, 150 + out.right.get(i)*50, i+1, 150 + out.right.get(i+1)*50);
}
}
// here we provide a way to mute out
// because, let's face it, it's not a very pleasant sound
void keyPressed()
{
if ( key == 'm' )
{
if ( out.isMuted() )
{
out.unmute();
}
else
{
out.mute();
}
}
}
void stop()
{
out.close();
minim.stop();
super.stop();
}
i have this and i have some questions:
1why do we put the sound thing in the setup section?
2the draw section does loops. the setup section doesnt. so if i want to do loops with the sound: for example choose random numbers for the frequencies if i write the random function it just plays only one random waveform and it doesnt change the frequency value in relation with a frame rate. can somebody help me?
1