EBC Exercise 18 Using the DSP for Audio Processing

From eLinux.org
Revision as of 14:18, 25 August 2011 by Yoder (Talk | contribs) (Running the DSP)

Jump to: navigation, search


In the previous exercise you saw how to bring audio into the Beagle and send it out again. You also did some processing on the audio. All this was done on the ARM processor. The DM3730 on the BeagleBoard has both an ARM processor and a C64x fixed-point DSP. This exercise shows you how to use the DSP via C6Run. C6Run is a set of tools which will take in C files and generate either an ARM executable, or an ARM library which will leverage the DSP to execute the C code.

There are two uses of C6Run, exposed through two different front-end scripts. They are called C6RunLib and C6RunApp. We focus on C6RunLib here.

Examine the Files

  • Copy the AudioThru files from here to your Beagle.
  • Change directories to AudioThru/lab06d_audio_c6run.
# cd lab06d_audio_c6run
# ls

These are the same files as used in the previous audio thru lab. The files audio_process.c and audio_process.h are new. audio_thread.c has been changed slightly. Makefile is completely different.

Edit audio_thread.c and search for audio_process. There are two occurrences. I'll talk about the first on later, go to the second.

$ gedit audio_thread.c

	audio_process((short *)outputBuffer, (short *)inputBuffer, blksize/2);

I've replaced the call to memcpy() with the call to audio_process(). Pointers to the input and output buffers are passed along with the number samples in the buffers. Note blksize is the number of 8-bit chars in the buffers. We're working with 16-bit samples, so everything is converted to shorts.

Look at audio_process.c. Presently all it does is a memcpy() when called.

Make

Before the first make the paths need to be set up. Do this:

$ source ~/c6run_build/environment.sh
$ source ~/c6run_build/loadmodules.sh

We are now dealing with two C compilers. One for the ARM the other for the DSP. The first source above sets PATHs for each of the compilers. Take a look at environment.sh to see the details. The most interesting part is PLATFORM_CFLAGS, which we'll discuss later. The second source (loadmodules.sh) loads some kernel modules that are needed to support the DSP. Take a look at it, we'll explain some of it later.

Be sure to source the environment.sh file every time you start a new terminal. Source the loadmodule.sh file every time you reboot your Beagle.

Run make, but do it like this so you can see what it creates:

$ make clean
$ ls
$ time make
$ ls -sh

My make takes about 20 seconds to compile everything. What new things do you see?

There are 3 groups of files here:

  1. The source code (*.c and *.h),
  2. object files for running on the ARM (gpp) only (audioThru_arm, gpp, gpp_lib) and
  3. objects files for running on the DSP (audioThru_dsp, dsp, dsp_lib).

What's significant is that the same source code produced both sets of objects (dsp, gpp). It's how the source is compiled determines where it is run. If you run ./audioThru_arm the code runs only on the ARM. Try it. It should run just like before.

Running the DSP

Now try running ./audioThru_dsp. This code runs on the ARM, mostly. The function(s) in audio_process.c run on the DSP. Here's what's happening.

  1. When you run ./audioThru_dsp, main.c and audio_thread.c run on the ARM as before.
  2. C6run has inserted a stub for audio_process() so that when is it called the first time on the ARM, it checks to see if the DSP has been initialized. If not, the ARM loads the code for audio_process() on the DSP and then passes the parameters to the DSP and tells it to run the code.
  3. Notice the line: Starting DSP...1.5XXX s. This is printed after the first call to audio_process(). Starting the DSP takes about 1.5s or so. Fortunately it only has to start once.
  4. The ARM waits for the code to complete on the DSP (i.e. it blocks so other processes on the ARM can run.)
  5. Once the DSP completes, the ARM continues running.
  6. Subsequent calls to audio_process() need only pass the parameters and tell the DSP to go.

Running

Run the apps.

# ./audioThru_arm
# ./audioThru_dsp

Both will run until you hit ctrl-C. To hear something you need to hookup your mp3 player to the input on the Beagle and speakers to the output.

Once you are sure it is working, try building everything from scratch.

# make clean
# make

By default make creates both the ARM only and DSP objects. make takes about 20 seconds on my Beagle.

Experiment with the code

Now that you have something working, play around a bit. git is installed so you can preserve the present contents of the files with:

# git add Makefile audio_input_output.c audio_process.c audio_thread.c
# git commit -m "Initial commit"

If needed you can use git to retrieve the original version of the files.

Things to try:

  • There are places in the code where timing can be displayed. Remove the comments and display the times. How often is the main loop executed? How long does the DSP take? What's the overhead for the DSP?
  • Try making the DSP do more than pass through. Zero out the left channel to be sure it is working.
  • Try changing the sampling rate and buffer sizes. What setting cause the buffers to overflow or underflow?
  • Implement your own processing on the DSP. Do a simple FIR lowpass filter, etc.
  • Switch the input to the microphones on the web cam and listen to your voice.