Audio Testing
Patrick Berry & Anjana Rajan
Team QRAP

Introduction

Many projects involve audio in some form or another. This creates an audio processing component of the project. It is very easy to come up with digital audio processing algorithms, but difficult to actually test them in hardware.
The purpose of this application note is to offer a simple method of testing digital audio algorithms in software rather than hardwave.  This has the potential of eliminating errors once the algorithms are implemented in VHDL. A C-program has been developed that allows a person to process digital audio in the .wav format. It returns a .wav file that can be listened to from a standard media player, or can generate other messages that the user desires.
 

.wav File Background

.wav files are a standard method of storing digital audio signals. The file consists of header information, along with digital audio samples. The header contains useful information about the audio file, such as:

Standard .wav files either have 8-bit samples or 16-bit samples. 8-bit samples are stored as an unsigned integer, while 16-bit samples are stored in two's comliment notation. This is important information to consider when you're encoding your digital audio algorithms.

Stereo samples are stored with alternating samples representing alternating channels.

sample 0 for channel 0
sample 0 for channel 1
sample 1 for channel 0
sample 1 for channel 1
.....
Mono samples are simply stored sequentially.
 

What wave.c Does

wave.c is a program which processes .wav files. It parses out the header information contained in the .wav file, outputs a data file containing the header information (useful for debugging), and contains functions that process the digital audio signals. It contains the flexibility so that users can add their own functions containing the audio algorithm of their choice.

wave.c requires that there be an input .wav file called input.wav, and generates an output .wav file called output.wav. An output file containing the header information is generated and is called wave.dat.
 

How to Add Other Digital Audio Functions

To make the most out of wave.c, you'll have to add in your own digital audio processing functions. Currently, there is a simple volume controller (adjusting the amplitude of the samples), and a distortion algorithm. To implement your own function, follow the general format of the above functions.  The following are some easy steps you can use to create your function.

The program's main purpose if to basically filter out the header information of the .wav file. Once this is done (in the main() function at the clause where i > 44) you can manipulate the data stream however you wish. For example, if you're testing an algorithm that detects patterns in audio, you may wish to output a message when the pattern is detected, not all of the bits. This assumes that the user has some basic knowledge of C-programming, and can interpret what is happening in the wave.c program.

NOTE 1: For information on the fgetc() or fputc() function, see their manual pages in UNIX, or there is plenty of documentation online. Same goes for bitwise operations.

NOTE 2: When you're implementing your audio algorithm, remember to take into account whether the signal is stereo or mono, with 8-bit samples or 16-bit samples. For the 16-bit samples, the bytes are stored in "Little Endian" mode, meaning the least significant byte is stored first and then the most significant byte. This will have to be accounted for both when reading in, and outputing samples. Also, 16-bit samples are stored in two's compliment format, which will also have to be accounted for.
 

How to Use wave.c

wave.c can be compiled and run on UNIX systems or DOS/Windows systems. When running the program, ensure you have a .wav file called input.wav in the same directory as the executable. The output files output.wav and wave.dat will be generated and saved in that directory as well. If you are having troubles with wave.c corrupting .wav files, look at the wave.dat file to see if you made any incorrect assumptions.

Here is a Makefile for compiling the code in UNIX.
The code was also successfully tested using the Borland C++ compiler for DOS.
 

Why Anyone Would Use This

In any project where there is an audio component, there will be synchronization issues, meaning you have audio algorithms ready to be tested, but the hardware isn't ready. This can be caused by ADC or DAC troubles, or any other interfacing problems. It is important, however that you be able to test the algorithms before implementing them in hardware. This can easily be done using wave.c in software.

For the advanced user, wave.c can also be used to generate testbenches of digital audio to be simulated in MaxPlus2.
 

Getting wave.c

You can get a copy of wave.c from here.

NOTE: You are allowed to modify the code in any way you see fit. The authors are not responsible for any problems that may occur with wave.c. If you use this in any application, please give credit to the authors. The least you can do is buy them lunch.
 

Acknowledgements

Information on .wav files was obtained from


A good C-Programming reference is:



Prepared By: Patrick Berry & Anjana Rajan
Team QRAP
Document Created: 2001/03/05
Last Updated: 2001/03/05