Alias-Free Digital Synthesis of Classic Analog Waveforms
Total Page:16
File Type:pdf, Size:1020Kb
Alias-Free Digital Synthesis of Classic Analog Waveforms Tim [email protected] rd.edu Julius Smith [email protected] u CCRMA http://www-ccrma.stanford.edu/ Music Department, Stanford University Abstract Techniques are reviewed and presented for alias-free digital synthesis of classical analog synthesizer waveforms such as pulse train and sawtooth waves. Techniquesdescribed include summation of bandlim- ited primitive waveforms as well as table-lookup techniques. Bandlimited pulse and triangle waveforms are obtained by integrating the difference of two out-of-phase bandlimited impulse trains. Bandlimited impulse trains are generated as a superposition of windowed sinc functions. Methods for more general bandlimited waveform synthesis are also reviewed. Methods are evaluated from the perspectives of sound quality, computational economy, and ease of control. 1 Introduction impulse train Any analog signal with a discontinuity in the wave- 1 form (such as pulse train or sawtooth) or in the wave- 0.8 form slope (such as triangle wave) must be bandlim- 0.6 ited to less than half the sampling rate before sampling 0.4 to obtain a corresponding discrete-time signal. Simple methods of generating these waveforms digitally con- 0.2 tain aliasing due to having to round off the discontinuity 0 0 5 10 15 20 time to the nearest available sampling instant. The sig- nals primarily addressed here are the impulse train, rect- Box Train, and Sample Positions angular pulse, and sawtooth waveforms. Because the 1 latter two signals can be derived from the ®rst by inte- 0.8 gration, only the algorithm for the impulse train is de- 0.6 veloped in detail. 0.4 0.2 2 Why Simple Discrete-Time Pulse 0 0 5 10 15 20 Trains are Aliased Rounded−Time Pulse Train The ªobviousº way to generate a discrete-time ver- 1 sion of an impulse train is to approximate it by a unit- 0.8 δ sample-pulse train. The unit sample pulse n is de- 0.6 ®ned as 0.4 = δ ∆ 1; n 0 = n 0.2 j j = ; ; ;::: 0; n 1 2 3 0 The unit-sample pulse is only de®ned for integer n,so 0 5 10 15 20 we have a problem: Suppose the desired impulse-train = frequency is f1 = 1 T1, then the period in samples has to Figure 1: Rounded-Time Impulse Train as a Sampled Version = = = = = be P = T1 Ts Fs f1,whereFs 1 Ts is the sampling of an Ideal Rectangular Pulse Train rate, and P is rarely an integer. Because pitch perception Stilson and Smith 1 Alias-Free Synthesis ∞ is so accurate , it does not work to round M to the near- jωTs ∝ ω + π Y e ∑ X k2 Fs est integer, except at frequencies so low that the error is ∞ k = on the order of a tenth of a percent (around 100 Hz or ∞ ω + π below for a 50 kHz sampling rate). Therefore, to make = ∑ P k2 Fs ∞ the pitch right, it is necessaryto compute the impulse ar- k = ∞ rival times very accurately and round each arrival time δω + π ω ∑ k2 F l to the nearest sample instant. This process can be mod- s 1 ∞ l = eled as pitch-period jitter which obviously adds noise to the signal. It can also be modeled as a uniform sampling The desired pulse-train spectrum is only the k = 0term of a periodic sequence of rectangular pulses one sample above. Each nonzero k term contributes a string of wide (Figure 1): aliased of harmonics across the entire frequency band. The amount of aliasing is highly signi®cant and audible, j j = ∆ 1; t Ts2as can be predicted from looking at Fig. 6. = pt j j> = 0; tTs2The only frequency which does not suffer aliasing is DC since the sinc spectral envelope goes through zero The Fourier transform of this pulse is a sinc function at all multiples of the sampling rate. For this reason, the Z ∞ aliasing is reduced at very low frequencies relative to the ∆ ω j t ω = = P p t e dt Ts sinc fTs sampling rate. This provides another explanation why ∞ the aliasing is not as objectionable for low fundamental π frequencies (where the nearest-integer roundoff is an in- where ω = 2 f ,and signi®cant fraction of the period): The aliased frequen- π ∆ sin x cies that would tend to be most noticeable (those near or = : sincx πx below the fundamental frequency) are most attenuated. The above analysis extends immediately to rectangle A periodic sequence of these rectangular pulses is con- waves. structed as ∞ ∆ Trivial Sawtooth Trivial Square = + xt ∑ p t lT1 ∞ l = and its Fourier transform is, by the shift theorem and properties of delta functions, ∞ ∆ jωlT1 ω = ω X ∑ e P ∞ l = ∞ Saw. Spec. Sq. Spec. ω δω ω ∝ P ∑ l 1 0 0 ∞ l= ω ; ω = ω P l l ∝ −20 −20 ω 6= ω ; 8 0; l l δ ∆ −40 −40 ω ω = π where denotes the delta function, and l 2 lF1. Thus, the rectangular-pulse train has an in®nite har- −60 −60 monic spectrum weighted by a sinc function having ze- 0 0.2 0.4 0 0.2 0.4 freq (norm) freq (norm) ros at multiples of the sampling rate Fs (because the original rectangular pulse was taken to be one sampling Figure 2: Spectra of Trivial Sawtooth and Square-Wave Sig- interval wide). Since the sinc function has a lot of en- nals, Low Frequency ergy above its ®rst zero crossing, sampling xt will cause aliasing of an in®nite number of harmonics whose A similar argument applies to explain why sawtooth amplitudes fall off at 6 dB per octave (since sinc fTs signals alias: If the unit-amplitude sawtooth is gener- falls off as 1 = f ). (Harmonics under the outer half of the main lobe of the sinc function also alias.) Sampling, we ated by = get sn f1nTs mod1 where f1 is the desired frequency, then it can be shown ∆ = $ yn x nTs to be simply a sampling of a continuous-time (ªanalogº) Stilson and Smith 2 Alias-Free Synthesis Trivial Sawtooth Trivial Square it appears not to be done in practice. 3 Bandlimited Synthesis In this section, various preexisting methods for syn- thesis of bandlimited waveforms will be reviewed. Saw. Spec. Sq. Spec. 0 0 3.1 Additive Synthesis Additive synthesis is trivially bandlimited simply by not −20 −20 generating harmonics higher than Fs =2; typically this also presents a computational savings. Additive synthe- −40 −40 sis systems that use the inverse FFT to compute the os- cillators are bandlimited by de®nition because the in- −60 −60 0 0.2 0.4 0 0.2 0.4 verse FFT only generates frequencies up to Fs =2. In freq (norm) freq (norm) inverse-FFT synthesis, time-aliasing becomes the error to minimize. Figure 3: Spectra of Trivial Sawtooth and Square-Wave Sig- nals, High Frequency 3.2 Wavetable Synthesis One of the very earliest synthesis techniques used sawtooth of equivalent slope. Since the analog sawtooth in computer music was periodic wavetable synthesis is not bandlimited, the sampled version will be aliased. [Mathews 1969] (not to be confused with sample play- This is slightly different from a rounded-time retrig- back synthesis which is also called wavetable synthe- gered sawtooth which is better described as the convolu- sis these days). In this technique, a wavetable contains tion of a single cycle of a sawtooth wave with a rounded- only one period of the desired tone, sampled at a high time impulse train, which was just shown to be aliased rate, such as N = 512 samples per period. Playing out as well. Since a single cycle of a sawtooth has a Fourier the table repeatedly generates a periodic waveform with transform which falls off at 6 dB per octave (all dis- fundamental frequency Fs =N,whereFs is the sampling continuous waveforms have spectral fall-offs no faster rate. Skipping every other sample on playback yields a than 6 dB per octave [Papoulis 1991]), it follows that fundamental frequency of 2Fs =N and so on. Intermedi- the spectrum of the rounded-time retriggered sawtooth ate frequencies f0 are obtained using a non-integer skip- = also falls off at 6 dB per octave. Therefore, sampling it factor, or ªphase increment,º given by Inc = Nf0 Fs;in causes aliasing in an amount similar to that in the sam- such cases, the wavetable address has a fractional part pled rectangular pulse train. which is often either discarded or used to round to the By convolving the rounded-time impulse train (sam- nearest integer (reasonable for very large N and/or heav- pled rectangular pulse train, with pulses of width ily oversampled waveforms), or it is used to determine Ts) with an arbitrary ®xed ®lter, formant synthesis an interpolated table value. By far the most common such as VOSIM [Kaegi and and S. Tempelaars 1978], interpolation technique is linear interpolation. How- Chant [Rodet et al. 1989] (see also [Roads 1996]) is de- ever, higher order interpolation methods, especially La- scribed. By multiplying the rounded-time impulse train grange [Schafer and Rabiner 1973] and bandlimited in- by a periodic amplitude envelope and convolving it with terpolation [Smith and Gossett 1984], have been used a Blackman FFT window, window-function synthesis commercially. is described [Goeddel and Bass 1984] (summarized in Interpolated wavetable synthesis is not guaranteed to [Roads 1996]). In all these cases, a pitch-period is as- be bandlimited when the phase increment is larger than sociated with the impulse response of the formant ®lter one sample. In these cases, one is performing the equiv- (or lowpass ®lter in the case of window-function syn- alent of a decimation of the waveform, with the decima- thesis), perhaps overlapping with those of other periods, tion factor being equal to the phase increment in sam- and the impulse-responsestart times are quantized to the ples.