<<

Reverberation Transfer Function

MUS420/EE367A Lecture 3 Artificial Reverberation and Spatialization s1(n) h11

Julius O. Smith III ([email protected]) Center for Computer Research in Music and (CCRMA) s2(n) h12 y1(n) Department of Music, Stanford University Stanford, California 94305 s3(n) h13

June 13, 2018

h21 Outline h y (n) The Reverb Problem 22 2 • Reverb h23 • Early Reflections • Late Reverb Three sources • • Schroeder Reverbs One listener (two ears) • • Feedback Delay Network (FDN) Reverberators Filters should include pinnae filtering • • (spatialized reflections) Waveguide Reverberators • Filters change if anything in the room changes • In principle, this is an exact computational model.

1 2

Implementation Complexity of Exact Reverberation

Let hij(n)= impulse response from source j to ear i. Reverberation time is typically defined as t60, the time, in Then the output is given by six convolutions: seconds, to decay by 60 dB. y (n)=(s h )(n)+(s h )(n)+(s h )(n) Example: 1 1 ∗ 11 2 ∗ 12 3 ∗ 13 y2(n)=(s1 h21)(n)+(s2 h22)(n)+(s3 h23)(n) Let t =2 seconds ∗ ∗ ∗ • 60 For small n, filters h (n) are sparse fs = 50 kHz • ij • Tapped Delay Line (TDL) a natural choice Each filter hij requires 100,000 multiplies and • • additions per sample, or 5 billion multiply-adds per Transfer-function matrix: second.

S1(z) Three sources and two listening points (ears) Y1(z) H11(z) H12(z) H13(z) • ⇒ = S2(z) 60 billion operations per second Y2(z) " H21(z) H22(z) H23(z) #     S3(z) – 20 dedicated CPUs clocked at 3 Gigahertz   – multiply and addition initiated each clock cycle – no wait-states for parallel input, output, and filter coefficient accesses FFT convolution is faster, if throughput delay is • tolerable (and there are low-latency algorithms)

Conclusion: Exact implementation of point-to-point transfer functions is generally too expensive for real-time computation.

3 4 Possibility of a Physical Reverb Model Perceptual Aspects of Reverberation

In a complete physical model of a room, Artificial reverberation is an unusually interesting signal processing problem: sources and listeners can be moved without affecting • the room simulation itself, “Obvious” methods based on physical modeling or • spatialized (in 3D) stereo output signals can be input-output modeling are too expensive • extracted using a “virtual dummy head” We do not perceive the full complexity of • reverberation How expensive is a room physical model? What is important perceptually? • Audio bandwidth = 20 kHz 1/2 inch wavelength How can we simulate only what is audible? • ≈ • Spatial samples every 1/4 inch or less • A 12’x19’x8’ room requires > 200 million grid points • A lossless 3D finite difference model requires one • multiply and 6 additions per grid point 60 billion ⇒ additions per second at fs = 50 kHz A 100’x50’x20’ concert hall requires more than • 3 quadrillion operations per second

Conclusion: Fine-grained physical models are too expensive for real-time computation, especially for large halls.

5 6

Perception of Density and Mode Density Proof that Echo Density Grows as Time Squared

Consider a single spherical wave produced from a point For typical rooms • source in a rectangular room. – Echo density increases as t2 – 2 Tesselate 3D space with copies of the original room Mode density increases as f • Count rooms intersected by spherical wavefront Beyond some time, the echo density is so great that a • • stochastic process results Above some , the mode density is so great • that a random frequency response results There is no need to simulate many echoes per sample • There is no need to implement more resonances than • the ear can hear

7 8 Proof that Mode Density Grows as Freq. Squared Early Reflections and Late Reverb

The resonant modes of a rectangular room are given by1 Based on limits of perception, the impulse response of a 2 2 2 2 reverberant room can be divided into two segments k (l,m,n)= kx(l)+ ky(m)+ kz(n) Early reflections = relatively sparse first echoes kx(l)= lπ/Lx = lth of the fundamental • • in the x Late reverberation—so densely populated with echoes • that it is best to characterize the response L = length of the room along x • x statistically. Similarly for y and z • Similarly, the frequency response of a reverberant room Mode map to a uniform 3D Cartesian grid can be divided into two segments. • indexed by (l,m,n) Grid spacings are π/L , π/L , and π/L in x,y, and Low-frequency sparse distribution of resonant modes • x y z • z, respectively. Modes packed so densely that they merge to form a • Spatial frequency k of mode (l,m,n) = distance random frequency response with regular statistical • from the (0,0,0) to (l,m,n) properties Therefore, the number of room modes having a given • spatial frequency grows as k2

