Simple Synthesizer Part 1

Download Report

Transcript Simple Synthesizer Part 1

Simple Synthesizer Part 2
Based on Floss Manuals (Pure Data)
“Building a Simple Synthesizer”
By Derek Holzer
Slides by Denny Lin
Copyright © 2011 by Denny Lin
1
Generating Waveforms
• The Fourier theorem states that any
complex waveform can be broken down
into a series of sine waves
• Thus, any complex waveform can be
generated by adding sine waves
• Resulting waveforms are bandlimited, has
less aliasing noise, and sounds “warmer”
than those produced with the phasor~
object
Copyright © 2011 by Denny Lin
2
Internal messages
• Internal messages are message objects
that send a message to the PureData
application.
• Can be used to perform various audio
processing tasks, including write
waveforms
• Stored in a message object that starts with
a semicolon
Copyright © 2011 by Denny Lin
3
Sine Wave
• The internal message:
;
waveform sinesum 2051 1
• Generates an internal message sent to an array named
waveform
• The word sinesum specifies a series of harmonics
• 2051 specifies the number of units on the X range of the
waveform array
• 1 specifies the peak amplitude of the first harmonic;
since a sine wave has only one harmonic, this is the last
item on the list of harmonics
• Output is a sine wave graphed in the array waveform
• Must use tabread4~ to play the waveform
Copyright © 2011 by Denny Lin
4
Saw tooth Wave
• The formula for a saw tooth is 1/h, where h is the
number of the harmonic:
–
–
–
–
First harmonic = 1/1 = 1
Second harmonic = 1/2 = 0.5
Third harmonic = 1/3 = 0.333
Fourth harmonic = 1/4 = 0.25
• The message:
;
Waveform1 sinesum 2051 1 0.5 0.333 0.25
• Generates a saw tooth wave with the first 4 harmonics
• Can get a better approximation by adding more
harmonics to calculate the waveform
Copyright © 2011 by Denny Lin
5
Triangle Wave
• The triangle wave contains only odd numbered
harmonics (locations for even harmonics contain 0’s)
• Odd harmonics are formed by dividing 1 by the square of
the harmonic number
• Every other odd harmonic is multiplied by-1:
–
–
–
–
–
–
–
First harmonic: 1/1 = 1
Second harmonic: 0
Third harmonic: (-1) * 1/32 = -1/9 = -0.11111
Fourth harmonic: 0
Fifth harmonic: 1/52 = 1/25 = 0.04
Sixth harmonic: 0
Seventh harmonic: (-1) * 1/72 = -1/49 = 0.02041
Copyright © 2011 by Denny Lin
6
Square Wave
• The square wave contains only odd-numbered
harmonics (locations for even harmonics contain
0’s)
• Odd harmonics are formed by dividing 1 by the
harmonic number:
–
–
–
–
–
–
–
First harmonic: 1/1 = 1
Second harmonic: 0
Third harmonic: 1/3 = 0.33333
Fourth harmonic: 0
Fifth harmonic: 1/5 = 0.2
Sixth harmonic: 0
Seventh harmonic: 1/7 = 0.14286
Copyright © 2011 by Denny Lin
7
Normalizing and DC Offset
• Normalizing a signal means to adjust the signal
gain so that its peak dynamic range fits a target
range without signal clipping
• DC Offset is the signal’s offset from the zero line.
Also known as the mean amplitude of a
waveform: if mean amplitude is 0, DC offset is 0
• We typically normalize an audio signal to
maximize its dynamic range, and remove any
DC offset to preserve signal headroom
Copyright © 2011 by Denny Lin
8
Normalize Square Wave and
Remove DC Offset
• Multiplying square
wave by 2 doubles
the dynamic range
• Subtracting signal by
1 removes DC offset
so the square wave
oscillates about the
zero line
• These operations can
be built into the expr~
object
Copyright © 2011 by Denny Lin
9
High Pass Filter, Limiter, and Z
• A high pass filter (hip~ object)
with cutoff at 1Hz can be used
to remove any DC offset
• A limiter~ object outputs an
amplification factor to keep the
signal within range
• The z~ object is used to
produce a delay (i.e. 64
samples) so that the limiter~
object has enough time to
output an amplification factor
to keep signal within range
Copyright © 2011 by Denny Lin
10
Anti-Aliasing
• Aliasing noise occurs when generated
frequencies exceed the Nyquist frequency
or half the audio sampling rate
• Aliasing noises are sometimes called
“birdies”
• Anti-aliasing techniques include
oversampling, low-pass filtering, and using
band-limited waveforms as signal source
Copyright © 2011 by Denny Lin
11
Oversampling and Low-Pass
Filtering
• Use the block~ object
and pass in creation
arguments 1024 1 16
– Sets the block size to 1024
samples
– Oversample by a factor of
16
• In this patch, a
Butterworth filter with
cutoff frequency of 15KHz
low-pass filters the
phasor signal
Copyright © 2011 by Denny Lin
12
Band-limited Waveform
• Fewer undesirable
harmonics are found in
band-limited waveforms
produced with sinesum
• This example generates a
saw tooth by adding up
nine sine waves
• The phasor~ output is
multiplied by 2048 and is
used to look up the index
of the array to be played
Copyright © 2011 by Denny Lin
13