Audio Synthesis
Audio Synthesis
Audio Synthesis
Having considered the background theory to digital audio processing, lets consider some practical multimedia related examples:
Digital Audio Synthesis making some sounds Digital Audio Effects changing sounds via some standard effects. MIDI synthesis and effect control and compression
Back Close
Subtractive synthesis FM (Frequency Modulation) Synthesis Additive synthesis Sample-based synthesis Wavetable synthesis Granular Synthesis Physical Modelling
Back Close
Subtractive Synthesis
Basic Idea: Subtractive synthesis is a method of subtracting overtones from a sound via sound synthesis, characterised by the application of an audio lter to an audio signal. First Example: robot (1939). Vocoder talking
84
Back Close
Take the output of a sawtooth generator Use a low-pass lter to dampen its higher partials generates a
more natural approximation of a bowed string instrument than using a sawtooth generator alone.
0.5 0.4 0.3 0.2 0.1 0
85
0.3
0.2
0.1
!0.1
!0.1 !0.2 !0.3
!0.2
!0.3
!0.4 !0.5
!0.4
0 2 4 6 8 10 12 14 16 18 20
10
12
14
16
18
20
Saying or singing ooh and aah (at the same pitch.) Vocal chords are generating pretty much the same raw, rich in
harmonic sound Difference between the two comes from the ltering which we apply with the mouth and throat. Change of mouth shape varies the cutoff frequency of the lter, so removing (subtracting) some of the harmonics. The aah sound has most of the original harmonics still present, The ooh sound has most of them removed (or to be more precise, reduced in amplitude.)
Back Close
Effect widely used in electronic music Basis of the wahwah guitar effect, so named for obvious reasons. We will see how we produce this effect in MATLAB code shortly.
Back Close
Now synthesise a jet plane landing sound Should mostly by use mouth shape to lter the white noise into
pink noise by removing the higher frequencies.
Back Close
When a mechanical musical instrument produces sound, the relative volume of the sound produced changes over time The way that this varies is different from instrument to instrument Examples: Pipe Organ : when a key is pressed, it plays a note at constant volume; the sound dies quickly when the key is released. Guitar : The sound of a guitar is loudest immediately after it is played, and fades with time. Other instruments have their own characteristic volume patterns. Also Note: While envelopes are most often applied to volume, they are also commonly used to control other sound elements, such as lter frequencies or oscillator pitches.
Back Close
91
Back Close
Back Close
input(\nPlay Low Pass Filtered (Low order) ? Y/[N]:\n\n, s); if doit == y, figure(2) plot(yf(1:440)); playsound(yf,Fs); end doit = ... input(\nPlay Low Pass Filtered (Higher order)? Y/[N]:\n\n, s); if doit == y, figure(3) plot(yf2(1:440)); playsound(yf2,Fs); end %plot figures doit = input(\Plot All Figures? Y/[N]:\n\n, s); if doit == y, figure(4) plot(y(1:440)); hold on plot(yf(1:440),r+); plot(yf2(1:440),g-); end
93
Back Close
synth.m
The supporting function, synth.m, generates waveforms as we have seen earlier in this tutorial:
function y=synth(freq,dur,amp,Fs,type) % y=synth(freq,dur,amp,Fs,type) % % Synthesize a single note % % Inputs: % freq - frequency in Hz % dur - duration in seconds % amp - Amplitude in range [0,1] % Fs - sampling frequency in Hz % type - string to select synthesis type % current options: fm, sine, or saw if nargin<5 error(Five arguments required for synth()); end N = floor(dur*Fs); n=0:N-1; if (strcmp(type,sine)) y = amp.*sin(2*pi*n*freq/Fs);
Back Close 94
elseif (strcmp(type,saw)) T = (1/freq)*Fs; ramp = (0:(N-1))/T; y = ramp-fix(ramp); y = amp.*y; y = y - mean(y); % period in fractional samples
elseif (strcmp(type,fm)) t = 0:(1/Fs):dur; envel = interp1([0 dur/6 dur/3 dur/5 dur], [0 1 .75 .6 0], ... 0:(1/Fs):dur); I_env = 5.*envel; y = envel.*sin(2.*pi.*freq.*t + I_env.*sin(2.*pi.*freq.*t)); else error(Unknown synthesis type); end % smooth edges w/ 10ms ramp if (dur > .02) L = 2*fix(.01*Fs)+1; % L odd ramp = bartlett(L); % odd length L = ceil(L/2); y(1:L) = y(1:L) .* ramp(1:L); y(end-L+1:end) = y(end-L+1:end) .* ramp(end-L+1:end); end
95
Back Close
synth.m (Cont.)
Note the sawtooth waveform generated here has a non-linear up slope:
0.2 0.15
0.1
96
0.05
!0.05
!0.1
!0.15 0
10
20
30
40
50
60
70
80
90
100
This is created with: ramp = (0:(N-1))/T; y = ramp-fix(ramp); fix rounds the elements of X to the nearest integers towards zero. This form of sawtooth sounds slightly less harsh and is more suitable for audio synthesis purposes.
Back Close
FM (Frequency Modulation) Synthesis (cont.) Radio broadcasts use FM in a different way FM synthesis is very good at creating both harmonic and
inharmonic (clang, twang or bong noises) sounds For synthesizing harmonic sounds, the modulating signal must have a harmonic relationship to the original carrier signal. As the amount of frequency modulation increases, the sound grows progressively more complex. Through the use of modulators with frequencies that are non-integer multiples of the carrier signal (i.e., non harmonic), bell-like dissonant and percussive sounds can easily be created.
98
Back Close
FM (Frequency Modulation) Synthesis (cont.) Digital implementation true analog oscillators difcult to use
due to instability
99
Back Close
Basic FM Equation:
101
!1
0
1
0.2
0.4
0.6
0.8
1.2
1.4
1.6
1.8
!0.8 !1
0.2
0.4
0.6
0.8
1.2
1.4
1.6
1.8
0.2
0.4
0.6
0.8
1.2
1.4
1.6
1.8
Back Close
MATLAB FM Example
MATLAB code to produce basic FM (fm eg.m, see also fm eg plot.m):
% Signal parameters fs = 22050; T = 1/fs; dur = 2.0; % seconds t = 0:T:dur; % time vector % FM parameters fc = 440; % center freq fm = 30; Imin = 0; Imax = 20; I = t.*(Imax - Imin)/dur + Imin; y = sin(2*pi*fc*t + I.*sin(2*pi*fm*t)); plot(t(1:10000), y(1:10000)); playsound(y, fs);
Back Close 102
e = A{J0sint +J1[sin( + )t sin( )t] +J2[sin( + 2 )t sin( 2 )t] +J3[sin( + 3 )t sin( 3 )t] . . .} Provides a basis for a simple mathematical understanding of FM
synthesis.
104
Back Close
Back Close
FM Synthesis: FM Algorithms
106
How to connect up Operators? Multiple Carriers : One oscillator simultaneously modulates two or more carriers Multiple Modulators : Two or more oscillators simultaneously modulate a single carrier Feedback : Output of oscillator modulates the same oscillator
Back Close
Additive synthesis
Basic Idea: Additive synthesis refers to the idea that complex tones can be created by the summation, or addition, of simpler ones.
107
Each
of the frequency components (or partials) of a sound has its own amplitude envelope. behaviour of these components.
Back Close
Back Close
Sample-based synthesis
Basic Ideas: Similar to either subtractive synthesis or additive synthesis.
110
The principal difference is that the seed waveforms are sampled sounds or instruments instead of fundamental waveforms such as the saw waves of subtractive synthesis or the sine waves of additive synthesis. Samplers, together with traditional Foley artists, are the mainstay of modern sound effects production. Musical genres: Hip-hop, Trip-hop, Dance music, Garage, Jungle, Trance, Modern Electronica invented due to samplers. Most music production now uses samplers.
Back Close
CMI Fairlight (1979) NED Synclavier (1979). EMU Emulator series (1981) Akai S Series (1986) Korg M1 (1988): The M1 also
introduced the workstation concept.
Back Close
Finding looping points Simple idea: Find silence points (zero (ampltiude) crossings) in
sample. E.g. Drum beats
114
Still need some sample across the range of the keyboard As memory became cheaper (and now with software based sample
synthesis), it became possible to use multisampling looping still used in individual samples. Finishing off the loop:
115
Early Days: Use a volume envelope curve to make the sound fade
away.
Back Close
The more energy the sound transports, the louder the sound
will seem. But a sound will be heard as a beat only if his energy is largely superior to the sounds energy history, that is to say if the brain detects a large variation in sound energy. Therefore if the ear intercepts a monotonous sound with sometimes big energy peaks it will detect beats,
Back Close
Back Close
118
Back Close
119
Back Close
Back Close
In software, this is measured by the velocity of a key press etc. Multisampling lays out samples vertically in keymap. Velocity layers layed out horzontally
121
Back Close
122
(Single key mapped) Single Velocity Layer Only one type of sound played at any velocity. Volume output maybe controlled by velocity but not change in timbre of sound.
Back Close
123
124
(Single key mapped) Triple Velocity Layer Three type of sounds played according to velocity. Here upper velocity sound is being played.
Back Close
125
Most instruments are a combination of multisample key mapped and velocity layers
Back Close
Sample-based synthesis Basics: Sample Keyswitching Instruments can make vastly different sounds depending how
they are played
Back Close
Full
orchestras and even choirs that can sing sing words too (Advanced Keyswitching). script control over sampler (Kontakt 2 and above).
Can
Programming
Back Close
Wavetable synthesis
What is Wavetable music synthesis? Similar to simple digital sine wave generation/additive synthesis but extended at least two ways.
128
Back Close
Roland D-50 and Roland MT-32/variants: Linear Arithmetic synthesizers combined complex sampled attack phases with less complex sustain/decay phases (basically a wavetable synthesizer with a 2-entry wave sequence table). Sequential Circuits Prophet-VS, Korg Wavestation: Vector synthesis - move through wavetables and sequences arranged on a 2-dimensional grid.
Back Close
Back Close
131
Back Close
Output waveform is always generated in real time as the CPU processes the wave sequences Waves in the tables are rarely more than 1 or 2 periods in length.
Back Close
Crossfade from one wavetable to the next sequentially. Crossfade = apply some envelope to smoothly merge waveforms.
133
Back Close
f1 = 440; f2 = 500; f3 = 620; Fs = 22050; %Create a single sine waves of frequencie f1 y1 = synth(f1,1/f1,0.9,Fs,sine); doit = input(\nPlay/Plot Raw Sine y1 looped for 10 ... seconds? Y/[N]:\n\n, s); if doit == y, figure(1) plot(y1); loopsound(y1,Fs,10*Fs/f1); end %Create a single Saw waves of frequencie f2 y2 = synth(f2,1/f2,0.9,Fs,saw); doit = input(\nPlay/Plot Raw saw y2 looped for 10 ...
Back Close
seconds? Y/[N]:\n\n, s); if doit == y, figure(2) plot(y2); loopsound(y2,Fs,10*Fs/f2); end %concatenate wave ywave = [y1 , y2]; % Create Cross fade half width of wave y1 for xfade window xfadewidth = floor(Fs/(f1*2)); ramp1 = (0:xfadewidth)/xfadewidth; ramp2 = 1 - ramp1; doit = input(\nShow Crossfade Y/[N]:\n\n, s); if doit == y, figure(4) plot(ramp1); hold on; plot(ramp2,r); end; %apply crossfade centered over the join of y1 and y2 pad = (Fs/f1) + (Fs/f2) - 2.5*xfadewidth; xramp1 = [ones(1,1.5*xfadewidth) , ramp2, zeros(1,pad)]; xramp2 = [zeros(1,1.5*xfadewidth) , ramp1, ones(1,pad)];
135
Back Close
% Create two period waveforms to fade between ywave2 = [y1 , zeros(1,Fs/f2)]; ytemp = [zeros(1,Fs/f1), y2]; ywave = ywave2; % do xfade % add two waves together over the period modulated by xfade ramps % (recall .* to multiply matrices element by element % NOT MATRIX mutliplication ywave2 = xramp1.*ywave2 + xramp2.*ytemp; doit = input(\nPlay/Plot Additive Sines together? Y/[N]:\n\n, s); if doit == y, figure(5) subplot(4,1,1); plot(ywave); hold off set(gca,fontsize,18); ylabel(Amplitude); title(Wave 1); set(gca,fontsize,18);
136
Back Close
subplot(4,1,2); plot(ytemp); set(gca,fontsize,18); ylabel(Amplitude); title(Wave 2); set(gca,fontsize,18); subplot(4,1,3); plot(xramp1); hold on plot(xramp2,r) hold off set(gca,fontsize,18); ylabel(Amplitude); title(Crossfade Masks); set(gca,fontsize,18); subplot(4,1,4); plot(ywave2); set(gca,fontsize,18); ylabel(Amplitude); title(WaveTable Synthesis); set(gca,fontsize,18); loopsound(ywave2,Fs,10*Fs/(f1 + f2)); end
137
Back Close
Crossfade from one wavetable to the next sequentially. Crossfade = apply some envelope to smoothly merge waveforms.
138
Back Close
% Create Cross fade half width of wave y1 for xfade window xfadewidth = floor(Fs/(f1*2)); ramp1 = (0:xfadewidth)/xfadewidth; ramp2 = 1 - ramp1; %apply crossfade centered over the join of y1 and y2 pad = (Fs/f1) + (Fs/f2) - 2.5*xfadewidth; xramp1 = [ones(1,1.5*xfadewidth) , ramp2, zeros(1,pad)]; xramp2 = [zeros(1,1.5*xfadewidth) , ramp1, ones(1,pad)]; % Create two period waveforms to fade between ywave2 = [y1 , zeros(1,Fs/f2)]; ytemp = [zeros(1,Fs/f1), y2]; % do xfade % add two waves together over the period modulated by xfade ramps ywave2 = xramp1.*ywave2 + xramp2.*ytemp;
Back Close
140
Amplitude
Amplitude
Back Close
Back Close
Back Close
Back Close
Granular Synthesis
All sound is an integration of grains, of elementary sonic particles, of sonic quanta. -Iannis Xenakis, Greek Composer (1971).
144
Granular synthesis:
Often a cloud, that is subject to manipulation Unlike any natural sound and also unlike the sounds produced
by most other synthesis techniques.
145
Back Close
Back Close
Curtis Roads (1988), digital granular synthesis Barry Truax (1990) real-time granular synthesis composition
Riverrun, Buy the CD!
Back Close
Programmable : Csound, MATLAB, MAX/MSP routines: Standalone : Supercollider, Granulab, RTGS X. DAW plug-ins standalone : VSTis etc. Modern Music Samplers : Native Instruments Kontakt, Intakt...., others
Back Close
150
Back Close
Back Close
152
Pitch-synchronous granular synthesis: Overlapping grain envelopes designed to be synchronous with the frequency of the grain waveform, thereby producing fewer audio artifacts.
Back Close
153
Back Close
154
Back Close
Physical Modelling
Physical modelling synthesis is the synthesis of sound by using a mathematical model set of equations and algorithms to simulate a physical source of sound.
155
Back Close
Karplus-Strong
synthesis (1971)
strong
TD
Feedback, Filtering and delay. Essentially subtractive synthesis technique based on a feedback
loop similar to that of a comb lter.
Back Close
TD
Output signal and feedback into a delay line. Output of the delay line is fed through a lter -gain of the lter
must be less than 1 at all frequencies, usually a rst order lowpass lter
Fundamental frequency is the reciprocal of the period. Required delay D for a given fundamental frequency F1is
therefore calculated as:
D=
Fs F1
TD
Back Close
160
Back Close
figure(1); % ******* Run Loop Start ******* % for n = 1:N, y(n) = dline(ptr); [dline(ptr), z] = filter(b, 1, y(n), z); % Increment Pointers & Check Limits ptr = ptr + 1; if ptr > D ptr = 1; end if mod(n,2000) == 0 subplot(3,1,2);plot(dline) str = sprintf(Filter delayline step %d,n); title(str); subplot(3,1,3); plot(y); str = sprintf(Waveform Step %d,n); title(str); figure(1); end end % Scale soundfile if necessary max(abs(y)) if max(abs(y)) > 0.95 y = y./(max(abs(y))+0.1); disp(Scaled waveform); end figure(2);clf;plot(y); title(Final Step);set(gca,fontsize,18); playsound(y,fs);
161
Back Close