1For a tutorial on vector wavenumber, see Appendix E, section E.6.5, in the text: http://ccrma.stanford.edu/˜jos/pasp/Vector Wavenumber.html

9 10

Perceptual Metrics for Ideal Reverberation Energy Decay Curve (EDC)

Some desirable controls for an artificial reverberator For measuring and defining reverberation time t60, include Schroeder introduced the so-called energy decay curve (EDC) which is the tail integral of the squared impulse t (f)= desired reverberation time at each frequency • 60 response at time t: 2 G (f)= signal power gain at each frequency ∞ • EDC(t) =∆ h2(τ)dτ C(f)= “clarity” = ratio of impulse-response energy Zt • in early reflections to that in the late reverb EDC(t) = total signal energy remaining in the ρ(f)= inter-aural correlation coefficient at left and • reverberator impulse response at time t • right ears EDC decays more smoothly than the impulse response • itself Perceptual studies indicate that reverberation time t60(f) should be independently adjustable in at least three Better than ordinary amplitude envelopes for • frequency bands. estimating t60

11 12 Energy Decay Relief (EDR) Energy Decay Relief (EDR) of a Body Impulse Response The energy decay relief (EDR) generalizes the EDC to multiple frequency bands: bodyv6t − Summed EDR M EDR(t ,f ) =∆ H(m,k) 2 n k | | m=n X 40 where H(m,k) denotes bin k of the short-time (STFT) at time-frame m, and M is the 20 number of frames. 0

FFT window length 30 40 ms −20

• ≈ − Magnitude (dB) −40 EDR(tn,fk) = total signal energy remaining at time • 1 t sec in frequency band centered at f −60 n k 2

3 −80 4 0 2 4 6 8 10 12 14 5 16 18 Time (frames) Band Centers (kHz)

Energy summed over frequency within each “critical • band of hearing” (Bark band) Violin body = “small box reverberator” •

13 14

Reverb = Early Reflections + Late Reverb Early Reflections

The “early reflections” portion of the impulse response is x(n) Tapped Delay Line Late defined as everything up to the point at which a statistical ...... Reverb description of the late reverb becomes appropriate y(n) Often taken to be the first 100ms • Better to test for Gaussianness • – Histogram test for sample amplitudes in 10ms TDL taps may include lowpass filters windows • (air , lossy reflections) – Exponential fit (t60 match) to EDC (Prony’s Several taps may be fed to late reverb unit, • method, matrix pencil method) especially if it takes a while to reach full density – Crest factor test (peak/rms) Some or all early reflections can usually be worked • Typically implemented using tapped delay lines (TDL) into the delay lines of the late-reverberation • (suggested by Schroeder in 1970 and implemented by simulation (transposed tapped delay line) Moorer in 1979) Early reflections should be spatialized (Kendall) • Early reflections influence spatial impression •

15 16 Late Reverberation Moorer’s ideal late reverb: exponentially decaying • Desired Qualities: – Good smoothness in both time and frequency domains 1. a smooth (but not too smooth) decay, and – High frequencies need to decay faster than low 2. a smooth (but not too regular) frequency response. frequencies Schroeder’s rule of thumb for echo density in the late Exponential decay no problem • • reverb is 1000 echoes per second or more Hard part is making it smooth • For impulsive , 10,000 echoes per second or • – Must not have “flutter,” “beating,” or unnatural more may be necessary for a smooth response irregularities – Smooth decay generally results when the echo density is sufficiently high – Some short-term energy fluctuation is required for naturalness A smooth frequency response has no large “gaps” or • “hills” – Generally provided when the mode density is sufficiently large – Modes should be spread out uniformly – Modes may not be too regularly spaced, since audible periodicity in the time-domain can result

17 18

Schroeder Allpass Sections (Late Reverb) Why Allpass?

