Two Dimensional Spatialization of Sound

I originally wrote this package at the Voice Systems and Technologies group of the Communications Research Centre Canada (CRC) to support a project sponsored by DND/Defence and Civil Institute of Environmental Medicine. (DCIEM) It uses Head Related Transfer Functions to create a 2D soundscape.  The program takes a single monaural sound signal and processes it to create a binaural signal that places the source of the sound at an selectable arbitrary place around the listener.  The package makes use of a set of HRTF Measurements of a KEMAR Dummy-Head Model created by Bill Gardner and Keith Martin of the MIT Media Lab.

Thanks to DCIEM and CRC, I have received permission to release the package under the GNU General Public Licence.

What is it?

There are five parts to the package. The sound spatialization software is ANSI C, and can be ported to any platform which will support the sound I/O requirements.  The example program runs comfortably on a Pentium® 100.

Sound Spatialization Software

The main functions are:
- soundscapeUpdate(), which specifies the coordinates of the sound source and listener and the positions of the walls of the room which they occupy, and
- spatialize(), which given a vector of monaural speech samples produces a vector of binaural spatialized speech samples based on the previously supplied coordinates.

The Example Program for Windows

The Windows example program will allow you to experiment with sound spatialization.

The window which opens when you launch sound2d.exe is a plan view of a room.  Click the left mouse button to move the position of the sound source.  Click the right mouse button to move the position of the listener.  Drag the window to change the size and shape of the room.

The file menu allows the user to open and play a sound file.  The sound file must be monaural, 16 bit samples, and recorded at 11025 samples/second.  The sound card must be able to support stereo output at this sampling rate.

A text space at the bottom gives the azimuth and range of the sound source relative to the listener, as well as the number of taps and last tap position for the right and left ear filters.

Five sound rays are shown.  The blue ray is the direct ray from sound source to listener.  The four green rays are first order reflections of the sound off the walls of the room.

Utility for Calculating the D-HRTFs

This is the program that was used to calulate the differential HRTFs that are used in 3Dsound.c The program was written on an Apple Macintosh, and was written to use a closed source FFT. This program would have to be converted to use the new open source FFT that the 2D sound software uses.

The program reads in a stereo hrtf file recorded in (left/right) sample formats as 16 bit ints.  It calculates an inverse filter based on the right channel hrtf, then applies the inverse filter to the left channel.  The sampling rate is reduced from the original 44100 Hz to 11025 Hz by decimation after low pass filtering in the frequency domain.

An FFT written in well structured C.

This function is based on a paper entitled "A New Principle for Fast Fourier Transformation", Charles M. Rader and N.M. Brenner, I.E.E.E. Transactions on Acoustics, Speech and Signal Processing, June 1976, pp 264-266. It is loosely based on a translation of a FORTRAN subroutine "FOUREA", which appeared in the book "Programs for Digital Signal Processing", published by I.E.E.E. Press, chapter 1, section 1.1, 1979.

Also included is a small test application that can be used to compare the result of this FFT with four1.c from Numerical Recipes in C. Note that the Licence of that book does not allow redistibution of the four1.c code. This test application can guide you in converting other programs to use the open source FFT.

TMS320C3x code

The latency associated with the operating system limits the rate of motion which can be imparted to the sound. As a result, we have considered running the 2D sound engine on a DSP coprocessor rather than within the Windows environment, and have developed a low-level API for the TMS320-C3X DSP for use in this and other projects.

The low-level API is similar in functionality to the low-level sound API for Windows, and allows the developer to program at a higher level of abstraction, not having to deal with hardware interrupts. It contains drivers for the Crystal CS4231A audio codec and implements audio buffers as linked lists. When actions on a given buffer are complete, a user-specified callback function is called to process the buffer. The last thing the function must do is add the buffer back to the end of the linked list.

An example of the use of the API is contained in System35.c. The example refers to functions of a vocoder which are not within the scope of the GNU General Public Licence. The developer can substitute her own functions for the ones shown.

Obtaining the package

The source code of Version 0.1.5 of the software is distributed in a ZIP file
here.  I have also provided a ZIP file of the Windows executable.  It is recomended that you look at the README file which is also included in the source package.

The dHRTF calculation utility and the C_FFT package are both in the package.

you may also obtain just the C_FFT function Here

The TMS320 Code is Here

Please send me any comments and suggestions at

New! Please read the FAQ

Web Page designed by Charles MacDonald

link back to my home page.