# Audio Effects Lab

AI and Robotics

Nov 24, 2013 (4 years and 7 months ago)

181 views

Audio Effects Lab

Introduction:

This lab assignment deals with simple digital audio effects; the algorithms are
implemented using digital signal processors so that the music signals can be processed in
real
-
time. We will implement a simple audio loo
p back in this lab and listen to a piece of
music from a portable CD player. In part 1 we will use Matlab for the implementation
and process the data off
-
line using .wav files. This should give you a good understanding
of the sound effects and their algori
thms. Part 2 focuses on the implementation of these
signal
-
processing applications on the Spectrum Digital TMS320C5410 EVM board.
These simple effects can be combined to give complex acoustic effects. For a more
detailed description of these applications s
ee Orfanidis section 8.2.

You can record your own voice to test your programs. Make sure that you record in the
single channel mode with 8 bit resolution at a sampling frequency of 8 kHz and that you
save the file as an .wav file.

Equipment Needed:


PC with Matlab and Signal Processing Toolbox


Microphone and speakers/earphones


Portable CD player with your favorite musical artists.


Texas Instruments TMS320C5416 DSK boards

Theory:

of the textbook to introduce the concept of circular buffers.

Part 1: Digital Audio Effects in Matlab.

Echo Filter:

Implement a simple echo filter that has the following difference equation:

y(n) = x(n) + ax(n
-
D)

The tran
sfer function and the impulse response of this filter are:

H(z) = 1 + az
-
D

, h(n) =

(n) + a

(n
-
D)

Choose D, the number of samples that the signal is delayed, such that the signal is
delayed by 0.125s and let
a
be 0.5. (
Time Delay


DT

D/

fs

)
fs
= 8000 Hz.

Plot the frequency response of the filter using the matlab command
freqz.
m>freqz(num,den); num is a vector of the numerator coefficients; den is a vector of
the denominator coefficients.

Experiment with lower and lower val
ues of D and listen to your delayed signal until you
can no longer distinguish a separate echo. How many milliseconds of delay does this
correspond to?

Sample Matlab code for implementing filter:

function [y]=simpledelay(fn);

% fn
-
string containing fil
ename of wav file

xlen=length(x);%Calc. the number of samples in the file

%Initialize constants

a=.5;delay=0.2;

D=delay*fs; %Calculate the number of samples in the delay

y=zeros(size(x));

% Plot the spectrum of the ec
ho signal

figure(1);clf;

freqz([1 zeros(1,D
-
1) a],[1]);% plot the spectrum of the echo signal

title(‘Spectrum of Echo Filter’);

% filter the signal

for i=D+1:1:xlen

y(i)=x(i)+a*x(i
-
D);

end;

sound(y,fs));%play the filtered signal y

Comb Filter

three successive echoes echo filter gives the following comb filter:

y(n)= x(n) + ax(n

D) + a
2

x(n

2D) + a
3
x(n
-
3)

The transfer function of this filter is:


z) = 1 + az
-
D

+ a
2
z
-
2D

+ a
3
z
-
3D

Implement the non
-
recursive form of this filter choosing D such that the delay is 0.2s. Set
a
to 0.5 and plot the frequency response of the comb filter.

Keeping the delay D the same, choose
a
=0.2 and run the program again
. What effect do
you hear? Repeat for
a =0.1
.

Reverberator Filter

If an infinite number of successive echoes are added up, the effect imitates the
reverberating nature of a room and gives the IIR comb filter or reverberator. The
following plain reve
rberator filter can be used as a basic building block for more
complicated reverberation algorithms (see Orfanidis, section 8.2.3). Its I/O equation and
transfer function are:

y(n) = ay(n

D) + x(n), H(z) = 1/(1

a z
-
D
)

Again, choose D such that the

delay is 0.125s, let
a

be 0.5 and plot the transfer function
of this plain reverberator filter. Run the program with the new feedback coefficient a=.9.
Listen to the impulse response. Repeat for a = 0.25. Discuss the effect of increasing or
decreasing

a
.

Part 2: Audio Loop back on the DSP board

This section of the lab introduces the user to real
-
time programming on the Texas
Instruments TMS320C5416 DSK board. The purpose is to develop your familiarity with
the hardware and software used in this
course, and consequently introduce you to the
real
-
time programming concepts to be considered. Each real
-
time signal must be
retrieved, digitized (quantized), processed by the C5416 DSP chip, and finally the output
will be converted to an analog signal. T
he program will allow the user to look at a
generated waveform from the analog output. The analog waveform, that would be
developed, will be sent to the C5416 DSK board via the analog input. The waveform will
IC) on the C5416 DSK board, to be digitized.
The AIC is interfaced to the C5416 DSK chip, which processes the digital signal and then
sends it back to the AIC to be converted into an analog signal. The AIC has a sampling
rate of 16 KHz (32 KHz is possibl
e).

The section will consist of two parts, the first will be utilizing the DSP board to create the
same audio effects that were simulated using the Matlab software package. The labs
were
provided

by Prof. Richard Sikora. The following is the description

of the first
section:

Section 2a:

1.

A template for an audio project. Sets up the audio codec, the 4 user switches
to control the program and the 4 LEDs to act as a bargraph display. This
project template can be used as the starting point for new projec
ts.

2.

