Audio Effects 理论实现与应用(2) Delay Line Effects --Delay

本文探讨了音频延迟线在音乐制作中的关键作用,介绍了基本延迟、反馈延迟、滑动回声、多抽头延迟和乒乓延迟等技术。还讨论了数字延迟的实现,包括线性插值和高阶插值,以及这些技术在实际应用中的效果和技巧。
摘要由CSDN通过智能技术生成

Delay lines are the fundamental building blocks of many of the most impor- tant effects. They are rather easy to implement, and only small changes in how they are used allow many different audio effects to easily be con- structed. In this chapter, we look at some common effects that are built using delay lines

Delay

Delay is a simple effect with powerful applications. In the simplest case, add- ing a single delayed copy of a sound to itself can enliven an instrument’s sound in a mix or, at longer delay times, allow a performer to play a duet with himself or herself. Many familiar effects, including chorus, flanging, vibrato, and reverb, are also built on delays.

Theory
Basic Delay

The basic delay plays back an audio signal after a specified delay time. Depending on the application, the delay time might range from a few milli- seconds to several seconds or longer. Figure 2.1 shows a block diagram of the basic delay. It is common to mix the delayed output with the original input, thereby producing two copies of the sound. For this reason the basic delay is also sometimes known as an echo effect (though as we will see, the percep- tion of echo also depends on the delay time).

We can express the output audio samples y[n] as a function of the input samples x[n], the delay time N (expressed in samples), and the gain g of the delayed signal:

y[n] = x[n] + gx[n N]                                                                   (2.1)

Delay is a linear, time-invariant effect. To show linearity, consider two sig- nals x1[n] and x2[n]. Let y1[n] and y2[n] be the delayed output of each signal

21

x[n]

g

+

y[n]

Delay

FIGURE 2.1

Diagram of the basic delay unit, or an echo device. The box marked “delay” is commonly known as a delay line.

individually. If we delay the sum of the signals, we find that the output is the sum of the individual delayed signals:

y[n] = (x1[n] + x2[n]) + g (x1[n N] + x2[n N])

= (x1[n] + gx1[n - N]) + (x2[n] + gx2[n - N]) = y1[n] + y2[n]

 

(2.2)

Time invariance implies that shifting the input in time produces an identi- cal shift in the output. Consider taking the delay of xd[n] = x[n M] for some number of samples M:

yd[n] = x[n - M] + gx[n - M - N] = y[n - M]                                      (2.3)

Using the Z transform, we can also find the frequency response of the basic delay:

Y(z)                     -N

 

Y(z)

 

-N      zN + g

= X(z) + gz  X(z)

 

H(z) =           = 1 + gz

X z

( )

=     zN                           (2.4)

Since the transfer function H(z) has no poles outside the unit circle, the basic delay must be stable in all cases; i.e., a bounded input will always produce a bounded output.

Delay with Feedback

The simple “feedforward” delay is limited in application, producing only a single echo. Most audio delay units also have a feedback control (sometimes called regeneration), which sends a scaled copy of the delay output back to the input, as shown in Figure 2.2. Feedback causes the sound to repeat con- tinuously, and assuming a feedback gain less than 1, the echoes will become quieter each time. Though the echoes are theoretically repeated forever, they will eventually become so quiet as to be below the ambient noise in the sys- tem and thus be inaudible.

To find the time domain difference equation for delay with feedback, it helps to consider the signal d[n] at the output of the delay line:

gFB

x[n]

+

gFF

+

y[n]

Delay N

FIGURE 2.2

Diagram of the basic delay unit with feedback.

y[n] = x[n] + gFFd[n]      where

 

d[n] = x[n - N] + gFBd[n - N]           (2.5)

The form of d[n] is similar to the delayed output signal y[n N], which lets us substitute and write y[n] directly in terms of x[n]:

y[n - N] = x[n - N] + gFFd[n - N]

d[n] =  gFB  y[n - N] +

gFF

 

1 -  gFB

gFF

 