Allpass filters do not occur in natural reverberation! −g −g −g • “Colorless reverberation” is an idealization only x(n) M1 M2 M3 y(n) • possible in the “virtual world” g g g Perceptual factorization: • Coloration now orthogonal to decay time and echo Typically, g =0.7 • density Delay-line lengths Mi mutually prime, and • span successive orders of magnitude e.g., 1051, 337, 113 Allpass filters in series are allpass • Each allpass expands each nonzero input sample from • the previous stage into an entire infinite allpass impulse response Allpass sections may be called “impulse expanders”, • “impulse diffusers” or simply “diffusers” NOT a physical model of diffuse reflection, but • single reflections are expanded into many reflections, which is qualitatively what is desired.

19 20 Are Allpass Filters Really Colorless? A Schroeder Reverberator called JCRev Allpass impulse response only “colorless” when • extremely short (less than 10 ms or so). 0.742 FFCF4799

Long allpass impulse responses like feedback 0.733 • RevIn FFCF4999 0.7 0.7 0.7 RevOut comb-filters AP1051 AP337 AP113 0.715 The difference between an allpass and FFCF5399 • 0.697 feedback-comb-filter impulse response is one echo! FFCF5801 z−0.046fs OutA Allpass Impulse Response, M=7, g=0.7 (a) 1 − 0.8 z 0.057fs OutB 0.6 RevOut 0.4 z−0.041fs OutC 0.2 Amplitude 0 −0.054fs −0.2 z OutD

−0.4 0 10 20 30 40 50 60 70 80 90 100 Classic Schroeder reverberator JCRev. Feedback Comb Filter Impulse Response, M=7, g=0.7 (b) 1

0.5 JCRev was developed by John Chowning and others at

0 CCRMA based on the ideas of Schroeder. Amplitude

−0.5 Three Schroeder allpass sections: −1 0 10 20 30 40 50 60 70 80 90 100 • Time (samples) N 7 g ∆ g + z− 0.7+z− 1 AP = (a) H(z)= 1+0.7z 7 (b) H(z)= 1+0.7z 7 N N − − 1+ gz− Steady-state tones (sinusoids) really do see the same • Four feedforward comb-filters (STK uses FBCFs): gain at every frequency in an allpass, while a comb • filter has widely varying gains. g ∆ N FFCFN = g + z−

21 22

Schroeder suggests a progression of delays close to Freeverb • 100 ms M T , i =0, 1, 2, 3, 4. i ≈ 3i .84,.2 LBCF1557 Comb filters impart distinctive coloration: LBCF .84,.2 • 1617

Early reflections .84,.2 LBCF1491 • Room size LBCF .84,.2 • 1422 input 0.5 0.5 0.5 0.5 outL Could be one tapped delay line AP225 AP556 AP441 AP341 .84,.2 • LBCF1277 Usage: Instrument adds scaled output to RevIn LBCF .84,.2 • 1356

Reverberator output RevOut goes to four delay lines LBCF .84,.2 • 1188 .84,.2 Four channels decorrelated LBCF1116 • Imaging of reverberation between speakers avoided • For stereo listening, Schroeder suggests a mixing Four Schroeder “diffusion allpasses” in series • matrix at the reverberator output, replacing the • Eight parallel Schroeder-Moorer decorrelating delay lines • lowpass-feedback-comb-filters: A mixing matrix should produce maximally rich yet 1 • LBCF f,d =∆ uncorrelated output signals N 1 d N 1 f 1 dz− 1 z− JCRev is in the Synthesis Tool Kit (STK) − − − • Second stereo channel: increase all 12 delay-line JCRev.cpp • lengths by “stereo spread” (default = 23 samples) • JCRev.h. • Used extensively in the free-software world •

23 24 Freeverb Parameters T60 in Freeverb

d (“damping”) default: “Room size” f sets low-frequency t • • 60 damp = initialdamp * scaledamp =0.5 0.4=0.2 “damping” d controls how rapidly t60 shortens as · • frequency increases f (“room size”) default: • Diffusion allpasses set lower bound on t60 roomsize = initialroom * scaleroom + offsetroom • = 0.5 0.28+0.7=0.84 Interpreting “Room Size” Parameter · 1 Feedback lowpass (1 d)/(1 dz− ) causes Low-frequency reflection-coefficient for two • − − • reverberation time t60(ω) to decrease with frequency plane-wave wall bounces ω, which is natural Could be called liveness or reflectivity f mainly determines reverberation time at • Changing roomsize normally requires changing • low-frequencies (where feedback lowpass has • delay-line lengths negligible effect)

