The MP4 – Structured Audio Language. By Van Bucsko May 7, 2008. Intro – What is SAOL?. SAOL is a standard programming language that specifies sound as a computer program that generates audio when it is executed, as opposed to just audio data. - PowerPoint PPT Presentation
Citation preview
Slide 1By Van Bucsko
May 7, 2008
Intro – What is SAOL?
SAOL is a standard programming language that specifies sound as a
computer program that generates audio when it is executed, as
opposed to just audio data.
It is pretty similar to C++ as far as logic, expressions, and math
go, but there are several differences in variables, the kinds of
files each can play and so on.
Numbers and Names
global blocks
Standard Names
Global Parameters:
5 kinds
Expressions and Statements
Arithmetic Expressions Unary (-) takes precedence over both the
binary classes (+, - and *, /)
All binary and unary operations in SAOL follow a rate rule – the
rate of an expression is the rate of its fastest
subexpression.
i-rate is the slowest, k-rate is faster and a-rate is the fastest
rate
Arrays and Other Expressions
declared exactly like in C++; use the same syntax and
numbering
indexed arrays in SAOL are scalars – the array takes on the fastest
rate possible
Ex. ivar i[2]; ksig k; asig a[3];
SAOL basically uses the same operators for less than, greater than,
less than/equal to, greater than/equal to, and not equal
exceptions – if both operands are scalar width (1), with
&&, the right subexpression is only evaluated if the left
one is true - opposite for || - right subexpression is evaluated
only if the left one is false
Switch – switch operator takes the logical value of the first
non-zero operand (there are 3 operands with switch)
if at least one subexpression has width greater than 1, all three
subexpressions are evaluated
More Statements and a Loop
Assigment Statements
the syntax for these statements is lval (a instr parameter or
signal variable that receives the new value) = expr (an expression
evaluated to generate the value to assign).
these statements also have rules about width because an lval can be
a scalar or array variable – both the lval and expression have to
be scalar width
If & If – Else
if (note > 5) // expr i-rate
{
While Statement
only loop used in SAOL; executed basically exactly like in
C++
statement in parentheses must be scalar width, and (along with all
the statements in the set), must run at the same rate
Core opcodes
What are they? Core Opcodes basically serve the same function as
library functions do in C++.
Opcode calls basically act like parameters or variables in
expressions.
Transcendentals :
Trigonometric Opcodes - forward trig opcodes take angle parameters
in units of radians, and inverse trig opcodes return angle values
in radians
The trig opcodes are asin, acos and atan.
there are no tan or hyperbolic functions in the opcode library, so
there are replacements in the Slib library.
There are also log, log10 and sqrt opcodes.
Loudness, Tempo and Pitch opcodes
Loudness -Waveform amplitude is often converted to the decibel (dB)
scale to express loudness.
Ex. opcode dbamp(xsig x)
SAOL has two rate-polymorphic core opcodes that handle conversion
between amplitude and dB units: the dbamp and ampdb.
Pitch – a set of 12 rate-polymorphic core opcodes handles
conversions between three note name encodings and cycles per
second.
the opcodes are named by the abbreviations for the four kinds of
pitches, cps, midi, pch and oct.
the oct and pch types are octave-fraction and pitch class notation
respectively, which use float numbers; the integer part of the
number for both types is the octave number from a full keyboard.
Also oct opcodes may return values between the 12 note steps. The
pch opcodes give values rounded to the nearest semitone (in .01
increments).
Tempo – the global tempo can be changed in SAOL from the default 60
beats per minute through the k-rate core opcode settempo.
Ex. kopcode settempo(ksig x)
opcode gettempo([xsig dummy])
Declarations:
First you have to declare a table (and follow the naming
rules).
To import tables, an instr parameter accesses a global wavetable by
declaring an instr wavetable with the same name as the global
wavetable.
SAOL has a special data type called the tablemap which is an array
of wavetables to support some wavetable applications that create a
set of sample buffers.
More Wavetables
Periodic Waveforms – 3 wavetable generators produce a single cycle
of a periodic waveform
harm, the simplest generator, specifies a waveform as a harmonic
series of N zero-phase sine waves; can be used to generate a pure
tone
harm_phase generator specifies an amplitude parameter and a phase
parameter to each sinusoid (or curve of the sine function), and the
periodic generator also adds a frequency parameter
buzz generator specifies an algorithm for generating a family of
pulse-like waveforms using only a few parameters.
Envelope Waveforms – 5 generators (step, lineseg, expseg, spline,
cubicseg) produce wavetables useful for signal envelopes
For each one, the envelope is specified as a piece-wise waveform,
and the generators interpolate between the break points to create a
waveform
the cubic equations should not be too complex, they are way too
complex to calculate manually, so it’s best to use a computer
program
Sound Files
2nd parameter of generator sample specifies the name of the audio
file to be read into the table.
1st parameter specifies the size of the wavetable.
Only certain types of AIFF (the kind of music file on a CD) or WAV
files are supported by sfront, a translator that converts MP4-SA
files into efficient C programs.
The opcode speedt shrinks the size of the wavetable without
changing the pitch in the sample.
10
4 core opcodes play back wavetables.
Each core opcode has an internal pointer to the wavetable that
always starts at the first sample.
2 of them, koscil and doscil are specialized for creating signals
by repeating a cycle of a waveform stored in a table.
Table Playback (cont’d.)
The doscil opcode plays back the wavetable t once and then returns
0. It also considers the the wavetable to be a recording of a
pitched sound.
The loscil opcode enhances doscil by playing back the wavetable at
a set pitch.
Ex. aopcode oscil(table t, asig freq [,ivar loops])
kopcode koscil(table t, ksig freq [,ivar loops])
Low-Level Opcodes
9 opcodes produce settings for the wavetable t:
fsetsr and fsetbase set the sampling rate and base frequency,
respectively.
ftsetloop and ftsetend change the loop start and ending points
respectively.
ftlen, ftsr, ftbasecps, ftloop and ftloopend return the values of
the length, sampling rate, base frequency, and loop start and end
points.
Tableread and tablewrite read and write values into the
wavetables.
Low-level Generators
polynomial fills a wavetable with nth order polynomial
values.
concat takes a list of wavetables as parameters, joins them
together and then initializes its own wavetabl
Random fills a wavetable with pseudorandom values, and a
distribution number of 1-5 tells the distribution type.
Window produces a wavetable to one of a set of windowing
functions.
Output Statement
SAOL instruments have one audio output port each, and each one
holds the instrument’s audio output.
Every SAOL program includes an output_bus, the width of which is
set by the global parameter outchannels.
After all instances of execute, the output_bus is summed onto the
system’s final audio output, which usually falls into the range of
-1 and 1, and is sent to a file to be stored or to a converter, so
one can listen to it.
Effects Instruments
An instrument that processes audio output is called an effects
instrument.
An effects instrument usually processes the value held by the
standard input name, and writes a modified version to the audio
output port.
i = 0;
}
Send Statements
Create instances of effects instruments; these statements can only
appear in global blocks.
Have three sections:
1st specifies the name of instrument to be created.
2nd is an expression list, whose values initialize the instrument
parameters of the instance.
3rd specifies the audio input port for the instrument as a list of
at least one bus.
Route Statements
By default, an instrument sends its audio input port to output_bus,
but route statements can change it to go to a user-defined
bus.
A statement consists of a bus name and a list of instruments.
Several route statements can target the same bus.
Signal Flow Graphs
A set of send and route statements act together to form a
diagram.
Send statements create the boxes in the diagram, connected by lines
to and from the boxes that represent the route statements.
Determining Execution Order of Instruments
1st rule – instruments that produce a signal should run before
instruments that use the signal.
2nd rule – if loops are created by the send and route statements,
the order of the send statements creates the order of the
instances.
By default, the instruments run in any order.
Any of the above rules can be overriden by the sequence statement,
which has a list of instruments as parameters and these instruments
are executed in the order listed.
System buses
The input_bus – a system bus that lets SAOl programs process
external audio streams, like WAV files or live mikes.
The output_bus – holds the final output of the SAOL decoder.
Ex. send(rvb; inchan + outchan; input_bus);
// output_bus in a send statement
send(scale; 0.5 ; output_bus);
SASL Scores
SASL score – a list of commands that trigger actions relative to
the clock time the SAOL programs run by.
SASL commands are one line long and are a list of elements.
Instr command
Starts with an optional label
1st required element is the trigger time, which is a float value in
units of beats that says when to create the instance.
2nd – the name of the SAOL instrument to be instantiated.
Then a float duration value that says how long it should
execute.
Control command
Changes the value of a SAOL variable.
Begins with the trigger time, which tells when to change the
value.
Then an optional label element is next, and then the keyword
control is the name of the variable you want to change.
Tempo and End commands
When the tempo command executes, it changes the global tempo
value.
Ex. 0.283 tempo 130.0
0.12 tempo 4
When end executes, the simulation ends, and no more audio is
produced.
Ex. 129.0934 end
globals {
Streaming and SASL
The MP4 binary file format has provisions for certain SASL
commands.
If these commands have timestamps, they follow the trigger
semantics; if not, they are executed at the next possible
opportunity.
A “*” can be added to each command to indicate that it’s higher
priority.
MIDI Basics
What exactly is MIDI in reference to computers and music?
MIDI commands for start and end notes use integers for the notes on
the keyboard (0-127, with 60 as Middle C).
These commands specify a key number, the note value that was
pressed or released, and a channel number (between 0-15).
Many electronic keyboards have a pitch wheel on the side of the
keyboard to bend a note.
MIDI Files can include tempo commands, which change the value of
the global SAOL tempo value.
More MIDI
NoteOn command creates an instance of the instrument that has the
same number as the command channel.
An instance created on a specific channel executes until a NoteOff
executes with that instance.
However, the instance can be delayed with either a Sustain Pedal on
the keyboard, or through the SAOL extend statement to delay the end
of the instance.
Standard Names in MIDI
There are five accepted names that contain info about MIDI:
channel, preset, MIDIbend, MIDItouch, and MIDIctrl.
Channel holds the extended channel number of the command that
created the instance, and preset holds the value of the preset
extended channel value.
MIDIbend, MIDItouch, and MIDIctrl all have to do with the extended
channels associated with the instance, along with certain commands
they are also associated with.
SAOL Dynamic Instruments
The SAOL instr statement performs dynamic instrument instantiation,
so that a child instrument can be copied several times from its
parent.
5 SAOL standard names (time, itime, released, dur and cpuload) let
an instance monitor its execution status.
An instance can delay its termination time with the extend
statement, which works the same as in MIDI.
Turnoff statement can force a program to terminate.
Execution of a SAOL program
1st – all the instruments and wavetables are initialized, and the
instances are also produced with the send statements.
2nd – all SASL or dynamically generated instruments are
initialized, all SASL table, tempo and control and MIDI events and
tempo commands that are ready to execute are run, and instruments
that are supposed to be terminated end.
3rd – like the first step, except all imports variables and table
wavetables are set to an initial value.
4th – all local variables are set to the values of their
corresponding global variables, and all imports exports wavetables
are linked to their associated global wavetables.
Questions? Comments?
Bibliography
Lazzaro, John and Wawrznek, John. The MP4 – Structured Audio Book.
CS Division, UC Berkeley: 1999.
<http://www.cs.berkeley.edu/~lazzaro/sa/book/in
dex.html>
The End. Yay!