Computer Music Synthesis

Download Report

Transcript Computer Music Synthesis

Computer Music Synthesis
Chapter 4
Based on “Excerpt from Designing Sound”
by Andy Farnell
Slides by Denny Lin
Copyright © 2011 by Denny Lin
1
Pure Data Audio
• 4.1 Audio objects
– Audio connections
– Blocks
– Audio object CPU use
• 4.2 Audio objects and principles
–
–
–
–
–
Fan-out and merging
Time and resolution
Audio signal block to messages
Sending and receiving audio signals
Audio generators
Copyright © 2011 by Denny Lin
2
Pure Data Audio
• 4.2 Audio objects and principles (cont’d)
– Audio line objects
– Audio input and output
– A simple MIDI mono-synthesizer example
– Audio filter objects
– Audio arithmetic objects
– Trigonometric and math objects
– Audio delay objects
Copyright © 2011 by Denny Lin
3
Audio connections
• In Pure Data, there are message
connections and audio connections
• Pd does not let you make incompatible
connections (i.e. an audio signal to a
message inlet connection)
• Audio objects have a name ending with a
tilde (~)
• Audio connections (audio cords) look fatter
than message connections
Copyright © 2011 by Denny Lin
4
Blocks
• Signal in audio
connections are made of
samples
• Samples are single
floating point values in a
sequence that form an
audio signal
• A group of (typically 64)
samples make up a block
or vector
• Audio objects do more
work than message
processing objects
Copyright © 2011 by Denny Lin
5
Audio object CPU use
• Message processing objects are idle most of the
time, consuming very few resources
• When computer audio is switched on, the CPU
is processing a constant stream of signal blocks
even if they contain zeros
• Audio signals are processed synchronously with
the soundcard sample rate
• Message operations are executed at the
beginning of each pass of audio block
processing
Copyright © 2011 by Denny Lin
6
Fan-out and merging
• Unlike message objects,
audio signal fan-out and
fan-in have no negative
effects
• Audio block are sent in
connection creation order
• Patches may be easier to
understand when signals
are summed with the
signal addition (+~) object
Copyright © 2011 by Denny Lin
7
Time and resolution
• Pd measures time mostly in milliseconds, but
also in seconds or samples
• Time measurement in samples is based on the
current sampling rate of the program or sound
card of the computer system
• Typically, a sample is 1/44100th of a second, and
is the smallest time unit that can be measured
as a signal
• The metro and vline~ objects can deal in
fractions of a millisecond
Copyright © 2011 by Denny Lin
8
Audio signal block to messages
• The env~ object provides the RMS value
of one block of audio data scaled 0 to 100
in dB
• The snapshot~ object gives the
instantaneous value of the last sample in
the previous block
• The print~ object displays the entire block
when banged, and is used in debugging
Copyright © 2011 by Denny Lin
9
Sending and receiving audio
signals
• Audio send and receive objects are written
as send~ and receive~, or s~ and r~
• Only one audio send can exist with a given
name
• To create a signal bus with many to one
connectivity, use throw~ and catch~
• Within sub-patches and abstractions use
inlet~ and outlet~ to create inlets and
outlets
Copyright © 2011 by Denny Lin
10
Audio generators
• The phasor~ object produces an
asymmetrical periodic ramp wave; the left
inlet specifies frequency; the right inlet
specifies phase between 0.0 and 1.0
• The osc~ object produces sinusoidal
waveforms (has same inlets as phasor~)
• The noise~ object takes no parameters
and generates white noise in the range
-1.0 to 1.0
Copyright © 2011 by Denny Lin
11
Audio generators (cont’d)
• Data stored in tables can be:
– used to generate frequencies with the
tabread~ object
– played as a sound recording with the
tabplay~ object
– read as audio samples with the tabread4~
object
– read as audio waveforms with the tabosc4~
object
Copyright © 2011 by Denny Lin
12
Table oscillator using tabread~
Copyright © 2011 by Denny Lin
13
Table oscillator using tabosc4~
Copyright © 2011 by Denny Lin
14
Sample replay from arrays
Copyright © 2011 by Denny Lin
15
Audio line objects
• The line~ object can be used to control
audio signals and simple envelopes
• A line~ object’s inlet takes a list of items:
– First item specifies a target level
– Second item specifies time to get to target
level
• The vline~ object can be used to generate
complex envelopes
Copyright © 2011 by Denny Lin
16
Interpolation
• Some PureData objects
(i.e. line~, vline~,
tabread4~, tabosc4~) use
interpolation to fill in
audio signal data
between two or more
points
• Here are animations of
Bezier curves (red lines)
for interpolating signals
between 2, 3 and 4 points
See:
http://en.wikipedia.org/wiki/Bézier_curve
Copyright © 2011 by Denny Lin
17
Audio input and output
• Audio input is handled by the analog to
digital converter (adc~) object
• Audio output is handled by the digital to
analog converter (dac~) object
• By default, they offer two inlets or outlets
for stereo operation
Copyright © 2011 by Denny Lin
18
A simple MIDI mono-synthesizer
•
•
•
•
•
•
•
•
The notein object gets MIDI data from
keyboard
The stripnote object passes non-zero
velocity MIDI numbers to left outlet, and
passes velocity values (1 to 127) to its right
outlet
The mtof object converts MIDI numbers to
frequencies
The trigger object bangs vline message first
before sending frequency to osc~
vline~ message: start at 0, end at 1 in 10 ms
after 0 ms delay; return to 0 in 100 ms after
20 ms delay
First *~ object controls amplitude envelope
from vline~ object
Second *~ object is master volume control
based on velocity value from stripnote
object, scaled to 0 and 1
Stereo output produced by dac~ object
Copyright © 2011 by Denny Lin
19
Anatomy of a vline~ message
Copyright © 2011 by Denny Lin
20
Audio filter objects
• The lop~ and hip~
objects are low and high
pass filters, respectively.
Their first argument is the
cutoff frequency
• The bp~ and vcf~ objects
are band-pass and
voltage controlled filters,
respectively. Their two
arguments are: cutoff
frequency and resonance
(typically, a number
between 0 and 10)
500hz low pass filter
500hz high pass filter
100hz band pass filter, resonance 3
100hz voltage controlled filter,
resonance 2
Copyright © 2011 by Denny Lin
21
Audio arithmetic objects
Copyright © 2011 by Denny Lin
22
Trigonometric and math objects
* Available through external libraries in some Pd versions
Copyright © 2011 by Denny Lin
23
Audio delay objects
• The delwrite~ object
writes audio data into
a delay buffer through
its left inlet
• The delread~ object
reads the delayed
signals from buffer
• The vd~ object is 4
point interpolating
variable delay object
Write to mydelay buffer of size 500ms
Reads the mydelay buffer
Reads the variable delay buffer mydelay
Copyright © 2011 by Denny Lin
24
FFT Spectrum Analysis
• Joseph Fourier (1768 – 1830) proposed that all
periodic signals are made of a sum of simpler
periodic oscillations (sines and cosines).
• Through Fourier analysis, signals can be
transformed between time and frequency
domains.
• Fast Fourier Transformation (FFT) allows real
time conversions of a graph depicting signal
amplitude over time (i.e. oscilloscope), to
another that depicts signal amplitude over
frequency (i.e. spectrum analyzer).
Copyright © 2011 by Denny Lin
25
Fourier Transform in PD
• The rfft object: Real Forward Discrete Fourier Transform.
– Inlet receives a time domain signal
– Left outlet sends the magnitude (real or cosine) component of
frequency domain signal
– Right outlet sends the phase (complex or sine) component of
frequency domain signal
Copyright © 2011 by Denny Lin
26
PD Spectrum Analyzer
Copyright © 2011 by Denny Lin
27