At very high frequencies, t60(ω) is dominated by the • diffusion allpass filters

25 26

Freeverb Allpass Approximation FDN Late Reverberation

Schroeder Diffusion Allpass b1 x (n) c1 N 1 z−M1 ∆ g + z− g b2 x (n) c2 AP = − u(n) 2 z−M2 N 1 gz N − b3 x (n) c3 − 3 z−M3 Freeverb implements E(z)

q11 q12 q13 N g1 g 1+(1+ g)z− q21 q22 q23 g2 y(n) AP − q31 q32 q33 N N g ≈ 1 gz 3 − − d Each Freeverb “allpass” is more precisely a feedback Jot (1991) FDN Reverberator for N =3 • g comb-filter FBCFN in series with a feedforward 1,1+g comb-filter FFCF − , where Generalized state-space model (unit delays replaced N • 1 by arbitrary delays) FBCF g =∆ N 1 gz N Note direct path weighted by d − − • 1,1+g ∆ N FFCFN− = 1+(1+ g)z− . The “tonal correction” filter E(z) equalizes mode − • energy independent of reverberation time A true allpass is obtained at g =(√5 1)/2 0.618 (perceptual orthogonalization) • (reciprocal of “golden ratio”) − ≈ Gerzon 1971: “orthogonal matrix feedback reverb” Freeverb default is g =0.5 • • cross-coupled feedback comb filters (see below)

27 28 Choice of Orthogonal Feedback Matrix Q Hadamard Feedback Matrix

