Sound 3: Coding Audio Signals Using Beads

Intro To Audiovisual Computing

Coding Audio Signals

Digital Audio signals

  • 1 dimensional array of floating point numbers
  • Normalised between -1. and 1.
  • Digital representation of speaker movement (back and forth).
  • Amplitude of a waveform

Revision – Formats

  • 44,100 samples per second
  • Why this many samples?
  • What is a frequency, and how do we measure it?
  • Usually 16 bits per sample (two bytes).
  • Why this many bits?
  • Mono == 1 channel. Stereo == 2 channels

Signal Processing

  • When creating audio software, it’s often good to imagine a ‘signal chain’
  • i.e. a series of steps that the signal goes through.
  • We can think of each step in the chain as a function that transforms the audio signal.
  • You may have done some basic maths for this already.

Signal Processing

There are a number of cool things you can do like this.

  • Sound synthesis
  • Sample playback and manipulation
  • Filtering (convolution)
  • Amplitude analysis (beat detection)
  • Frequency analysis (pitch and texture detection)
  • Complex transformations for Music Information Retrieval
  • Mental Plug-ins

UGen Model

  • One way of approaching audio signal processing is the Ugen model.
  • A Ugen (Unit Generator) performs a function that allows us to manipulate audio. e.g., iterating through an array of samples (playing the sound back), altering the amplitude (mixing), detecting frequency information.
  • You can think of a UGen as a bunch of guitar effects pedals plugged into each other.
  • This is similar to the way PD and Max MSP works.
  • More common in text based audio programming languages
  • Supercollider
  • http://www.audiosynth.com/

Beadsproject.net

  • Beads project is a UGen based audio library for Java.
  • Works well with Processing.
  • Significantly more powerful than Minim or ESS.
  • Much more reliable.
  • Optimised.
  • Designed for audio software development.
  • Cutting edge signal processing.

www.beadsproject.net

Using Beads

  • When you draw things in Processing, you need to have a screen to draw onto. You set this up in void setup()
  • When you want to play sound back, you should ideally have some master inputs and outputs to send sound to.
  • THIS IS CALLED AN “AUDIO CONTEXT

AudioContext ac; // ac is the name of you audiocontext

  • Then you need to plug in some UGens to make sound.
  • You can put all of this in void setup()

Using Beads

Once you have an Audio Context, you can plug things into it.

ac = new AudioContext();//your new mixer
Noise n = new Noise(ac);//a UGen that makes white noise
Gain g = new Gain(ac, 1, 0.1);//a UGen that controls volume.
//syntax for Gain is (audiocontext (string), numberOfChannels (int) , volume (float))
g.addInput(n);//plug the noise object into the gain object
ac.out.addInput(g);//plug the gain object into the mixer
ac.start(); // turn it on and turn it up!

Note that you are plugging into the mixer, and this is sending the input to its output!!!
(ac.out.addInput(g)).

Using Beads

You can play back samples in beads really easily once you’ve set up an audiocontext.

String audioFile = selectInput();// This tells the program to ask for a file called audioFile
//The next line creates a new sample player called player, connects it to the audio context
//and loads the sample called audioFile
SamplePlayer player = new SamplePlayer(ac, SampleManager.sample(audioFile));
//The rest is the same as before, although you’re now plugging in your sample player
Gain g = new Gain(ac, 2, 0.2); // now we have 2 channels, not 1.
g.addInput(player);
ac.out.addInput(g);
ac.start();

Streaming Samples instead of loading

One great thing about beads is that you can stream the audio in chunks. This speeds things up a lot.

//you should specify that you want to stream the
//file before you<span> </span>create your sampleplayer
//the syntax is a bit weird, but it works!
SampleManager.setBufferingRegime(Sample.Regime.newStreamingRegime(1000));

//the time is the stream buffer size in ms.

Envelopes

You can use envelopes to shape the sound over time.

This allows you to create fade-ins, fade-outs, change the playback speed and other more complex modulations.

The envelop UGen is called Envelope

Using Envelopes

You need to have an audiocontext, and a UGen to apply the envelope to (use the previous example)

Envelope ampEnv = new Envelope(ac, 0);
//the number 500 is the starting value
//you then need to add a new stage, or segment
//to the envelope. Beads keeps track of the timing on its own!!
ampEnv.addSegment(1, 10000);//go to 1 in 10 seconds
//BUT CAN BE ANY VALUE!!!
 
//you can then use it to control the gain level
Gain g = new Gain(ac, 1, ampEnv);//ampEnv now controls the fader level
g.addInput(player);//our sample player
ac.out.addInput(g);
ac.start();
PDF Creator    Send article as PDF to