x[n - N]

 

(2.6)

y[n] = gFBy[n - N] + x[n] + (gFF - gFB)x[n - N]

Taking the Z transform, we can find the frequency domain transfer function:

Y(z) - gFBz-NY(z) = X(Z) + (gFF - gFB )z-N X(z)

H(z) =

 

Y(z)

)

X( z =

1 + z-N (gFF - gFB )

=

1 - z- N gFB

zN + gFF - gFB zN - gFB

 

(2.7)

Thus, the system has poles at the N complex roots of gFB. As with the basic delay, delay with feedback is linear and time invariant. The above trans- fer function implies the effect will be stable whenever the poles are inside the unit circle, that is, when |gFB| < 1. This result aligns with intuition, in that only when the feedback gain is less than 1 will the echoes grow softer over time.

Other Delay Types
Slapback Delay

A slapback delay is identical to a basic delay without feedback and with a relatively short delay time, typically between 60 and 150 ms. The delayed copy is perceived as a separate sound that appears immediately after the original sound. A longer delay, where there is a noticeable gap between the original and delayed sounds, is often referred to as an echo.

gFB

x[n]

+

+

+

y[n]

zN3

zN2

zN1

zN4

FIGURE 2.3

Flow diagram of a three-tap delay. If the last delay value is zero, and only the third tap is used, the system is equivalent to the basic delay.

Multitap Delay

In a standard delay with or without feedback, the time between copies is always the same, since the output signal is taken after the signal reaches the end of the delay line. Multitap delay provides more flexibility by taking sev- eral additional outputs in the middle of the delay line, where the signal has been delayed only part of the total time. This process is known as “tapping” the delay line, following the analogy of adding taps along a water pipe to get water at various locations. Multitap delay is commonly labeled according to the number of taps; for example, a four-tap delay would have four total outputs at various points on the delay line. The delay between each tap is typically not the same, so multitap delays allow more complex patterns to be created that can add interesting rhythmic qualities to an instrument. A diagram of multitap delay is shown in Figure 2.3.

The multitap delay is a more general case of the basic delay design. The multitap delay can be further generalized by allowing feedback from the tap outputs to the beginning of the delay line as well. In this case, care must be taken with the feedback gains to avoid creating an unstable system.

Ping-Pong Delay

Ping-pong delay is a multichannel delay-based effect that produces a bounc- ing sound from one channel to the other, hence the name. It is implemented as a delay with feedback with at least two distinct delay lines (Figure 2.4). Each delay line may be driven by a separate input, or only one input can be used. The output of each delay line, rather than feeding back to itself, attaches to the input of the opposite delay line. In its two-channel configura- tion, ping-pong delay produces a sound that bounces between left and right channels in a stereo track.

X1(z)

Y1(z)

a1               +

zN

c1

+

b1

b2

X2(z)

Y2(z)

a2               +

zN

c2

+

FIGURE 2.4

Flow diagram of a ping-pong delay unit.

Implementation
Basic Delay

Before the days of digital audio, delays were one of the more cumbersome effects to implement, relying on physical audiotape or analog “bucket bri- gade device” integrated circuits to store and retrieve audio signals. In the digital realm, delay is one of the simplest effects. Audio samples are stored in a preallocated memory buffer as they arrive, while previously stored samples are read from the buffer once the delay time has elapsed. In other words, in a simple delay, each sampling period includes one read operation (retrieving the delayed signal) and one write operation (storing the current signal). When the end of the memory buffer is reached, the system should loop around to the beginning of the buffer. In signal processing, this process is known as a circular buffer, and it is quite efficient. Programming consider- ations for circular buffers are discussed in Chapter 13.

Variations

Delay with feedback is implemented identically to a simple delay, but rather than storing the raw input signal in the memory buffer, the sum of the input signal and the delayed, scaled output is stored (x[n] + gFBx[n N] in Figure 2.2). Ping-pong delay uses two independent memory buffers and, hence, two read operations and two write operations for each sample.

Multitap delay uses a single memory buffer with multiple read pointers. At each sample, the current input is written into a slot in the buffer (the write pointer), but samples are read back from multiple locations in the buffer

(the read pointers). The spacing in memory between the pointers deter- mines the difference in their delay times. This process is further discussed in Chapters 10 and 13.

Delay Line Interpolation

Digital delays are implemented using a memory buffer of discrete audio samples. To change the delay time, we change the distance in the buffer between where samples are written and where they are read back. However, many effects, including the flanger and chorus, require a delay that changes over time. To achieve a smooth variation in delay, rounding to the nearest- integer number of samples is usually not good enough.

Delay becomes more complex when a noninteger number of samples is required. Consider a simple delay with a length of 0.5 samples. From Equation (2.1) we have

y[n] = x[n] + gx[n 0.5] y[1] = x[1] + gx[0.5]                                                                              (2.8)

However, x[n] is defined only for integer n, so x[0.5] does not exist. Strictly speaking, it is not correct to think of x[0.5] as “halfway between” x[0] and x[1]. However we might ask what the result would be if x[n] were converted from discrete to continuous time, shifted half a sampling period, then recon- verted to discrete time. An excellent discussion of the underlying mathemat- ics of this process, which is based on sinc functions (sin(n)/n), can be found in [3]. Interestingly, exact reconstruction of fractional sample values requires knowledge of the entire signal (i.e., x[n] from n = –∞ to ∞), which is clearly impossible in a real-time audio context.

In practice, fractional delays in audio are implemented using interpola- tion or allpass filters [7]. Interpolation involves using a weighted combina- tion of surrounding samples to approximate the fractional sample value. Interpolation involves estimating a value of a continuous function, given discrete points, and can be used to estimate values between points on a delay line. Polynomial interpolation is where the function is estimated to be an Nth-order polynomial, x(t) = cNtN + cN–1tN–1 + … c1t1 + c0.

If values out of the delay line closest to the required point are read, this is zeroth-order, or nearest-neighbor, interpolation. It is probably the least com- putationally expensive approach. However, the output now has abrupt jumps between values. The quality of this approach is quite poor. Clicking in the output may be heard as the delay length changes, also known as zipper noise. Linear interpolation, or first-order interpolation, is implemented by con- necting two known samples by a straight line and then reading the desired

value from that line. This is given in the following equation:

x(t) = (n + 1 − t)x[n] + (t n)x[n + 1], n t < n + 1                                                                              (2.9)

Linear interpolation is simple to calculate and produces much better results than nearest-neighbor interpolation. However, it is still only a rough approximation to the ideal continuous time case, and it can introduce noise and aliasing into the signal. In many cases, audibly better quality will be obtained with a more computationally complex interpolation method.

One such method is second-order polynomial interpolation. Consider three successive samples, x[n – 1], x[n], and x[n + 1]. We would typically use these samples if we are trying to interpolate a value of x near x[n]. Let’s define a new function, y(τ) = x(t), where τ = t n. Thus, x[n – 1], x[n], and x[n + 1] become y[–1], y[0], and y[1]. Assuming that these points are on a second-order polynomial, we have the following three equations:

y[-1] = c2(0 - 1)2 + c1(0 - 1) + c0

y[0] = c2 02 + c10 + c0

y[1] = c2(0 + 1)2 + c1(0 + 1) + c0

 

(2.10)

where c0, c1, and c2 are the coefficients of some second-order polynomial.

This can be solved to give

c0 = y[0]

c1 = (y[1] - y[-1])

2

c2 = (y[1] - 2y[0] + y[-1])

2

 

(2.11)

So our interpolated values are

x(t) = y(t) = c2t2 + c1t + c0

 

(2.12)

= (x[n + 1] - 2x[n] + x[n - 1])(t n)2 

2 + (x[n + 1] - x[n - 1])(t n)

2 + x[n]

(t - n - 1)(t - n)x[n - 1] - 2(t - n - 1)(t - n + 1)x[n] + (t - n)(t - n + 1)x[n + 1] 2

Cubic interpolation requires more computation, but it can give better results with lower added noise resulting from inaccuracies than the ideal sinc-function case. There are many forms of cubic interpolation; a detailed discussion is available in [8]. The simplest case uses the four samples sur- rounding the interpolated location:

x(t) = c3(t - n)3 + c2(t - n)2 + c1(t - n) + c0

 

for

 

n £ t < n + 1          (2.13)

where the coefficients are given by

c3 = -x[n - 1] + x[n] - x[n + 1] + x[n + 2]

c2 = x[n - 1] - x[n] - a0 c1 = x[n + 1] - x[n - 1] c0 = x[n]

Code Example

The following C++ code fragment, adapted from the code that accompanies this book, shows the implementation of a basic delay with feedback, and without interpolation.

// Variables whose values are set externally:

int numSamples;     // How many audio samples to process float *channelData; // Array of samples, length numSamples float *delayData;   // Our own circular buffer of samples int delayBufLength; // Length of our delay buffer in samples int dpr, dpw;           // Read/write pointers into delay buffer

// User-adjustable effect parameters:

float dryMix_;      // Level of the dry (undelayed) signal float wetMix_;   // Level of the wet (delayed) signal float feedback_; // Feedback level (0 if no feedback)

for (int i = 0; i < numSamples; ++i)

{

const float in = channelData[i]; float out = 0.0;

// The output is the input plus the contents of the

// delay buffer (weighted by the mix levels). out = (dryMix_ * in + wetMix_ * delayData[dpr]);

// Store the current information in the delay buffer.

// delayData[dpr] is the delay sample we just read, i.e.

// what came out of the buffer. delayData[dpw] is what

// we write to the buffer, i.e. what goes in delayData[dpw] = in + (delayData[dpr] * feedback_);

if (++dpr >= delayBufLength) dpr = 0;

if (++dpw >= delayBufLength) dpw = 0;

// Store output sample in buffer, replacing the input channelData[i] = out;

}

This example assumes that a single channel of input audio data is present

in the channelData array. In a real-time effect, channelData will hold only the most recent block of audio samples, rather than the entire input sig- nal. To implement the delay, we write each input sample into delayData at a position indicated by the write pointer dpw, while reading a delayed sample previously written into the buffer using read pointer dpr.

delayData is a circular buffer: after each sample is processed, dpr and dpw are incremented, and when either of them reaches the end of the buf- fer, it is reset back to position 0. Notice that there is no parameter for the delay length in this code example. It is the difference between the read and write pointers dpr and dpw that determines the delay length. These values are initialized elsewhere in the effect. More details and a more extensive code example can be found in Chapter 13.

Applications

Delays are a very common effect in music production. Even a single basic delay, without feedback, has many uses. A common use is to combine an instrument’s sound with a short echo (for example, around 50–100 ms) to create a doubling effect. This can create a wider, more lively sound than the original single version. If the original and delayed copies are panned differently in a stereo mix, short delays can also help make the mix sound “bigger.” More complex arrangements including feedback and multiple taps can start to simulate the sound of a reverb unit, though reverb (covered in Chapter 11) typically creates more complex patterns than can be simulated with simple delays.

Longer delays become less subtle once the original and delayed copies are easily perceived as two separate acoustic events. One common trick is to syn- chronize the delay time with the tempo of the music, such that the delayed copies appear in rhythm with the track [9]. If the delay time is especially long, for example, equal to one or more bars of music, a musician can play over himself or herself and develop elaborate harmonies and textures.

Sampler and looper pedals are fundamentally based on the delay, with additional features to be able to define the start and end of an audio segment, which then can loop continuously. Other features are possible, including the ability to mix additional sounds onto a loop that was previously recorded, to play a loop backwards, or to have multiple simultaneous loops. Some

standard delay pedals will include basic looper capability, though often lim- ited to a single loop of a few seconds at most.

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值