Late reverberation should resemble exponentially A second-order Hadamard matrix: decaying noise. This suggests the following two-step ∆ 1 1 1 H2 = , procedure for reverberator design: √2 1 1  −  1. Set t = and make a good white-noise generator 60 ∞ Higher order Hadamard matrices defined by recursive 2. Establish desired reverberation times in each embedding: ∆ 1 H2 H2 frequency band by introducing losses H4 = . √2 H2 H2  −  The white-noise generator is the lossless prototype reverberator. Since H3 does not exist, the FDN example figure • above can be redrawn for N =4, say, (instead of N =3), so that we can set Q = H4 The Hadamard conjecture posits the existence of • Hadamard matrices HN of order N =4k for all positive integers k. “As of 2008, there are 13 multiples of 4 less than or • equal to 2000 for which no Hadamard matrix of that order is known. They are: 668, 716, 892, 1004, 1132, 1244, 1388, 1436, 1676, 1772, 1916, 1948, 1964.” [http://en.wikipedia.org/wiki/Hadamard matrix]

29 30

Choice of Delay Lengths Mi Mode Density Requirement

FDN order = sum of delay lengths: Delay line lengths Mi are typically mutually prime N • ∆ (Schroeder) M = Mi (FDN order) i=1 For sufficiently high mode density, Mi must be X • i sufficiently large. Order = number of poles P • – No “ringing tones” in the late impulse response All M poles are on the unit circle in the lossless • – No “flutter” prototype If uniformly distributed, mode density = • M = MT modes per Hz fs Schroeder suggests 0.15 modes per Hz • (when t60 =1 second) Generalizing: • M 0.15 t f ≥ 60 s Example: For fs = 50 kHz and t60 =1 second, • M 7500 ≥ Note that M = t60 fs is the length of the FIR filter • giving a perceptually exact implementation. Thus, recursive filtering is about 7 times more efficient by this rule of thumb.

31 32 Choice of Loss Gains gi Damping Filter Design

b1 The damping filter Gi(z) associated with the delay line x n c1 1( ) −M1 z of length Mi in the FDN can be written in principle as b2 x (n) c2 u(n) 2 z−M2 Mi b3 x (n) c3 Gi(z)= GT (z)Li(z) 3 z−M3 E(z) where GT (z) is the lowpass filter corresponding to one q11 q12 q13 g1 q21 q22 q23 sample of wave propagation through air, and Li(z) is a g2 y(n) q31 q32 q33 g3 lowpass corresponding to absorbing/scattering boundary d reflections along the (hypothetical) ith propagation path. Jot (1991) FDN Reverberator for N =3 Define

To set the reverberation time t60, we need to move t60(ω) = desired reverberation time at frequency ω • the poles of the lossless prototype slightly inside the p = ejωkT = kth pole of the lossless prototype unit circle k The scaling coefficients g can accomplish this for We can introduce frequency-independent damping with • i 0

33 34

Example Frequency-Dependent Damping

For frequency-dependent damping, consider the mapping Start with a pole at dc (digital integrator): • 1 1 z− G(z) z− 1 ← H(z)= 1 [1, 1, 1,...] 1 z− ↔ where G(z) is a lowpass filter satisfying G(ejωT ) 1, − ≤ Move it from radius 1 to radius 0.9 using ω • 1 1 ∀ z− 0.9z− : ← Neglecting phase in the loss filter G(z), the 1 • 1 1 H(z)= [1, 0.9, 0.81,...] substitution z− G(z) z− only affects the pole 1 0.9z 1 ↔ ← − − radius, not angle G(z) = per-sample filter in the propagation medium • Schroeder (1961): • The reverberation times of the individual modes must be equal or nearly equal so that different frequency components of the sound decay with equal rates ⇒ – All pole radii in the reverberator should vary smoothly with frequency – Otherwise, late decay will be dominated by largest pole(s)

35 36 Lossy Mapping Example

Let’s in more detail look at the z-plane mapping Start with a pole at dc (digital integrator): 1 1 • z− G(z) z− 1 ← H(z)= [1, 1, 1,...] 1 z 1 ↔ Pole k contributes the term − − • rk 1 2 2 Move it from radius 1 to radius 0.9 using Hk(z)= = rk 1+ pkz− + p z− + • 1 1 1 p z 1 · k ··· z− 0.9 z− : − k − ←  1 to the partial fraction expansion of the transfer H(z)= [1, 0.9, 0.81, ...] 1 0.9 z 1 ↔ function − − Now progress from radius 0.9 to 0.8 using This term maps to • • 1 rk 1 1+ αz− 1 H˜k(z) = z− 0.9 z− 1 p [G(z)z 1] ← 1+ α − k − 1 2 2 with 0.8=(1 α)/(1 + α) = rk 1+[G(z)pk]z− +[G(z)pk] z− + · ··· α = (1 0−.8)/(1+0.8)=1/0.9: jωkT  ⇒ − Thus, pole k moves from z = pk = e to 1 1 • H(z) = = jωkT 1+αz 1 0.9+z 1 p˜k = Rk e 1 0.9 − z 1 1 0.9 − z 1 − 1+α − − 0.9+1 − where 1 jωkT jωkT = Rk = G Rk e G e 1 0.81z 1 + 1 z 2 ≈ − 1.9 − 1.9 − which is a good approximation  here since R k is nearly 1 for reverberators.

37 38

Desired Pole Radius First-Order Delay-Filter Design

Pole radius R and t are related by k 60 Jot used first-order loss filters for each delay line: t60(ωk)/T Rk =0.001 1 a G (z)= g − i i i1 a z 1 The ideal loss filter G(z) therefore satisfies − i − t (ω)/T G(ω) 60 =0.001 gi gives desired reverberation time at dc | | • a sets reverberation time at high frequencies The desired delay-line filters are therefore • i Mi Gi(z)= G (z) Design formulas:

3MiT/t60(0) gi = 10− ⇒ t60(ω) jωT M T ln(10) 1 Gi(e ) i =0.001. a = log (g ) 1 i 4 10 i − α2 or   jωT MiT where 20log10 Gi(e ) = 60 . t (π/T ) − t60(ω) α =∆ 60 t60(0) Now use invfreqz or stmcb, etc., in Matlab to design low-order filters Gi(z) for each delay line.

39 40 Tonal Correction Filter Zita-Rev1 Reverberator

Let h (n) = impulse response of kth system pole. Then k FDN+Schroeder reverberator • ∞ = h (n) 2 = total energy Free open-source C++ for Linux by Fons Adriaensen Ek | k | • n=0 Faust example zita rev1.dsp X • Thus, total energy is proportional to decay time.

zita_rev1_eng...1, 8, 0.1))))(48000) To compensate, Jot proposes a tonal correction filter E(z) for the late reverb (not the direct signal). fbdelaylines(8) delayfilters(...1, 8, 0.1))))

