Delay-Based Digital Audio Effects Module for DJs and Musicians
Delay Based Audio Effects Using the TMS320C6713
Transcript of Delay Based Audio Effects Using the TMS320C6713
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
1/51
1
TI DSP Developer Online Training
Delay Based Audio Effects Using theTMS320C6713 DSP
Lee MinichPresident
Lab X Technologies, LLC
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
2/51
2
TI DSP Developer Online Training
Session Objectives
Learn the basics of fixed and variable delays
Learn basic technique for implementing sub-
sample delays Learn how to efficiently implement fixed and
variable delays using the TMS320C6713 DSP
Investigate performance trade-offs implementingdelays
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
3/51
3
TI DSP Developer Online Training
Why Delays are Important?
Delays are a fundamental tool used in audio
applications
Time alignment of speaker arrays (sound
reinforcement, live sound, home theater)
Lip sync processing (home theater)
Delay based effects (recording studio, live sound)
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
4/51
4
TI DSP Developer Online Training
Who uses Delays?
Sound reinforcement/Live sound
Music Industry (effects manufacturers)
Professional Studio equipment Home Theater
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
5/51
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
6/51
6
TI DSP Developer Online Training
Agenda
Introduction
Fixed Digital Delay
Variable Digital Delay Implementation Details
Further Investigation
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
7/51
7
TI DSP Developer Online Training
Introduction
Various audio applications based on Digital
Delay.
Time alignment (Live sound, Sound Distribution, Home
Theater)
Audio effects (Recording, FOH, MI).
Two classes of delays
Fixed Delay
Variable Delay
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
8/51
8
TI DSP Developer Online Training
Anatomy of a Digital Delay
Write pointer Head
Read pointer Tail
Delay buffer
Regeneration Mix coefficients of wet and dry
Delay Buffer
+
+ Output y(n)
Input x(n)
Regen
MixWet
MixDry
Write Pointer
Head
Read Pointer
Tail
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
9/51
9
TI DSP Developer Online Training
Circular Buffer
Delay buffer actually
implemented as a
circular buffer
Metaphor of a recordingplatter, advancing once
per sample.
Modulo pointer arithmetic
used in the calculation ofread and write pointer
positions
Write pointer eventually
overwrites oldest samples
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
10/51
10
TI DSP Developer Online Training
Agenda
Introduction
Fixed Digital Delay
Variable Digital Delay Implementation Details
Further Investigation
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
11/51
11
TI DSP Developer Online Training
Fixed Digital Delay
As name implies, constant
or Fixed delay length
Typical uses include: Time alignment
Canyon echo
simulation
Play Along delay effectDelay Buffer
+
+ Output y(n)
Input x(n)
Regen
MixWet
MixDry
Write Pointer
Head
Read Pointer
Tail
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
12/51
12
TI DSP Developer Online Training Home Theater Time AlignmentExample
Speed of sound: 1116 ft /
second (at sea level)
Approx 1 ms = 1 ft
7.1 Surround System, 7discrete channels of delay
to time align each speaker
to optimal l istening
locationListener
Delay_RS
Delay_RF
Delay_C
Delay_LF
Delay_LS
Delay_LB Delay_RB
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
13/51
13
TI DSP Developer Online Training
Audio Effect Examples
Canyon Echo simulation
Popularized by people at canyons
Play along Delay
Popularized by U2s The Edge
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
14/51
14
TI DSP Developer Online Training
Agenda
Introduction
Fixed Digital Delay
Variable Digital Delay Flanger
Chorus
Implementation Details Further Investigation
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
15/51
15
TI DSP Developer Online Training
Variable Digital Delay
As name implies, delay length varies over time.
Primary use is in audio effects
Read pointer is driven by a Low FrequencyOscillator (LFO)
Reading faster or slower than input sample rate
creating a respective increase / decrease inpitch
This pitch shifting can be thought of as Doppler
shift, implying motion
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
16/51
16
TI DSP Developer Online Training
Anatomy of a Variable Delay
Exactly the same as a Fixed Delay except read pointer
varies via a Low Frequency Oscillator (LFO)
Typically variable delay composed of two portions:
Static delay Variable delay
Delay Buffer
+
+ Output y(n)
Input x(n)
Regen
MixWet
MixDry
Write Pointer
Head
Read PointerTailStatic Variable
Low Frequency Oscillator
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
17/51
17
TI DSP Developer Online Training Low Frequency Oscillator(LFO)
Oscillator
1.0
0.0
Width
Integer . Fraction
Static Delay
Read Address
Read pointer is driven by a Low Frequency Oscillator (LFO)
As its name implies, this oscillator is a very low frequency (0.1Hz to 2 Hz)
Output of the LFO is both integer and fractional samples
Integer port ion of the LFO determines the specific samplesinvolved in interpolation
Fractional portion of the LFO is used in the interpolation tocreate sub-sample delays
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
18/51
18
TI DSP Developer Online Training
Sample Skipping
The crudest form of variable delay is moving the
read pointer on integer sample boundaries.
Sometimes referred to as sample skipping
since the pointer skips from one sample to the
next instead of smooth motion
Results in noticeable zipper noise as the delay
buffer is varied
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
19/51
19
TI DSP Developer Online Training
Sub-sample interpolation
Delay pointer can be moved fractional samples
Accomplished by interpolating between successive
samples.
The simplest implementation is l inear interpolationbetween two successive samples
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
20/51
20
TI DSP Developer Online Training
Agenda
Introduction
Fixed Digital Delay
Variable Digital Delay Flanger
Chorus
Implementation Details Further Investigation
S O
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
21/51
21
TI DSP Developer Online Training
Flanger Effect
Legend has it that a recording engineer bumped against
the flange of the tape reel while double tracking a guitar
track.
This momentarily slowed the tape speed, thus changing
the pitch slightly, and subsequently recovering to the
appropriate tape speed and pitch.
Mixed with the original track caused the characteristic
sound, thus Flanging , in the analog sense, was born.
TI DSP D l O li T i i
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
22/51
22
TI DSP Developer Online Training
Flanger Effect
Frequency response of a Flanger is of primary
importance.
Creates harmonically related notches at multiples of
delayLength/2 When viewed on a logarithmic frequency scale, these
notches appear as teeth in a comb , and are thus
sometimes called comb filters.
Varying delay length over time changes the number andfrequencies of notches
Ideally, the delay length goes to zero, which allows the
frequency notches to sweep to infinity
Regen path used to intensify the effect
TI DSP Developer Online Training
Fl A di E l
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
23/51
23
TI DSP Developer Online Training
Flanger Audio Example
Dramatic Sweeping effect
Most famous example is Barracuda by Heart
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
24/51
TI DSP Developer Online Training
Ch Eff t
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
25/51
25
TI DSP Developer Online Training
Chorus Effect
Simulation of multiple instruments playingsimultaneously, creating thicker sound due tominute differences in pitch and timing
Similar effects occur with multiple vocalistssinging the same notes simultaneously in achorus, thus the name Chorus
Primary importance is pitch shift, not frequencyresponse
To avoid frequency notching associated withflangers, a minimum delay is introduced called a
static delay Typically no regen path
TI DSP Developer Online Training
Ch A di E l
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
26/51
26
TI DSP Developer Online Training
Chorus Audio Example
Popularized by textural players such as Andy
Summers of The Police
TI DSP Developer Online Training
Agenda
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
27/51
27
p g
Agenda
Introduction
Fixed Digital Delay
Variable Digital Delay Implementation Details
Sample by Sample vs. Block Processing
Block Processing on the TMS320C6713 DSP Starter Kit
(DSK)
Using Ping-Pong Buffers
Code Excerpts inside Block Processing
Further Investigation
TI DSP Developer Online Training
Sample by Sample Processing
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
28/51
28
Sample by Sample Processing
An input sample is processed and an output
sample generated within a single audio sample.
PRO: Minimal transport delay.
CON: High overhead accessing the relatively
slow A/Ds, external memories, and D/As.
TI DSP Developer Online Training
External Memory
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
29/51
29
External Memory
Audio samples rates ranging from 44.1 kHz
(Compact Disc), 48 kHz, 96 kHz, and now 192
kHz at widths from 20 to 32 bits
Delays of tens of milliseconds consume 4410 to
19200 samples, per audio channel.
Insufficient on chip RAM to meet these delay
requirements
Larger external bulk delay RAM is needed
In high performance DSP such as TI
TMS320C6713 DSP, external memory poses a
bottleneck.
TI DSP Developer Online Training
Block Processing
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
30/51
30
Block Processing
A block of samples are gathered, a block of
samples are processed, and a block of samples
are output.
PRO: Increased efficiency by amortizing
overhead costs over a block of samples.
CON: Increased transport delay.
TI DSP Developer Online Training
Block Processing
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
31/51
31
Block Processing
TMS320C6713 DSP Enhanced Direct Memory
Access (EDMA) transfers, in which several
external memory accesses can be queued up.
EDMA hardware orchestrates the manipulation
of buffer pointers.
Primary process is notified when the samples
have been cached into internal memory.
Processing is done on an entire block, within
fast internal memory, and coefficients can be
cached to further improve performance.
TI DSP Developer Online Training Block Processing on TMS320C6713
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
32/51
32
gDSK
McBsP1
RX PingEDMA
RX Pong
TX Pong
TX Ping
Block Processing
TMS320C6713External Hardware
ADC
DAC
Frame Clock
Left Channel Right Channel
Left Channel Right Channel
Analog Out Left
Analog Out Right
Analog In Left
Analog In
Right
TI DSP Developer Online Training
RX/TX Ping-Pong Buffers
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
33/51
33
RX/TX Ping-Pong Buffers
Two receive (RX) buffers
Two transmit (TX) buffers
EDMA hardwareorchestrates datatransfers
Moves samples to/fromappropriate RX/TXbuffers
Generates interrupt withbuffers are full
Handles pointermanipulation to
Ping/Pong betweenbuffers on successiveblock transfers
TI DSP Developer Online Training Block Processing use of Ping/Pongb ff
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
34/51
34
buffers
Processing opposite
buffer EDMA is accessing
Provides an entire block
length period of time tocomplete processing
TI DSP Developer Online Training
Inside Block Processing
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
35/51
35
Inside Block Processing
Split
Left Buffer
Right Buffer
MergeAlgorithm 0 Algorithm 1 Algorithm N TX Ping/PongRX Ping/Pong
External Left Buffer
External Right Buffer
TI DSP Developer Online Training
Processing the Buffers
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
36/51
36
Processing the Buffers
void processBuffer(void){
Uint32 pingPong;
Int16 *receiveBuffer;
Int16 *transmitBuffer;
/* Get contents of mailbox posted by edmaHwi */
pingPong = SWI_getmbox();
/* Copy data from transmit to receive, could process audio here */
if (pingPong == PING) {
/* Toggle LED #3 as a visual cue */
DSK6713_LED_toggle(3);
receiveBuffer = gBufferRcvPing;
transmitBuffer = gBufferXmtPing;
} else {
/* Toggle LED #2 as a visual cue */
DSK6713_LED_toggle(2);
receiveBuffer = gBufferRcvPong;
transmitBuffer = gBufferXmtPong;
}
splitData(receiveBuffer, leftProcessingBuffer, rightProcessingBuffer, BUFFSIZE);
Flanger_Process(leftProcessingBuffer, rightProcessingBuffer, BUFFSIZE/2, variableDelayType_LinearInterpolation);
Delay_Process(leftProcessingBuffer, rightProcessingBuffer, BUFFSIZE/2, 48000*3.5);
mergeData(transmitBuffer, leftProcessingBuffer, r ightProcessingBuffer, BUFFSIZE/2);
}
TI DSP Developer Online Training
Split
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
37/51
37
Split
/** 2 16 bit words are packed into single 32 bit transfer. The input buffer
* is interleaved left/right/left/right/... and subsequently split into
* separate left and right buffers.
*/
void splitData(Int16 *inbuf, Int16 *leftBuff, Int16 *rightBuff, Int16length)
{
length = length / 2;
while(length--)
{
*leftBuff++ = *inbuf++;
*rightBuff++ = *inbuf++;}
}
TI DSP Developer Online Training
Merge
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
38/51
38
Merge
/** 2 separate buffers are merged to form single output buffer
* interleaved as left/right/left/right/....
*
* NOTE: Assumes left and right buffers are equal length, and
* that output buffer will be 2 times the input length*/
void mergeData(Int16 *outbuf, Int16 *leftBuff, Int16 *rightBuff, Int16 length)
{
while(length--)
{
*outbuf++ = *leftBuff++;
*outbuf++ = *rightBuff++;
}
}
TI DSP Developer Online Training
Fixed Delay
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
39/51
39
y
static void delay(Int16 *audioBuffer, Int16 audioBufferLength, Int32 delayLength, DelayInfo* delayInfo){
Int16 i = 0;
Int16 input, output;
Int32 index = delayInfo->index;
delayLength = DELAY_BUFFER_LENGTH - delayLength;
for (i = 0; i < audioBufferLength ; i++) {output = delayInfo->buffer[(index + delayLength) % DELAY_BUFFER_LENGTH]; // get tail from within buffer
input = audioBuffer[i];
delayInfo->buffer[index] = input + (delayInfo->regen * output); // update head with new input
audioBuffer[i ] = (delayInfo->mixDry * input) + (delayInfo->mixWet * output); // get tai l from within buffer
index = (index + 1) % DELAY_BUFFER_LENGTH;
}
delayInfo->index = index;
}
Delay Buffer
+
+ Output y(n)
Input x(n)
Regen
MixWet
MixDry
Write Pointer
Head
Read Pointer
Tail
TI DSP Developer Online Training Allocating Delay Buffers inSDRAM
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
40/51
40
SDRAM
#pragma DATA_SECTION(delayBufferLeft, "SDRAM")
Int16 delayBufferLeft[DELAY_BUFFER_LENGTH];
#pragma DATA_SECTION(delayBufferRight, "SDRAM")
Int16 delayBufferRight[DELAY_BUFFER_LENGTH];
TI DSP Developer Online Training
Delay Instance Data
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
41/51
41
y
typedef struct{
Int32 index;
Int16* buffer;
float regen;
float mixDry;
float mixWet;
} DelayInfo;
DelayInfo leftDelayInfo = {
0, // index
delayBufferLeft, // buffer
0.5, // regen
0.707, // mixDry
0.707 // mixWet
};
DelayInfo rightDelayInfo = {
0, // index
delayBufferRight, // buffer
0.5, // regen
0.707, // mixDry
0.707 // mixWet
};
void Delay_Process(Int16 *audioBufferLeft, Int16 *audioBuf ferRight, Int16 audioBuf ferLength, Int32 delayLength)
{
delay(audioBufferLef t, audioBufferLength, delayLength, &lef tDelayInfo); // Lef t delay
delay(audioBufferRight, audioBufferLength, delayLength, &rightDelayInfo); // Right delay
}
TI DSP Developer Online Training
Sample Skipping Flanger
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
42/51
42
p pp g g
static void flangerSampleSkip(Int16 *audioBuffer, Int16 audioBufferLength, VariableDelayInfo *delayInfo){
Int16 i = 0;
Int32 delayLength;
Int16 input, output;
Int32 index=delayInfo->index;
LFOInfo lfoInfo = *(delayInfo->lfoInfo);
for (i = 0; i < audioBufferLength; i++) {updateLFO(&lfoInfo);
delayLength =(lfoInfo.lfo*delayInfo->width*LFO_MAX) + delayInfo->staticDelay; // calculate tail pointer
delayLength = DELAY_BUFFER_LENGTH - delayLength;
output = delayInfo->buffer[(index + delayLength) % DELAY_BUFFER_LENGTH]; // get tail from within buffer
input = audioBuffer[i]; // update head with new sample
delayInfo->buffer[index] = input + (delayInfo->regen * output); // write to buffer audioBuffer[i ] = (delayInfo->mixDry * input) + (delayInfo->mixWet * output); // mix wet and dry paths
index = (index + 1) % DELAY_BUFFER_LENGTH; // update head pointer
}
*(delayInfo->lfoInfo) = lfoInfo; // update instance variables
delayInfo->index = index;
}
TI DSP Developer Online Training
Flanger via Linear Interpolation
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
43/51
43
g
static void flangerLinearInterpolation(Int16 *audioBuffer, Int16 audioBufferLength, VariableDelayInfo *delayInfo){
Int16 i = 0;
Int32 in tegerDelayLength;
float fractionalDelayLength;
Int16 input, output, cu rrentSample;
LFOInfo lfoInfo = *(delayInfo->lfoInfo);
Int32 index = delayInfo->index;
Int16 previousSample = delayInfo->previousSample;
for (i = 0; i < audioBu fferLength; i++) {updateLFO(&lfoInfo);
// calculate tail pointer
fractionalDelayLength =(lfoInfo.lfo*delayInfo->width*LFO_MAX) + delayInfo->staticDelay;
fract ionalDelayLength = (float)DELAY_BUFFER_LENGTH - fracti onalDelayLength ;
integerDelayLength = fractionalDelayLength; // implicit cast to Int32 does floor()
fraction alDelayLength -= integerDelayLength; // subtract off integer portion to leave fr actional portion of pointer
// get tail from w ithin bu ffer
currentSample = delayInfo->buffer[(index + integerDelayLength) % DELAY_BUFFER_LENGTH];
// linear interpolation between current and previou s samples
output = (currentSample * fractionalDelayLength) + (previousSample * (1.0 - fractionalDelayLength));
input = audioBuffer[i];// update head wi th new sample
delayInfo->buffer[index] = input + (delayInfo->regen * output); // write input and regenerated output
audioBuf fer[i ] = (delayInfo->mixDry * input ) + (delayInfo->mixWet * output); // mix wet and dry paths
previousSample = currentSample // update previous sample
index = (index + 1) % DELAY_BUFFER_LENGTH; // update head pointer }
*(delayInfo->lfoInfo) = lfoInfo; // update instance variables
delayInfo->index = index;
delayInfo->previousSample = previousSample;
}
TI DSP Developer Online Training
Triangle Wave LFO
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
44/51
44
typedef struct{float lfo;
float l foStep;
int sign;
}LFOInfo;
static float l foStep(float speed){
return speed*2.0/SAMPLE_RATE;
}
static void updateLFO(LFOInfo* lfoInfo)
{float speculativeStep;
// Update LFO
speculativeStep = lfoInfo->lfo + lfoInfo->lfoStep;
if (speculativeStep < 0 || speculativeStep > 1)lfoInfo->sign = -lfoInfo->sign;
lfoInfo->lfo += (lfoInfo->sign * lfoInfo->lfoStep);
}
TI DSP Developer Online Training
Transport Delay vs. CPU Usage
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
45/51
45
Block Size
Transport Delay
in mSec % CPU Usage
2 0.0625 100+
4 0.125 67.75
8 0.25 47.85
16 0.5 38.21
32 1 33.21
64 2 30.78
128 4 29.62
256 8 28.94
TI DSP Developer Online Training
Agenda
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
46/51
46
Introduction
Fixed Digital Delay
Variable Digital Delay
Implementation Details
Further Investigation
TI DSP Developer Online Training
Further Investigation
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
47/51
47
Multirate signal processing
Reverberation
Other LFO waveforms
TI DSP Developer Online Training
References
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
48/51
48
Effect Design (part 2) , Jon Dattorro, Journal of
the AES, October 1997
Multirate Digital Signal Processing , Crochiere &
Rabiner, Prentice-Hall 1983
DSP Applications Using C and the TMS320C6x
DSK, Rulph Chassaing, Wiley 2002
TI DSP Developer Online Training
Summary
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
49/51
49
Fixed Digital Delay
Variable Digital Delay
LFO
Flanger/Chorus
Implementation Details
Block processing on TMS320C6713 DSK
Use of Ping/Pong buffers
Circular buffers
Locating delay buffers in external memory
Linear Interpolation sub-sample delays Transport Delay vs. Block Size
TI DSP Developer Online Training
Copyright Notice
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
50/51
50
Copyright by Texas Instruments Incorporated
TI DSP Developer Online Training
TIs eLearning solutions provider
-
8/12/2019 Delay Based Audio Effects Using the TMS320C6713
51/51
51
Visit T&OE www.ti-eservices.com
Reach your customers with audio/video presentations.
On-demand delivery to TIers or TI customers
worldwide, anywhere, anytime.
Deliver your training online!
T&OE has a volume publishing agreementfor using Presedias PPT2Flash services.
Find more info at http://www.ti-eServices.com
Steve Enty ([email protected]): 972-917-5029
Clark Hise ([email protected]): 972-917-1239
T&OE ServicesT&OE Services
Breeze Copyright by Macromedia
http://www.ti-eservices.com/http://www.ti-eservices.com/http://www.ti-eservices.com/http://www.ti-eservices.com/http://www.ti-eservices.com/http://www.ti-eservices.com/