Delays and Echo. Simulates delays in communications networks and
reflection of sound heard in a canyon. Introduces circular buffers and the
configuration used for a Finite Impulse Response (FIR) filter.

3.

Reverberation, which is often abbreviated to rev
erb. Simulates single and
multiple reflections from the walls of a room. Introduces the configuration
used for an Infinite Impulse Response (IIR) filter.

4.

Electronic Crossover. Divides an audio signal into bass and treble and is used
to drive different loud
speakers. Uses an FIR filter and the user switches to
select 15 different crossover frequencies between 100 Hz and 6.4 kHz.

Follow the instructions from the document
TMS320C5416 DSK: Installing the
Applications for section 2a

and proceed to run the audio effects lab. Pay attention to the
code, and make sure you understand how it works. You will be required to give a
detailed explanation
of how the code functions.

Section 2b: Audio Loop back Example

The DSK uses a Burr Brown PCM3002 stereo codec for input and output of audio
signals. The codec samples analog signals on the microphone and line inputs and
converts them into digital data

so it can be processed by the DSP. When the DSP is
finished with the data it uses the codec to convert the samples back into analog signals on
the line and speaker outputs so the user can hear the output.
[1]

The on
-
board peripheral library provides hig
h
-
level support for DSP applications running
on the C5416 DSK. This library enables the user to develop applications that can control
and operate the peripherals of the DSK platform.

The on
-
board peripheral support includes:

On
-
board peripheral initiali
zation

On
-
board peripheral register access

On
-
board peripheral data movement

The following are the BSL API commands:

DSK5416_init():

Initialize the 5416 DSK

DSK5416_PCM3002_openCodec():

Allocate an identifying handle for an
instance of a codec

DS
K5416_PCM3002_closeCodec():

Release a codec handle

DSK5416_PCM3002_setParams()

Set parameters on codec registers

Read 16 bits from the codec data
stream

Read 32 bits from the codec data
stream

DSK54
16_PCM3002_write16()

Write 16 bit value to codec data
stream

DSK5416_PCM3002_write32()

Write 32 bit value to the codec data
stream

DSK5416_PCM3002_rset()

Set the value of a codec control
register

DSK5416_PCM3002_rget()

Return the value of a codec

register

DSK5416_PCM3002_outGain()

Set the codec output gain

DSK5416_PCM3002_loopback()

Enable/disable the codec loopback
mode

DSK5416_PCM3002_mute()

Enable/disable the codec mute mode

DSK5416_PCM3002_powerDown()

Enable/disable the codec powerdown
m
odes

DSK5416_PCM3002_setFreq()

Set the codec sample rate

DSK5416_DIP_init()

Initialize the DIP switches

DSK5416_DIP_get()

DSK5416_LED_init()

Initialize the LED’s

DSK5416_LED_off()

Turn specified LED off

DSK5416_LED_on()

Turn specified LED on

DSK5416_LED_toggle()

Toggle the specified LED

The description can be found in
C:
\
ti
\
docs
\
hlp
\
C5416DSK.HLP
. Go to the Software
Overview
--
> BSL API Summary. It comes w
ith sample program examples, and good
source codes can be found in
C:
\
ti
\
examples
\
dsk5416
\
bsl
. To successfully run the
programs first copy the files to your U:
\

drive (
Running

from the C:
\
ti directory can
corrupt the files for other students if you fail t
the code
)
. From
C:
\
ti
\
examples
\
dsk5416
\
bsl

go to the index section and type the
keyword i.e. tone, and read the description of how the program works and how one
needs to run the example.

Finally give a description o
f how one would utilize the API commands to read a
streaming audio signal to the DSP board. Once that is done one should create an audio
effect that imitates the reverberating nature of a room, and the user should hear that from
the output of the speaker.

Questions to be answered for Part 1:

Echo:

1.

Explain how this filter works
--
relate the frequency response and the difference
equation.

2.

What is the smallest delay that your ears can detect? Calculate the delay in terms
of the number of samples for a

sampling rate of 8 kHz.

3.

Using the Matlab frequency response of this filter with a delay of 0.1 s and
sampling rate of 8 kHz, where do the nulls in the frequency response fall (at what
frequency?)? Explain this phenomenon in physical terms. (Hint: It’s ca
lled
multipath interference)

4.

Experiment with different values of
A.
What happens when
A
is small or large?

Comb:

1.

Explain how this filter works
--
relate the frequency response and the difference
equation.

2.

Using the Matlab frequency response of this f
ilter with a delay of 0.1 s and
sampling rate of 8 kHz, where do the nulls in the frequency response fall (at what
frequency?)?

3.

Experiment with different values of
A.
What happens when
A
is small or large?
Compare this filter with the echo filter.

Reverberator:

1.

Explain how this filter works
--
relate the frequency response and the difference
equation.

2.

Compare the frequency response to an echo filter with the same delay value D,
sampling rate and constant,
a
. How do they differ?

3.

Compile and run this program for
A
=.5 and
D
ELAY=3000 with a sampling rate
of 8 kHz. What do you hear? What delay does this correspond to?

4.

Change
a
to .25 and recompile the program. What do you hear?

5.

Change
a
to .9 and recompile the program. What do you h
ear? Discuss the effect
of changing
a
.

6.

What is the maximum value of
a?
Why is this the maximum value?

Questions to be answered for Part 2:

Give a detailed description of how the code from section 2a works.

Describe the functi
ons of API commands a