..simple example of how to use filters?

353 views
Skip to first unread message

stckfrm

unread,
Jul 16, 2010, 10:57:50 AM7/16/10
to beadsproject
Hi there,

I've only just started using Beads for a uni project to make some
prototypes of multi-agent systems in audio. It's a great library and
I'm having a lot of fun with it, but I was a little confused about how
to use the filter classes.

I'm not an especially experienced programmer and although I'm sure I'd
be able to figure it out given enough time, I wondered whether someone
might be able to post some simple example code of how to apply a
LPRezFilter or BiquadFilter to a sine wave, just to get me started in
the right direction. Also, filtering is a pretty common application in
audio processing and I thought it might be helpful to any other
beginners if there were a couple of examples of how to use the
LPRezFilter or BiquadFilter classes up on here or on the main site.

Any help would be much appreciated,

Greg


P.S. Feel free to scold me if I've overlooked any examples that were
already posted but I couldn't find any when I searched..

Oliver Bown

unread,
Jul 19, 2010, 5:32:04 AM7/19/10
to beadsp...@googlegroups.com
Hi Greg,

there are some examples in preparation but not currently in the tutorials, only if you grab the whole Beads project using SVN (in which case they're in src/beads_examples).

Here are a couple from Biquad Filter...

A simple one...

//BEGIN CODE//

// Create our audio context.
AudioContext ac = new AudioContext();
// Start with some white noise as source material.
Noise n = new Noise(ac);
// Create a 2-channel band-pass filter with constant peak gain.
BiquadFilter bf = new BiquadFilter(ac, 2, BiquadFilter.BP_PEAK);
// Set the filter's frequency and Q-value.
bf.setFrequency(440).setQ(90);
// Add the white noise to the filter's inputs.
bf.addInput(n);
// Send the result to audio out.
ac.out.addInput(bf);
// Don't forget to start the audio running!
ac.start();


//END CODE//

And a less simple one...

//BEGIN CODE//

AudioContext ac = new AudioContext();
// Start with white noise.
Noise n = new Noise(ac);
// Create a 1-channel low-pass filter.
BiquadFilter bf = new BiquadFilter(ac, 2, BiquadFilter.LP);
// Create a "wave" by using a slow sine wave.
WavePlayer sine = new WavePlayer(ac, .3f, Buffer.SINE);
Function freq = new Function(sine) {
public float calculate() {
return x[0] * 600f + 800f;
}
};
// Set the filter parameters.
bf.setFrequency(freq).setQ(1);
// Add the white noise to the filter's inputs.
bf.addInput(n);
// Send the result to audio out.
ac.out.addInput(bf);
// Don't forget to start the audio running!
ac.start();


//END CODE//

The other filters work in similar ways. Please let me know if this is any help, or you can scold me if it's not.

O

PS: My current favourite is square wave through biquad and reverb.

> --
> You received this message because you are subscribed to the Google Groups "beadsproject" group.
> To post to this group, send email to beadsp...@googlegroups.com.
> To unsubscribe from this group, send email to beadsproject...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/beadsproject?hl=en.
>

stckfrm

unread,
Jul 27, 2010, 6:26:14 PM7/27/10
to beadsproject
Great! That was just what I was looking for.. Now I've got a whole new
toy to play with.

Thanks,
Greg

PS. I'll make sure to try it out ;)
Reply all
Reply to author
Forward
0 new messages