Monday 24 December 2012

Compiling PortAudio and Visual Studio (C++)

Install Visual Studio (C++)
This does not include 64 bit compilation support so install the Windows Software Development Kit version 7.1 from here : http://msdn.microsoft.com/en-us/windowsserver/bb980924.aspx
Convert and build the project : double click the .sln and when it has completed right click on the project and select rebuild
Additional instructions for compiling Portaudio :
http://portaudio.com/docs/v19-doxydocs/compile_windows.html
The ported project generates a .lib to link with your application and a .dll that you either put in the application directory or put into C:\Windows\System32.


One of the things I didn't understand was how the Portaudio APIs (WMME, DS etc) mapped to the hardware interfaces. There is an example (pa_devs.c) that I found really useful. I just compiled it and linked against the .obj created below; copied the .dll into the current directory and ran it. The output on the screen is most informative.

Which API to use ? :
In general I have had great results with the Direct Sound API and tend to use that.
I found the WDM-KS API has very low latency (for a laptop computer running an OS) of 4600 samples from output to input. The downside is that for most audio interfaces it only seems to support 44.1KHz (at least on the hardware that I am using) but that is OK for most applications.

Which APIs are compiled into the library ? :
These are selected using the PA_USE_XXXX #defines which can be configured using the compiler switches. To do this in Visual Studio Express do the following :
Right click on the project (portaudio)
Select "Properties"
Select the Configuration and Platform you wish to modify
Navigate to : Configuration Properties | C/C++ | Preprocessor | Preprocessor Definitions
Set your required API definition to 0 (disable) or 1 (enable) e.g. : PA_USE_WDMKS=1

For Visual Studio Express 2013 I made the following changes :
  1. Change the General Options | Target Name to add the extension _x86 : $(ProjectName)_x86
  2. Define PA_WDMKS_NO_KSGUID_LIB in the Preprocessor Definitions
and everything compiled fine.

When I used the DirectSound version of PortAudio I used the latest version of : DirectX (9.0a).

Here is a useful tip when using PortAudio with a GUI :
Modify PaUtil_DebugPrint in pa_front.c as shown below and the debug statements will be written to the file debug.log.
void PaUtil_DebugPrint( const char *format, ... )
{
va_list ap;

FILE *logFile;
logFile = fopen( "debug.log", "a" );

va_start( ap, format );
// vfprintf( stderr, format, ap );
vfprintf( logFile, format, ap );
va_end( ap );

// fflush( stderr );
fclose( logFile );
}


If you have found this solution useful then please do hit the Google (+1) button so that others may be able to find it as well.
Numerix-DSP Libraries : http://www.numerix-dsp.com/eval/

No comments:

Post a Comment