Page  140 ï~~REAL-TIME IMPLEMENTATION TECHNIQUES FOR A CONTINUOUSLY VARIABLE DIGITAL DELAY IN MODELING MUSICAL INSTRUMENTS Timo!1. Laakso', Vesa Valimaki23, Matti Karjalainen2'3, and Unto K. Laine2'3 'Helsinki University of Technology 2Helsinki University of Technology Laboratory of Signal Processing and Acoustics Laboratory Computer Technology, SF-02 150 Espoo, Finland SF-02150 Espoo, Finland 3CARTES (Computer Arts Centre at Espoo), SF-02100 Espoo, Finland ABSTRACT Real-time implementation of variable delay using FIR and allpass filters is considered. Simple closed-form design formulas are given and implementation costs with signal processors are discussed. I. INTRODUCTION One of the fundamental advantages of digital signal processing techniques over traditional "analogue" methods is the easy implementation of a constant delay: one simply takes a delay line of a desired length and lets the signal samples stay in a buffer memory for the given time. However, when a fractional or a continuously variable delay is required, more sophisticated methods must be used. This problem occurs, e.g., in the modeling of musical instruments where the length of a resonator tube or a string has to be tuned virtually continuously to generate a musical tone with a sufficiently accurate fundamental frequency [Kar83 ], [Lai88], [Kar9l ]. There are two basic strategies to approximate a digital fractional delay (variable or fixed): either to use finite-impulse-response (FIR) filters or allpass-type recursive (IIR) filters. In this contribution, we compare the use of FIR and allpass filters for the real-time implementation of a continuously variable delay element. Closed-form formulas for simple designs are given and implementation costs vs. performance are discussed, with code length estimates for TMS320C30 floating-point signal processor implementation. U. APPROXIMATION USING FIR FILTERS Let us consider the approximation of a noninteger delay D by an FIR filter with the z-domain transfer function N H(z) - X h(n)z-n (1) h =o where N is the filter order. Let us denote the fractional.part of the desired overall delay D by x. The first problem is how to choose.the overall delay D with respect to given N and x. Recalling that the group delay of an Nth-order symmetric filter is.N/2, which is not integer for odd N, itis advisable to choose D = x +N/2 for even N and D = x + (N - 1)/2 for odd N. So the largest values of the impulse response are at the center, which generally results in smallest approximation error. Using the classical Lagrange interpolation formula, the FIR filter coefficients are found by fitting the impulse response coefficients to pass through the given set of data values, or H(z) = z-D D=0...N (2) Hence, with integer values of the delay the approximation error is set to zero. The solution is (see, e.g., [Lai88I) h(n) = H" - (3) =0.,o. n n -J Lagrange interpolation has several advantages: easy closed-form design, best possible response at low frequencies (due to maximally flat characteristics at zero frequency), and smooth and bounded magnitude response. For example, the maximum never exceeds unity, which is important in applications including feedback. M. APPROXIMATION USING ALLPASS FILTERS The z transfer function of an Nth-order ailpass filter is of the form z-NA(z-1) ay +... +a,z- + Z' H z) = A (z ) 1+ a,z-1+..,Â~+auz-N 4 where the numerator polynomial is a mirrored version of the denominator A (z). Denoting the group delay of the denominator by:A(c1), the group delay of the whole allpass filter is tH(o) = N +2ta(o) (5) 140.

Page  141 ï~~Hence, the overall nominal delay is D = x + N. Here we present a simple closed-form design method for the allpass filter approximating desired group delay. In 1971, Thiran proposed an analytic solution for an all-pole lowpass filter with a maximally flat group delay at zero frequency [Thi71]. Since the group delay of an allpass filter is twice that of the denominator, the solution can be expressed as ak = (_lkN)_x+n k = 1...N (6) k,--ox +k +n where x is the fractional part of the delay and (N is a binomial coefficient. For example, the coefficient of the 1st-order allpass filter is a = -x/(x + 2) and those of the 2nd-order filter are a1 = -2x/(x + 3) and a2 = x(x + 1 )/((x + 3) (x + 4)). Allpass filters have exactly unity magnitude response by definition and excellent group delay approximation even with low (2 to 5th-order) filter orders. The stability of the filter is always guaranteed for positive x, as shown in [Thi71]. IV. TRANSIENT BEHAVIOUR When tuning tie delay continuously, there is the problem of severely disturbing glitches when a new integer delay is added or removed in the delay line. As discussed in [Smi91], these glitches can be practically eliminated in allpass filters. However, an even better performance can be obtained with FIR interpolators using special techniques, as will be shown in an extended version of this paper. V. IMPLEMENTATION CONSII)ERATIONS We have estimated the costs of filter computations as well as coefficient updates for both FIR and allpass design using formulas (3) and (6). The number of arithmetic operations as well as the estimated number of instructions for the TMS320C30 signal processor implementation are collected in Table 1, assuming that only the changing parts of the coefficients are updated and the rest are stored to eliminate unnecessary computations. The allpass filter is assumed to be implemented with direct form I structure, involving 2N delays and 2N multiplications. The implementation of the allpass filter is computationally slightly more intensive due to the required division in the coefficient update. However, usually much lower-order allpass filter is needed to meet the same delay specifications as those of an FIR filter. Furthermore, faster coefficient update can be obtained by polynomial approximation of the exact formulas, or by interpolating between stored sample values. Table 1. Comparison of Computational Costs of FIR and Allpass Implementations of Variable Delay Costs as a Function of Filter Order N HIR IAllpass Filter Computations: MUL/ADD N+l/N 2N/2N-1 TMS320C3O Code N + 5 Instr. 2N + 6 Instr. Coefficient Update: MUL/ADD/DIV N +N/N/0 N2+2N-I/2N- I/l TMS320C30 Code N2 + 2N + 5 Instr. N2 + 4N + 30 Instr. Memory: Coefficients I Delays N + 1/ N N I 2N VI. REFERENCES [Kar83] K. Karplus and A. Strong, "Digital synthesis of plucked string and drum timbres," Computer Music Journal, Vol. 7, No. 2, pp. 43-55, 1983. [Kar9l ] M. Karjalainen and U. K. Laine, "A model for real-time sound synthesis of guitar on a floating-point signal processor," in Proc. Int. Conf. Acoust. Speech Signal Process. (ICASSP'9 1), Toronto, Canada, May 1991. [Lai88] U. K. Lamne, "Digital modelling of a variable length acoustic tube," Proc. of thle Nordic Acoustical Meeting (NAM'88), pp. 165-168, Tampere, Finland, June 15-17, 1988. [Smi9l] J.O0. Smith, 'J. 0. Smith III comments on Sullivanm Karplus-Strong article," Computer Music Journal, Vol. 15, No. 2, pp. 10,-11, 1991. [Thi7 1] J.-P. Thiran, "Recursive digital filters with maximally flat group delay," IEEE Trans. on Circuit Theory, vol. CT- 18, pp. 659-664, Nov. 1971. 141