Sound 4: Using Beads to Make Stuff Happen

More Sound and Music

Using beads to make stuff happen

Last week we learned the following
  • What an audio context is
  • how to create one
  • How to play back sounds
  • How to create the UGens
  • How to control them
  • How to create a signal chain
  • How to change the volume of sounds
  • How to change gain
  • How to use envelopes

Beads 2

This week we will look at two really important things:
  • How to play back sounds at certain times
  • How to create and delete UGens on the fly
This involves a chain of nested functions!!!


To make things happen at different times, you need to create a clock

Clock clock = new Clock(ac,125);
//this  creates a clock object in the audiocontext ac. The clock sends a beat every 125 ms

It’s exactly like PD’s [metro] object


  • In order to make a UGen play back in time with the clock, you need to make it ‘listen’.
  • The UGen gets called inside a function called addMessageListener
  • We can dynamically create and delete UGens at certain times specified by the clock within this method

The function looks like this

clock.addMessageListener(do stuff);

We can create and delete UGens on the fly by specifying them within another function called

Bead() {}

If we create a new Bead, it can have loads of UGens in it.

So the whole thing looks like this:

new Bead() {
//beads stuff

Like a string of beads on a necklace

Listening to the Clock

The method ‘messageReceived(Bead message) is the next function in the ‘chain’

public void messageReceived(Bead message) {
Clock c = (Clock)message;
//test the clock, and create our beads
Now we’re ready to rock. Our clock message is called c. It’s a cable that carries the clock ticks to our beads (UGens).

Create our Beads

//test to see which beat division we are on. 4 will be true every 4 ticks of the clock.
if(c.isBeat(4)) {
//Now we can create our UGens. Let’s start with an envelope.
//We’ll use this envelope to change control the pitch of a sinewave
Envelope freqEnv = new Envelope(ac,250); //starting segment is at 250 hz.
//Now we create a UGen called a ‘WavePlayer’. It takes our envelope as an arg.
//it also takes an argument that specifies we want a SINEWAVE.
WavePlayer wp = new WavePlayer(ac, freqEnv, Buffer.SINE);
// Now we add a second segment that takes the pitch to 0 in 200 ms.
freqEnv.addSegment(0, 200);
//Create a gain UGen,
Gain g = new Gain(ac, 1, 1.);//what does this mean?

Tidying up

Now we need to close all our brackets and tidy up
//how many brackets do we need?
);//which function are we closing?
//Finally, we need to make our audio
//context dependent on the clock.
//then we can start

Aha !

  • The problem with our system is that it creates a string of new UGens every time the test is true. We need to kill them.
  • The following code kills off the string of beads.
  • Where does it need to go?
  • Does it replace anything?
  • How does it work?
Gain g = new Gain(ac, 1, new Envelope(ac, 1.));
((Envelope)g.getGainEnvelope()).addSegment(0, 400,new KillTrigger(g));
PDF Download    Send article as PDF to