Simultaneous Audio I/O with Scilab


Summary

pa_wavplay enables simultaneous input and output of audio signals via a sound card on a Windows PC, directly to the workspace of Matlab or Octave. It is based on the very popular multi-platform Portaudio audio I/O library. This page describes a port of pa wavplay to Scilab, a comprehensive matrix manipulation package available under an open-source licence.

pa_wavplay was written by Matt Frear and Johnson Chen of MARCS Lab at University of Western Sydney. Portaudio was written by Ross Bencina and others. Several other freely-available Matlab toolboxes use pa_wavplay as the interface to a sound card.

Details

This package is a port of the WMME version of pa_wavplay to Scilab 4.1.2. The port was made possible by the provision in Scilab of the mex-emulation code written by FD and JPC of the Scilab consortium. The original also supports ASIO and DirectX drivers. If you wish to use these other driver classes, please treat this distribution as a starting point.

The initial exploration of the Scilab port was helped by investigations by Aurelie Voisin and Mathias Krauss of ENSEEIHT Toulouse, who both worked en stage at DCU in Summer 2008.

This package enables:

Possible applications include: pa_wavplay is written to support sound hardware with multiple input and/or output channels, so its use is not restricted to cards with stereo (2-channel) connections.

The source code also works fine for Scilab v5.0.2.


Procedure

0. If you just wish to use pa_wavplay, just skip to step 9. below. The pre-built dll is supplied in the distribution package linked above. If for any reason you wish to actually re-build the package, start at step 1.

Building

1. To build pa_wavplay, first ensure that you have correctly installed a suitable Microsoft C++ compiler. I have used Visual C++ 2005 Express Edition, which is available for free download:

 http://www.microsoft.com/express/2005/download/default.aspx

Don't forget the service pack:

 "Microsoft Visual Studio Express Editions 2005 Service Pack 1"

available from that page.

2. You will also require an appropriate Platform SDK; I used the Windows Server 2003 Platform SDK:

  http://www.microsoft.com/express/2005/platformsdk/default.aspx

3. You will also need Portaudio version 18.x. I used:

http://www.portaudio.com/archives/portaudio_v18_1.zip

4. Copy the following files from the Portaudio distribution into the directory
where you have unzipped the scilab pa_wavplay distribution:

 Portaudio_v18_1\pa_common\pa_lib.c
 Portaudio_v18_1\pa_common\portaudio.h
 Portaudio_v18_1\pa_common\pa_host.h
 Portaudio_v18_1\pa_common\pa_trace.h
 Portaudio_v18_1\pa_win_wmme\pa_win_wmme.c

5. (Warning: this is a horrible kludge!)
Make a backup copy of the following file in the Scilab installation directory:

 C:\Program Files\scilab-4.1.2\Makefile.incl.mak,

such as:

 C:\Program Files\scilab-4.1.2\Makefile.incl.mak.gold.

6. In Makefile.incl.mak, just before the line:

CC_COMMON=-D__MSC__ -DWIN32 -c -DSTRICT -D__MAKEFILEVC__ -nologo $(INCLUDES) $(DTK) $(DPVM) $(DMKL) $(USE_MT)

place the following text as a new line:

USE_MT=-MT

7. Run Scilab, and CD to the directory containing the Scilab pa_wavplay code.

8. type:

 exec builder.sce

to build the dll sci_wavplayw.dll.

Using

9. Run Scilab and "cd"  to the directory in which you built pa_wavplay, or unzipped the distribution package.  Type:

 exec loader.sce

to load the new dll, and its associated Scilab function pawavplayw.

10. Type:

 pawavplayw()

to determine the sound device numbers to use in the next step.

11. Type:

 exec test_swp.sce

to test the new dll. You may wish to physically connect "line out" to "line in" to do a loop-back test.

12. The DLL and a set of Scilab macros that match the original Matlab m files may be loaded by typing:

 exec pa_wav.sce

Following execution of the above, the macros:

 pa_wavplay()
 pa_wavrecord()
 pa_wavplayrecord()

are available to the user. This may make it easier to port existing Matlab code that uses pa_wavplay.

NOTES:
======

i) If Scilab cannot find "windows.h" (which is in the Platform SDK but not part of the basic Visual Studio Express) you could follow the advice given on:

 http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=269821&SiteID=1

ii) pawavplayw() returns a report on all available (WMME) sound devices.

iii) There is a large delay ("latency") between the start of playback and of recording. This may be adjustable in the PortAudio code.

iv) steps 5. and 6. above are neccessary (but only in v4.1.2, and  NOT in v5.x) because the distributed Scilab v4.1.2 binary is compiled with multi-threading turned off ("USE_MT="), but  there are no single-threaded run-time libraries available with Visual C++ 2005 Express Edition.


Ronan Scaife,
Speech Laboratory,
RINCE,
School of Electronic Engineering,
Dublin City University,
Dublin 9,
IRELAND
scaifer@eeng.dcu.ie

updated: 8 July, 2011.

Original: 22 October 2008.