First-order case: in_delay distrib2(8) output2(8) 1 1 bz− allpass_combs(8) feedbackmatrix(8) E(z)= − 1 b − where 1 α b = − faust2firefox examples/zita rev1.dsp 1+ α and Feedback Delay Network + Schroeder Allpass Comb ∆ t60(π/T ) α = Filters: t60(0) as before. Allpass coefficients 0.6 • ± Inspect Faust block diagram for delay-line lengths, • etc.

41 42

Zita-Rev1 Damping Filters High-Frequency-Damping Lowpass

FDN reverberators employ a damping filter for each delay High-Frequency Damping Lowpass: line 1 ph Hh(z) = − 1 Zita-Rev1 three-band damping filter: 1 phz − − For t60 at “HF Damping” frequency fh to be half of Hd(z)= Hl(z)Hh(z) middle-band t60 (gain gm), we require where 1 p 1 j2πfhT h 1 pl 1+ z− Hh e = − j2πf T = gm H (z) = g +(g g ) − = low-shelf 1 phe h l m 0 − m 2 1 p z 1 − − − l −  1 p Squaring and normalizing yields a quadratic equation: H (z) = − h = low-pass h 1 p z 1 p2 + bp +1=0 − h − h h Solving for p using the quadratic formula yields g0 = Desired gain at dc h 2 gm = Desired gain across “middle frequencies” b b ph = 1, pl = Low-shelf pole controlling low-to-mid crossover: −2 − s 2 − 1 πf T   =∆ 1 where − 2 1+ πf1T b 1 g cos(2πf T ) = − m h > 1, ph = Low-pass pole controlling high-frequency damping: −2 1 g2 − m Gives half middle-band t60 at start of “high” band Discard unstable solution b/2+ (b/2)2 1 > 1 − − To ensure gm < 1, GUI keeps middle-bandp t60 finite | |

43 44 Rectilinear Digital Waveguide Mesh Waveguide Mesh Features

A mesh of such waveguides in 2D or 3D can simulate • waves traveling in any direction in the space. Analogy: tennis racket = rectilinear mesh of strings = • pseudo-membrane Wavefronts are explicitly simulated in all directions •

− 1 − 1 − 1 − 1 − 1 − 1 True diffuse field in late reverb z z z z z z •

z − 1 4-port z − 1 4-port z − 1 4-port z − 1 Spatialized reflections are “free” Scattering Scattering Scattering • z − 1 Junction z − 1 Junction z − 1 Junction z − 1 Echo density grows naturally with time • z − 1 z − 1 z − 1 z − 1 z − 1 z − 1 Mode density grows naturally with frequency • z − 1 4-port z − 1 4-port z − 1 4-port z − 1 Scattering Scattering Scattering Low-frequency modes very accurately simulated z − 1 Junction z − 1 Junction z − 1 Junction z − 1 • High-frequency modes mistuned due to dispersion − 1 − 1 − 1 − 1 − 1 − 1 • z z z z z z (can be corrected) (often not heard)

z − 1 4-port z − 1 4-port z − 1 4-port z − 1 Scattering Scattering Scattering Multiply free almost everywhere z − 1 Junction z − 1 Junction z − 1 Junction z − 1 • Coarse mesh captures most perceptual details z − 1 z − 1 z − 1 z − 1 z − 1 z − 1 •

45 46

Reverb Resources on the Web

Book chapter from our tex- • thttp://interactiveachttps://ccrma.stanford.edu/ jos/pasp/Artificial Modeling with Interactive • Visualizations by Lauri Saviojahttp://interactiveacoustics.info/ Room Mode Calculator2 • Valhalla reverb plugins3 • Harmony Central article4 (with sound examples) • William Gardner’s MIT Master’s thesis5 •

2https://amcoustics.com/tools/amroc 3https://valhalladsp.com/ 4http://www.harmony-central.com/Effects/Articles/Reverb/ 5http://www.harmony-central.com/Computer/Programming/virtual-acoustic-room.ps.gz

47