Beruflich Dokumente
Kultur Dokumente
• What happens when we multiply the output of a delay • Let the M sample delay correspond to τ seconds.
line by a gain factor g then feed it back to the input? • If the input to the filter is an impulse,
x(n) y(n) x(n) = {1, 0, 0, . . .} the output will have an impulse
g of amplitude 1 at n = 0, followed τ seconds later by
z −M
another impulse of amplitude g, followed again τ
Figure 2: The signal flow diagram of a comb filter. seconds later by another impulse of g 2 and so on.
CMPT 889: Computational Modelling for Sound Synthesis: Delay 3 CMPT 889: Computational Modelling for Sound Synthesis: Delay 4
Why is this a comb filter? The effect of the feedback coefficient
5
yield more extreme maxima and minima.
0 Simple Comb Impulse Response (g = 0.5)
1
0.8
−5 0.6
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
0.4
Normalized Frequency (×π rad/sample)
0.2
40 0
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05
20 8
4
0
2
−20 −2
−4
0 0.5 1 1.5 2 2.5 3 3.5
−40
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
Normalized Frequency (×π rad/sample) Figure 5: Impulse and Magnitude Response with g = 0.5.
0.8
0.6
0.4
0
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0.045 0.05
15
10
−10
0 0.5 1 1.5 2 2.5 3 3.5
CMPT 889: Computational Modelling for Sound Synthesis: Delay 5 CMPT 889: Computational Modelling for Sound Synthesis: Delay 6
• Since the pulses are equally spaced in time at an • Consider now, adding to the filter a delay element
interval equal to the loop time τ , it is periodic and which delays the input by M1 samples, with some
will sound at the frequency f0 = 1/τ . gain g1.
• The response decays exponentially as determined by • The general comb filter is given by the difference
the loop time and gain factor g. equation
• Notice that values of g nearest 1 yield the longest y(n) = x(n) + g1x(n − M1) − g2y(n − M2)
decay times.
where g1 and g2 are the feedforward and feedback
Matlab example coefficients, respectively.
fs = 44100; %sampling rate g1
f0 = 220; %desired fundamental z −M1
freqz(B, A);
CMPT 889: Computational Modelling for Sound Synthesis: Delay 7 CMPT 889: Computational Modelling for Sound Synthesis: Delay 8
Matlab Comb Filter Implementation Comb Transfer Function
1.5
Finding the tranfer function allows us to:
1
Amplitude
0.5
0
1. Find the frequency response by setting z = ejωT .
−0.5 2. Factor the transfer function to find the poles and
−1
0 5 10 15 20 25 30 35 40
zeros (see Digital Filters II)
Time (s)
CMPT 889: Computational Modelling for Sound Synthesis: Delay 9 CMPT 889: Computational Modelling for Sound Synthesis: Delay 10
jωT 1 + g1e−jM1 ωT
H(e ), , −π < ωT < π 0.8
1 − g2e−jM2 ωT 0.6
−jM1 ωT
H(ejωT ) = 1 + g1e
Imaginary Part
0.2
1 + g2e−jM2 ωT 0
−0.2
• The phase response is given by
−0.4
−0.8
−1
−1 −0.5 0 0.5 1
Real Part
CMPT 889: Computational Modelling for Sound Synthesis: Delay 11 CMPT 889: Computational Modelling for Sound Synthesis: Delay 12
A very simple string model Karplus-Strong Pluck String
CMPT 889: Computational Modelling for Sound Synthesis: Delay 13 CMPT 889: Computational Modelling for Sound Synthesis: Delay 14
6000
5000
4000
1000
in notes on filters).
0 1000 2000 3000 4000 5000 6000 7000 8000
Desired Frequency (Hz)
Figure 11: As the desired frequency gets higher, it becomes quantized to fewer possible
– Notice that the delay-line length is of an integer values. Notice for example, there is a single frequency value for all desired frequencies
size. This limits the resolution of possible sounding between 7000 and 8000 Hz.
frequencies.
CMPT 889: Computational Modelling for Sound Synthesis: Delay 15 CMPT 889: Computational Modelling for Sound Synthesis: Delay 16
Linear Interpolation Frequency-dependent decay rate
• Linear interpolation is the simplest of interpolation • Another (control) problem with the KS is that,
schemes. because of the low-pass filter in the feedback loop,
• If a delay value is 6.5 we would intuitively take the the decay rate is dependent on frequency.
outputs after delays of 6 and 7 samples then take the Plucked string at 441 Hz
1
value that is half-way between them. 0.8
Amplitude
0.6
0.2
6 and 7, but we would scale them differently, giving 0
0 0.5 1 1.5 2 2.5 3
more weight, in this case, to the output after a delay Time (s)
0.8
Amplitude
0.6
given by 0.4
0.2
where η is the desired fractional delay. Figure 12: Decay rate is faster at higher frequencies.
• PROBLEM: How does one control the decay rate so Selected Smith and Jaffe Extensions
as to obtain a note of desired duration?
CMPT 889: Computational Modelling for Sound Synthesis: Delay 19 CMPT 889: Computational Modelling for Sound Synthesis: Delay 20
Tuning First-Order Allpass Filter
and that the angle of a ratio is equal to the difference Setting the Allpass Phase Delay to a
between the numerator and denominator angles Desired Frequency
a
∠ = ∠b − ∠a.
b
• The low-frequency phase delay may be approximated • Given a desired fundamental frequency f1, the
by corresponding period in samples is given by
1−C
Pc(f ) ≈ , P1 = fs/f1.
1+C
and the filter coefficient C may be solved as a • We then desire a model with phase delay (in samples)
function of the desired phase delay Pc(f ).
N + Pa(f1) + Pc(f1) = P1.
1 − Pc(f )
C≈ . where Pa(f1) = 1/2 for the two-point averager.
1 + Pc(f )
• The integer buffer length N becomes
N , Floor(P1 − Pa(f1) − ǫ),
where ǫ is a number much less than 1, that was used
to shift Pc(f1)’s one-sampe delay range above 0 to 1,
to eliminate possible instability caused by pole-zero
cancellation on the unit circle (at a delay of 0).
• The delay in samples becomes
Pc(f1) , P1 − N − Pa(f1).
CMPT 889: Computational Modelling for Sound Synthesis: Delay 23 CMPT 889: Computational Modelling for Sound Synthesis: Delay 24
Attenuation of “Harmonics” Decay Rate of “Harmonics”
• On each pass through the delay-line loop, a partial at • The time constant τ is the time to decay by 1/e.
frequency f is subject to an attenuation equal to the
• To solve τf , the time constant for frequency f , begin
loop amplitude response, which in this case is the
by equating the attenuation factor to the exponential
gain of the two-point averager:
function e−t/τf :
Ga(f ) = cos(πf Ts).
αf (t) = e−t/τf
• After M passes through the delay-line loop, a partial t
ln αf (t) = − (take log of both sides)
at frequency f is subject to attenuation cos(πf Ts)M . τf
• Since the round-trip time in the loop is N + 1/2 t (N + 1/2) Ts
τf = − =−
samples, the number of trips through the loop after n ln αf (t) ln cos(πf Ts)
samples (nTs seconds) is given by
n t/Ts tfs • The time constant (in seconds) per harmonic is given
M= = = = tf1. by
N + 1/2 N + 1/2 N + 1/2
where fs/(N + 1/2) = f 1. t
τk , −
ln αk (t)
• The attenuation factor at time t = nTs is then given t
by = −
ln cos(πfk Ts)tf1
αf (t) , cos(πf Ts)tf1 .
1
• That is, a partial or harmonic of frequency f, having = −
f1 ln cos(πfk Ts)
an initial amplitude of A at time 0, will have
amplitude Aαf (t) at time t seconds.
CMPT 889: Computational Modelling for Sound Synthesis: Delay 25 CMPT 889: Computational Modelling for Sound Synthesis: Delay 26
CMPT 889: Computational Modelling for Sound Synthesis: Delay 27 CMPT 889: Computational Modelling for Sound Synthesis: Delay 28
Decay of non-harmonics Decay-time Shortening
• The previous analysis describes the attenuation due to • To shorten the decay time, a loss factor of ρ can be
“propagation” around the loop. introduced in the feedback loop, yielding
• Sinusoids that do not “fit” into the loop, i.e. are not yn−N + yn−(N +1)
yn = xn + ρ
integer multiples of the frequency whose period 2
exactly matches the loop length N + 1/2, are quicky • The amplitude envelope of a sinusoid at frequency f ,
destroyed by self interference. TODO: add matlab is now proportional to
figure.
αf (t, ρ) = |ρ cos(πf Ts)|f1t = |ρ|f1tαf (t).
• Though the loop is initialized with random numbers,
after a very short time the primary frequencies and the decay-time constant for the fundamental
remaining in the loop are those with an integer frequency becomes
number of periods in N + 1/2 samples. 1
τ1(ρ) = − .
f1 ln |ρ cos(πf1Ts)|
• Note that ρ cannot be used to lengthen the decay
time, since the amplitude at 0 Hz would increase
exponentially.
• |ρ| ≤ 1 if the string is to be stable.
• ρ is used to shorten the low-pitch notes.
CMPT 889: Computational Modelling for Sound Synthesis: Delay 29 CMPT 889: Computational Modelling for Sound Synthesis: Delay 30
• For a desired t60, determine the corresponding time • To stretch the decay, and reduce the low at high
constant τ frequencies, the feedback average Ha can be changed
t60 t60 t60 to a two-point weighted average.
τ =− = ≈ .
ln(0.001) ln(1000) 6.91 Ha(z, S) = (1 − S) + Sz −1
• The time constant is given by where S, the stretching factor, is between 0 and 1.
1
τ = − • For stability, S can’t be greater than 1.
f1 ln(ρ cos(πf1T ))
1 • When S = 1/2, Ha(z, S) reduces the the previous
ln(ρ cos(πf1T )) = − two-point averager.
f1
τ
1 • When S = 0 or 1, the frequency-dependent term
ρ cos(πf1T ) = exp −
f1 τ disappears, and the gain response is unity for all f.
−1/(f1τ )
e • At intermediate values, 0 < S < 1, the note duration
ρ = −
cos(πf1T ) is finite, with a minimum for S = 1/2.
• The resulting decay time is then a function of loss
factor ρ and stretch factor S.
CMPT 889: Computational Modelling for Sound Synthesis: Delay 31 CMPT 889: Computational Modelling for Sound Synthesis: Delay 32
Effect of Decay Stretching on Tuning Dynamics
• Changing S changes the effective loop length as a • Strings plucked hard have more energy in the higher
function of frequency since it changes the phase delay partials than string plucked lightly.
of the overall loop. • To simulate this dynamic difference in spectrum, the
• We must therefore compute Pa(f1) when using the bandwidth is controlled using a one-pole low-pass
Allpass filters to tune to the desired frequency. filter applied to the initial noise burst (before it is fed
• As shown in the paper, for low frequencies relative to into the string).
the sampling rate, we may use the approximation 1−R
Hd(z) , ,
1 − Rz −1
Pa(f, S) ≈ S, 0 ≤ S ≤ 1.
where R is a real number between 0 and 1, computed
• Again, for S = 1/2, we have the basic string as a funtion of fundamental frequency f1 and the
algorithms. desired dynamic level L.
• When a series of notes at pitch f1 is played while R is
moved gradually toward 1, a diminuendo is
approximated in terms of both decreasing loudness
and spectral bandwidth reduction.
CMPT 889: Computational Modelling for Sound Synthesis: Delay 33 CMPT 889: Computational Modelling for Sound Synthesis: Delay 34
• The dynamic level L is the bandwidth between 0 and 1. The one-pole lowpass filter having bandwidth L is
fs/2. given by
• If L is small, the spectrum is more lowpass filtered. 1 − RL
HL(z) , , RL , e−πLTs .
Large L gives a brighter spectrum corresponding to 1 − RLz −1
louder notes. 2. The gain at the reference frequency fm is
• For a given dynamic level L, R must be changed with 1 − RL
GL , |HL(ej2πfmTs )| =
pitch to yield uniform perceived loudness. A good |1 − RLe−j2πfmTs |
approximation is obtained by varying R so that the √
where fm = fufl is the geometric mean of the
amplitude of the fundamental f1 is constant. frequency range between fl and fu < fs/2.
• Steps for computing R for a given fundamental f1 and 3. The dynamics filter is a one-pole lowpass filter having
dynamic L: gain Gd(f1) = GL at any fundamental frequency f1,
1. Design a one-pole lowpass filter having bandwidth 1−R
GL = , where
L. |1 − Re−j2πf1 Ts |
2. Compute gain of the filter at the “middle” 1 − G2L cos(2πf1Ts)
frequency. R =
1 − G2L
3. Compute dynamics filter as a one-pole, lowpass p
1 − G2L cos2(πf1Ts)
filter having this gain at the desired fundamental ± 2GL sin(πf1Ts) ,
1 − G2L
f1 .
using the value < 1 in magnitude for stability.
CMPT 889: Computational Modelling for Sound Synthesis: Delay 35 CMPT 889: Computational Modelling for Sound Synthesis: Delay 36
Rests at the Ends of Notes Glissandi and Slurs
CMPT 889: Computational Modelling for Sound Synthesis: Delay 37 CMPT 889: Computational Modelling for Sound Synthesis: Delay 38
CMPT 889: Computational Modelling for Sound Synthesis: Delay 39 CMPT 889: Computational Modelling for Sound Synthesis: Delay 40
Multip-Tap Delay Line Example Simulating Plucking Position
b0 b1 b2 b3
having difference equation
y(n) y(n) = x(n) − x(n − µN ),
Figure 14: A multi-tapped delay with length M3 .
where µ is the fraction of the string between the
• In the above figure, the total delay line length is M3 bridge and pluck point.
samples, and the internal taps are located at delays of • When µ = 1/2, the even harmonics are removed, and
M1 and M2 samples, respectively. the effect is similar to that of plucking a string at its
• The output signal is a linear combination of the input midpoint.
signal x(n), the delay-line output x(n − M3), and the • This will have the effect of introducing zeros
two tap signals x(n − M1) and x(n − M2). uniformely spaced over the spectrum of the noise
• The difference equation is given by burst.
y(n) = b0x(n)+b1x(n−M1)+b2x(n−M2)+b3x(n−M3)
CMPT 889: Computational Modelling for Sound Synthesis: Delay 41 CMPT 889: Computational Modelling for Sound Synthesis: Delay 42