diff options
| author | Gary Scavone <gary@music.mcgill.ca> | 2007-12-06 01:40:05 +0000 |
|---|---|---|
| committer | Stephen Sinclair <sinclair@music.mcgill.ca> | 2013-10-10 01:08:11 +0200 |
| commit | 72ee1e6be2d918af467fef76932231be731795e9 (patch) | |
| tree | cdfed5b0b96a65ebfa407691218ea2ac8d1a64be /tests | |
Version 2.0
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/Debug/.placeholder | 0 | ||||
| -rw-r--r-- | tests/Makefile | 58 | ||||
| -rw-r--r-- | tests/Release/.placeholder | 0 | ||||
| -rw-r--r-- | tests/call_inout.cpp | 100 | ||||
| -rw-r--r-- | tests/call_inout.dsp | 110 | ||||
| -rw-r--r-- | tests/call_saw.cpp | 128 | ||||
| -rw-r--r-- | tests/call_saw.dsp | 110 | ||||
| -rw-r--r-- | tests/call_twostreams.cpp | 166 | ||||
| -rw-r--r-- | tests/call_twostreams.dsp | 110 | ||||
| -rw-r--r-- | tests/in_out.cpp | 109 | ||||
| -rw-r--r-- | tests/in_out.dsp | 110 | ||||
| -rw-r--r-- | tests/info.cpp | 66 | ||||
| -rw-r--r-- | tests/info.dsp | 110 | ||||
| -rw-r--r-- | tests/play_raw.cpp | 128 | ||||
| -rw-r--r-- | tests/play_raw.dsp | 110 | ||||
| -rw-r--r-- | tests/play_saw.cpp | 128 | ||||
| -rw-r--r-- | tests/play_saw.dsp | 110 | ||||
| -rw-r--r-- | tests/record_raw.cpp | 114 | ||||
| -rw-r--r-- | tests/record_raw.dsp | 110 | ||||
| -rw-r--r-- | tests/twostreams.cpp | 204 | ||||
| -rw-r--r-- | tests/twostreams.dsp | 110 |
21 files changed, 2191 insertions, 0 deletions
diff --git a/tests/Debug/.placeholder b/tests/Debug/.placeholder new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/Debug/.placeholder diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000..2f69c73 --- /dev/null +++ b/tests/Makefile @@ -0,0 +1,58 @@ + +OS = $(shell uname) + +RM = /bin/rm + +ifeq ($(OS),Linux) # These are for Linux + INSTR = info play_saw record_raw in_out play_raw twostreams call_saw call_inout call_twostreams + CC = g++ -Wall -D__LINUX_OSS_# -g -pg -O3 + LIBRARY = -lpthread +# CC = g++ -g -Wall -D__LINUX_ALSA_ # -g -pg -O3 +# LIBRARY = -lpthread -lasound + INCLUDE = -I../ +endif + +ifeq ($(OS),IRIX) # These are for SGI + INSTR = info play_saw record_raw in_out play_raw twostreams call_saw call_inout call_twostreams + CC = CC -D__IRIX_AL_ # -g -fullwarn -D__SGI_CC__ -O2 + LIBRARY = -laudio -lpthread + INCLUDE = -I../ +endif + +all: $(INSTR) + +clean : + rm $(INSTR) *~ *.raw core *.o + +cleanIns : + rm $(INSTR) + +strip : + strip $(INSTR) + +info: info.cpp ../RtAudio.cpp ../RtAudio.h + $(CC) -o info info.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE) + +play_saw: play_saw.cpp ../RtAudio.cpp ../RtAudio.h + $(CC) -o play_saw play_saw.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE) + +play_raw: play_raw.cpp ../RtAudio.cpp ../RtAudio.h + $(CC) -o play_raw play_raw.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE) + +record_raw: record_raw.cpp ../RtAudio.cpp ../RtAudio.h + $(CC) -o record_raw record_raw.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE) + +in_out: in_out.cpp ../RtAudio.cpp ../RtAudio.h + $(CC) -o in_out in_out.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE) + +twostreams: twostreams.cpp ../RtAudio.cpp ../RtAudio.h + $(CC) -o twostreams twostreams.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE) + +call_saw: call_saw.cpp ../RtAudio.cpp ../RtAudio.h + $(CC) -o call_saw call_saw.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE) + +call_inout: call_inout.cpp ../RtAudio.cpp ../RtAudio.h + $(CC) -o call_inout call_inout.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE) + +call_twostreams: call_twostreams.cpp ../RtAudio.cpp ../RtAudio.h + $(CC) -o call_twostreams call_twostreams.cpp ../RtAudio.cpp $(LIBRARY) $(INCLUDE)
\ No newline at end of file diff --git a/tests/Release/.placeholder b/tests/Release/.placeholder new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/Release/.placeholder diff --git a/tests/call_inout.cpp b/tests/call_inout.cpp new file mode 100644 index 0000000..c4ae167 --- /dev/null +++ b/tests/call_inout.cpp @@ -0,0 +1,100 @@ +/******************************************/ +/* + call_inout.c + by Gary P. Scavone, 2001 + + Records from default input and passes it + through to the output. Takes number of + channels and sample rate as input arguments. + Uses callback functionality. +*/ +/******************************************/ + +#include "RtAudio.h" +#include <iostream.h> + +/* +typedef signed long MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT24 + +typedef char MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT8 + +typedef signed short MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT16 + +typedef signed long MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT32 + +typedef float MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_FLOAT32 +*/ + +typedef double MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_FLOAT64 + +void usage(void) { + /* Error function in case of incorrect command-line + argument specifications + */ + cout << "\nuseage: call_inout N fs\n"; + cout << " where N = number of channels,\n"; + cout << " and fs = the sample rate.\n\n"; + exit(0); +} + +int inout(char *buffer, int buffer_size, void *) +{ + // Surprise!! We do nothing to pass the data through. + return 0; +} + +int main(int argc, char *argv[]) +{ + int device, stream, chans, fs; + RtAudio *audio; + char input; + + // minimal command-line checking + if (argc != 3) usage(); + + chans = (int) atoi(argv[1]); + fs = (int) atoi(argv[2]); + + // Open the realtime output device + int buffer_size = 512; + device = 0; // default device + try { + audio = new RtAudio(&stream, device, chans, device, chans, + FORMAT, fs, &buffer_size, 8); + } + catch (RtAudioError &m) { + m.printMessage(); + exit(EXIT_FAILURE); + } + + try { + audio->setStreamCallback(stream, &inout, NULL); + audio->startStream(stream); + } + catch (RtAudioError &m) { + m.printMessage(); + goto cleanup; + } + + cout << "\nRunning ... press <enter> to quit.\n"; + cin.get(input); + + try { + audio->stopStream(stream); + } + catch (RtAudioError &m) { + m.printMessage(); + } + + cleanup: + audio->closeStream(stream); + delete audio; + + return 0; +} diff --git a/tests/call_inout.dsp b/tests/call_inout.dsp new file mode 100644 index 0000000..9aac77e --- /dev/null +++ b/tests/call_inout.dsp @@ -0,0 +1,110 @@ +# Microsoft Developer Studio Project File - Name="call_inout" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=call_inout - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "call_inout.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "call_inout.mak" CFG="call_inout - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "call_inout - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "call_inout - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "call_inout - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "call_inout___Win32_Release"
+# PROP BASE Intermediate_Dir "call_inout___Win32_Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "call_inout - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "call_inout___Win32_Debug"
+# PROP BASE Intermediate_Dir "call_inout___Win32_Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "call_inout - Win32 Release"
+# Name "call_inout - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\call_inout.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\RtAudio.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=..\RtAudio.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/tests/call_saw.cpp b/tests/call_saw.cpp new file mode 100644 index 0000000..cb5509d --- /dev/null +++ b/tests/call_saw.cpp @@ -0,0 +1,128 @@ +/******************************************/ +/* + call_saw.c + by Gary P. Scavone, 2001 + + Play sawtooth waveforms of distinct frequency. + Takes number of channels and sample rate as + input arguments. Use callback functionality. +*/ +/******************************************/ + +#include "RtAudio.h" +#include <iostream.h> + +/* +typedef signed long MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT24 +#define SCALE 2147483647.0 + +typedef char MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT8 +#define SCALE 127.0 + +typedef signed short MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT16 +#define SCALE 32767.0 + +typedef signed long MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT32 +#define SCALE 2147483647.0 +*/ +typedef float MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_FLOAT32 +#define SCALE 1.0 + +/* +typedef double MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_FLOAT64 +#define SCALE 1.0 +*/ + +#define BASE_RATE 0.005 +#define TIME 1.0 + +void usage(void) { + /* Error function in case of incorrect command-line + argument specifications + */ + cout << "\nuseage: call_saw N fs\n"; + cout << " where N = number of channels,\n"; + cout << " and fs = the sample rate.\n\n"; + exit(0); +} + +int chans; + +int saw(char *buffer, int buffer_size, void *data) +{ + int i, j; + extern int chans; + MY_TYPE *my_buffer = (MY_TYPE *) buffer; + double *my_data = (double *) data; + + for (i=0; i<buffer_size; i++) { + for (j=0; j<chans; j++) { + *my_buffer++ = (MY_TYPE) (my_data[j] * SCALE); + my_data[j] += BASE_RATE * (j+1+(j*0.1)); + if (my_data[j] >= 1.0) my_data[j] -= 2.0; + } + } + + return 0; +} + +int main(int argc, char *argv[]) +{ + int device, stream, buffer_size, fs; + RtAudio *audio; + double *data; + char input; + + // minimal command-line checking + if (argc != 3) usage(); + + chans = (int) atoi(argv[1]); + fs = (int) atoi(argv[2]); + + // Open the realtime output device + buffer_size = 256; + device = 0; // default device + try { + audio = new RtAudio(&stream, device, chans, 0, 0, + FORMAT, fs, &buffer_size, 4); + } + catch (RtAudioError &m) { + m.printMessage(); + exit(EXIT_FAILURE); + } + + data = (double *) calloc(chans, sizeof(double)); + + try { + audio->setStreamCallback(stream, &saw, (void *)data); + audio->startStream(stream); + } + catch (RtAudioError &m) { + m.printMessage(); + goto cleanup; + } + + cout << "\nPlaying ... press <enter> to quit.\n"; + cin.get(input); + + // Stop the stream. + try { + audio->stopStream(stream); + } + catch (RtAudioError &m) { + m.printMessage(); + } + + cleanup: + audio->closeStream(stream); + delete audio; + if (data) free(data); + + return 0; +} diff --git a/tests/call_saw.dsp b/tests/call_saw.dsp new file mode 100644 index 0000000..344989b --- /dev/null +++ b/tests/call_saw.dsp @@ -0,0 +1,110 @@ +# Microsoft Developer Studio Project File - Name="call_saw" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=call_saw - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "call_saw.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "call_saw.mak" CFG="call_saw - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "call_saw - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "call_saw - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "call_saw - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "call_saw___Win32_Release"
+# PROP BASE Intermediate_Dir "call_saw___Win32_Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "call_saw - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "call_saw___Win32_Debug"
+# PROP BASE Intermediate_Dir "call_saw___Win32_Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "call_saw - Win32 Release"
+# Name "call_saw - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\call_saw.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\RtAudio.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=..\RtAudio.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/tests/call_twostreams.cpp b/tests/call_twostreams.cpp new file mode 100644 index 0000000..d763cc5 --- /dev/null +++ b/tests/call_twostreams.cpp @@ -0,0 +1,166 @@ +/******************************************/ +/* + twostreams.cpp + by Gary P. Scavone, 2001 + + Text executable using two streams with + callbacks. +*/ +/******************************************/ + +#include "RtAudio.h" +#include <iostream.h> + +/* +typedef signed long MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT24 +#define SCALE 2147483647.0 + +typedef char MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT8 +#define SCALE 127.0 + +typedef signed short MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT16 +#define SCALE 32767.0 + +typedef signed long MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT32 +#define SCALE 2147483647.0 + +typedef float MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_FLOAT32 +#define SCALE 1.0 +*/ + +typedef double MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_FLOAT64 +#define SCALE 1.0 + +void usage(void) { + /* Error function in case of incorrect command-line + argument specifications + */ + cout << "\nuseage: call_twostreams N fs\n"; + cout << " where N = number of channels,\n"; + cout << " and fs = the sample rate.\n\n"; + exit(0); +} + +int chans; + +int in(char *buffer, int buffer_size, void *data) +{ + extern int chans; + MY_TYPE *my_buffer = (MY_TYPE *) buffer; + MY_TYPE *my_data = (MY_TYPE *) data; + long buffer_bytes = buffer_size * chans * sizeof(MY_TYPE); + + memcpy(my_data, my_buffer, buffer_bytes); + + return 0; +} + +int out(char *buffer, int buffer_size, void *data) +{ + extern int chans; + MY_TYPE *my_buffer = (MY_TYPE *) buffer; + MY_TYPE *my_data = (MY_TYPE *) data; + long buffer_bytes = buffer_size * chans * sizeof(MY_TYPE); + + memcpy(my_buffer, my_data, buffer_bytes); + + return 0; +} + +int main(int argc, char *argv[]) +{ + int device, buffer_size, stream1, stream2, fs; + MY_TYPE *data = 0; + RtAudio *audio; + char input; + + // minimal command-line checking + if (argc != 3) usage(); + + chans = (int) atoi(argv[1]); + fs = (int) atoi(argv[2]); + + // Open the realtime output device + buffer_size = 512; + device = 0; // default device + try { + audio = new RtAudio(); + } + catch (RtAudioError &m) { + m.printMessage(); + exit(EXIT_FAILURE); + } + + try { + stream1 = audio->openStream(0, 0, device, chans, + FORMAT, fs, &buffer_size, 8); + stream2 = audio->openStream(device, chans, 0, 0, + FORMAT, fs, &buffer_size, 8); + } + catch (RtAudioError &m) { + m.printMessage(); + goto cleanup; + } + + data = (MY_TYPE *) calloc(chans*buffer_size, sizeof(MY_TYPE)); + try { + audio->setStreamCallback(stream1, &in, (void *)data); + audio->setStreamCallback(stream2, &out, (void *)data); + audio->startStream(stream1); + audio->startStream(stream2); + } + catch (RtAudioError &m) { + m.printMessage(); + goto cleanup; + } + + cout << "\nRunning two streams (quasi-duplex) ... press <enter> to quit.\n"; + cin.get(input); + + cout << "\nStopping both streams.\n"; + try { + audio->stopStream(stream1); + audio->stopStream(stream2); + } + catch (RtAudioError &m) { + m.printMessage(); + goto cleanup; + } + + cout << "\nPress <enter> to restart streams:\n"; + cin.get(input); + + try { + audio->startStream(stream1); + audio->startStream(stream2); + } + catch (RtAudioError &m) { + m.printMessage(); + goto cleanup; + } + + cout << "\nRunning two streams (quasi-duplex) ... press <enter> to quit.\n"; + cin.get(input); + + try { + audio->stopStream(stream1); + audio->stopStream(stream2); + } + catch (RtAudioError &m) { + m.printMessage(); + } + + cleanup: + audio->closeStream(stream1); + audio->closeStream(stream2); + delete audio; + if (data) free(data); + + return 0; +} diff --git a/tests/call_twostreams.dsp b/tests/call_twostreams.dsp new file mode 100644 index 0000000..b81d0d7 --- /dev/null +++ b/tests/call_twostreams.dsp @@ -0,0 +1,110 @@ +# Microsoft Developer Studio Project File - Name="call_twostreams" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=call_twostreams - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "call_twostreams.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "call_twostreams.mak" CFG="call_twostreams - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "call_twostreams - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "call_twostreams - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "call_twostreams - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "call_twostreams___Win32_Release"
+# PROP BASE Intermediate_Dir "call_twostreams___Win32_Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "call_twostreams - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "call_twostreams___Win32_Debug"
+# PROP BASE Intermediate_Dir "call_twostreams___Win32_Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "call_twostreams - Win32 Release"
+# Name "call_twostreams - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\call_twostreams.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\RtAudio.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=..\RtAudio.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/tests/in_out.cpp b/tests/in_out.cpp new file mode 100644 index 0000000..7513497 --- /dev/null +++ b/tests/in_out.cpp @@ -0,0 +1,109 @@ +/******************************************/ +/* + in_out.c + by Gary P. Scavone, 2001 + + Records from default input and passes it + through to the output. Takes number of + channels and sample rate as input arguments. + Use blocking functionality. +*/ +/******************************************/ + +#include "RtAudio.h" +#include <iostream.h> + +/* +typedef signed long MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT24 + +typedef char MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT8 + +typedef signed short MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT16 + +typedef signed long MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT32 + +typedef float MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_FLOAT32 +*/ + +typedef double MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_FLOAT64 + +#define TIME 4.0 + +void usage(void) { + /* Error function in case of incorrect command-line + argument specifications + */ + cout << "\nuseage: in_out N fs\n"; + cout << " where N = number of channels,\n"; + cout << " and fs = the sample rate.\n\n"; + exit(0); +} + +int main(int argc, char *argv[]) +{ + int chans, fs, device, buffer_size, stream; + long frames, counter = 0; + MY_TYPE *buffer; + RtAudio *audio; + + // minimal command-line checking + if (argc != 3) usage(); + + chans = (int) atoi(argv[1]); + fs = (int) atoi(argv[2]); + + // Open the realtime output device + buffer_size = 512; + device = 0; // default device + try { + audio = new RtAudio(&stream, device, chans, device, chans, + FORMAT, fs, &buffer_size, 8); + } + catch (RtAudioError &m) { + m.printMessage(); + exit(EXIT_FAILURE); + } + + frames = (long) (fs * TIME); + + try { + buffer = (MY_TYPE *) audio->getStreamBuffer(stream); + audio->startStream(stream); + } + catch (RtAudioError &m) { + m.printMessage(); + goto cleanup; + } + + cout << "\nRunning for " << TIME << " seconds ... fragment_size = " << buffer_size << endl; + while (counter < frames) { + + try { + audio->tickStream(stream); + } + catch (RtAudioError &m) { + m.printMessage(); + goto cleanup; + } + counter += buffer_size; + } + + try { + audio->stopStream(stream); + } + catch (RtAudioError &m) { + m.printMessage(); + } + + cleanup: + audio->closeStream(stream); + delete audio; + + return 0; +} diff --git a/tests/in_out.dsp b/tests/in_out.dsp new file mode 100644 index 0000000..ddfa94f --- /dev/null +++ b/tests/in_out.dsp @@ -0,0 +1,110 @@ +# Microsoft Developer Studio Project File - Name="in_out" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=in_out - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "in_out.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "in_out.mak" CFG="in_out - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "in_out - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "in_out - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "in_out - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "in_out___Win32_Release"
+# PROP BASE Intermediate_Dir "in_out___Win32_Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "in_out - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "in_out___Win32_Debug"
+# PROP BASE Intermediate_Dir "in_out___Win32_Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "in_out - Win32 Release"
+# Name "in_out - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\in_out.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\RtAudio.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=..\RtAudio.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/tests/info.cpp b/tests/info.cpp new file mode 100644 index 0000000..a4cfcf2 --- /dev/null +++ b/tests/info.cpp @@ -0,0 +1,66 @@ +/******************************************/ +/* + info.cpp + by Gary P. Scavone, 2001 + + Prints audio system/device info. +*/ +/******************************************/ + +#include "RtAudio.h" +#include <iostream.h> + +int main(int argc, char *argv[]) +{ + RtAudio *audio; + RtAudio::RTAUDIO_DEVICE my_info; + try { + audio = new RtAudio(); + } + catch (RtAudioError &m) { + m.printMessage(); + exit(EXIT_FAILURE); + } + + int devices = audio->getDeviceCount(); + cout << "\nFound " << devices << " devices ...\n"; + + for (int i=0; i<devices; i++) { + try { + audio->getDeviceInfo(i, &my_info); + } + catch (RtAudioError &m) { + m.printMessage(); + break; + } + + cout << "\nname = " << my_info.name << '\n'; + if (my_info.probed == true) + cout << "probe successful\n"; + else + cout << "probe unsuccessful\n"; + cout << "maxOutputChans = " << my_info.maxOutputChannels << '\n'; + cout << "minOutputChans = " << my_info.minOutputChannels << '\n'; + cout << "maxInputChans = " << my_info.maxInputChannels << '\n'; + cout << "minInputChans = " << my_info.minInputChannels << '\n'; + cout << "maxDuplexChans = " << my_info.maxDuplexChannels << '\n'; + cout << "minDuplexChans = " << my_info.minDuplexChannels << '\n'; + if (my_info.hasDuplexSupport) + cout << "duplex support = true\n"; + else + cout << "duplex support = false\n"; + cout << "format = " << my_info.nativeFormats << '\n'; + if (my_info.nSampleRates == -1) + cout << "min_srate = " << my_info.sampleRates[0] << ", max_srate = " << my_info.sampleRates[1] << '\n'; + else { + cout << "sample rates = "; + for (int j=0; j<my_info.nSampleRates; j++) + cout << my_info.sampleRates[j] << " "; + cout << endl; + } + } + cout << endl; + + delete audio; + return 0; +} diff --git a/tests/info.dsp b/tests/info.dsp new file mode 100644 index 0000000..067803a --- /dev/null +++ b/tests/info.dsp @@ -0,0 +1,110 @@ +# Microsoft Developer Studio Project File - Name="info" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=info - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "info.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "info.mak" CFG="info - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "info - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "info - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "info - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "info - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "info___Win32_Debug"
+# PROP BASE Intermediate_Dir "info___Win32_Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "info - Win32 Release"
+# Name "info - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\info.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\RtAudio.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=..\RtAudio.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/tests/play_raw.cpp b/tests/play_raw.cpp new file mode 100644 index 0000000..827f533 --- /dev/null +++ b/tests/play_raw.cpp @@ -0,0 +1,128 @@ +/******************************************/ +/* + play_raw.c + by Gary P. Scavone, 2001 + + Play a raw file. It is necessary that the + file be of the same format as defined below. + Uses blocking functionality. +*/ +/******************************************/ + +#include "RtAudio.h" +#include <iostream.h> +#include <stdio.h> + +/* +typedef char MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT8 +#define SCALE 127.0 + +typedef signed short MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT16 +#define SCALE 32767.0 + +typedef signed long MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT24 +#define SCALE 8388607.0 + +typedef signed long MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT32 +#define SCALE 2147483647.0 + +typedef float MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_FLOAT32 +#define SCALE 1.0; +*/ + +typedef double MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_FLOAT64 +#define SCALE 1.0; + +void usage(void) { + /* Error function in case of incorrect command-line + argument specifications + */ + cout << "\nuseage: play_raw N fs file\n"; + cout << " where N = number of channels,\n"; + cout << " fs = the sample rate, \n"; + cout << " and file = the raw file to play.\n\n"; + exit(0); +} + +int main(int argc, char *argv[]) +{ + int chans, fs, device, buffer_size, count, stream; + long counter = 0; + MY_TYPE *buffer; + char *file; + FILE *fd; + RtAudio *audio; + + // minimal command-line checking + if (argc != 4) usage(); + + chans = (int) atoi(argv[1]); + fs = (int) atoi(argv[2]); + file = argv[3]; + + fd = fopen(file,"rb"); + if (!fd) { + cout << "can't find file!\n"; + exit(0); + } + + // Open the realtime output device + buffer_size = 256; + device = 0; // default device + try { + audio = new RtAudio(&stream, device, chans, 0, 0, + FORMAT, fs, &buffer_size, 2); + } + catch (RtAudioError &m) { + m.printMessage(); + fclose(fd); + exit(EXIT_FAILURE); + } + + try { + buffer = (MY_TYPE *) audio->getStreamBuffer(stream); + audio->startStream(stream); + } + catch (RtAudioError &m) { + m.printMessage(); + goto cleanup; + } + + while (1) { + count = fread(buffer, chans * sizeof(MY_TYPE), buffer_size, fd); + + if (count == buffer_size) { + try { + audio->tickStream(stream); + } + catch (RtAudioError &m) { + m.printMessage(); + goto cleanup; + } + } + else + break; + + counter += buffer_size; + } + + try { + audio->stopStream(stream); + } + catch (RtAudioError &m) { + m.printMessage(); + } + + cleanup: + audio->closeStream(stream); + delete audio; + fclose(fd); + + return 0; +} diff --git a/tests/play_raw.dsp b/tests/play_raw.dsp new file mode 100644 index 0000000..dab880a --- /dev/null +++ b/tests/play_raw.dsp @@ -0,0 +1,110 @@ +# Microsoft Developer Studio Project File - Name="play_raw" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=play_raw - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "play_raw.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "play_raw.mak" CFG="play_raw - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "play_raw - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "play_raw - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "play_raw - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "play_raw - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "play_raw___Win32_Debug"
+# PROP BASE Intermediate_Dir "play_raw___Win32_Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "play_raw - Win32 Release"
+# Name "play_raw - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\play_raw.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\RtAudio.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=..\RtAudio.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/tests/play_saw.cpp b/tests/play_saw.cpp new file mode 100644 index 0000000..bd865aa --- /dev/null +++ b/tests/play_saw.cpp @@ -0,0 +1,128 @@ +/******************************************/ +/* + play_saw.c + by Gary P. Scavone, 2001 + + Play sawtooth waveforms of distinct frequency. + Takes number of channels and sample rate as + input arguments. Uses blocking functionality. +*/ +/******************************************/ + +#include "RtAudio.h" +#include <iostream.h> + +/* +typedef signed long MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT24 +#define SCALE 2147483647.0 + +typedef char MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT8 +#define SCALE 127.0 + +typedef signed short MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT16 +#define SCALE 32767.0 + +typedef signed long MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT32 +#define SCALE 2147483647.0 +*/ +typedef float MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_FLOAT32 +#define SCALE 1.0 + +/* +typedef double MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_FLOAT64 +#define SCALE 1.0 +*/ + +#define BASE_RATE 0.005 +#define TIME 1.0 + +void usage(void) { + /* Error function in case of incorrect command-line + argument specifications + */ + cout << "\nuseage: play_saw N fs\n"; + cout << " where N = number of channels,\n"; + cout << " and fs = the sample rate.\n\n"; + exit(0); +} + +int main(int argc, char *argv[]) +{ + int chans, fs, device, buffer_size, stream; + long frames, counter = 0, i, j; + MY_TYPE *buffer; + RtAudio *audio; + double *data; + + // minimal command-line checking + if (argc != 3) usage(); + + chans = (int) atoi(argv[1]); + fs = (int) atoi(argv[2]); + + // Open the realtime output device + buffer_size = 256; + device = 0; // default device + try { + audio = new RtAudio(&stream, device, chans, 0, 0, + FORMAT, fs, &buffer_size, 4); + } + catch (RtAudioError &m) { + m.printMessage(); + exit(EXIT_FAILURE); + } + + frames = (long) (fs * TIME); + data = (double *) calloc(chans, sizeof(double)); + + try { + buffer = (MY_TYPE *) audio->getStreamBuffer(stream); + audio->startStream(stream); + } + catch (RtAudioError &m) { + m.printMessage(); + goto cleanup; + } + + cout << "\nPlaying for " << TIME << " seconds." << endl; + while (counter < frames) { + for (i=0; i<buffer_size; i++) { + for (j=0; j<chans; j++) { + buffer[i*chans+j] = (MY_TYPE) (data[j] * SCALE); + data[j] += BASE_RATE * (j+1+(j*0.1)); + if (data[j] >= 1.0) data[j] -= 2.0; + } + } + + try { + //cout << "frames until no block = " << audio->streamWillBlock(stream) << endl; + audio->tickStream(stream); + } + catch (RtAudioError &m) { + m.printMessage(); + goto cleanup; + } + + counter += buffer_size; + } + + try { + audio->stopStream(stream); + } + catch (RtAudioError &m) { + m.printMessage(); + } + + cleanup: + audio->closeStream(stream); + delete audio; + if (data) free(data); + + return 0; +} diff --git a/tests/play_saw.dsp b/tests/play_saw.dsp new file mode 100644 index 0000000..b6f9313 --- /dev/null +++ b/tests/play_saw.dsp @@ -0,0 +1,110 @@ +# Microsoft Developer Studio Project File - Name="play_saw" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=play_saw - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "play_saw.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "play_saw.mak" CFG="play_saw - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "play_saw - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "play_saw - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "play_saw - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "play_saw - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "play_saw___Win32_Debug"
+# PROP BASE Intermediate_Dir "play_saw___Win32_Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "play_saw - Win32 Release"
+# Name "play_saw - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\play_saw.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\RtAudio.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=..\RtAudio.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/tests/record_raw.cpp b/tests/record_raw.cpp new file mode 100644 index 0000000..739566e --- /dev/null +++ b/tests/record_raw.cpp @@ -0,0 +1,114 @@ +/******************************************/ +/* + record_raw.c + by Gary P. Scavone, 2001 + + Records from default input. Takes + number of channels and sample rate + as input arguments. Uses blocking calls. +*/ +/******************************************/ + +#include "RtAudio.h" +#include <stdio.h> +#include <iostream.h> + +/* +typedef char MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT8 + +typedef signed short MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT16 + +typedef signed long MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT24 + +typedef signed long MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT32 + +typedef float MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_FLOAT32 +*/ + +typedef double MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_FLOAT64 + +#define TIME 2.0 + +void usage(void) { + /* Error function in case of incorrect command-line + argument specifications + */ + cout << "\nuseage: record_raw N fs\n"; + cout << " where N = number of channels,\n"; + cout << " and fs = the sample rate.\n\n"; + exit(0); +} + +int main(int argc, char *argv[]) +{ + int chans, fs, device, buffer_size, stream; + long frames, counter = 0; + MY_TYPE *buffer; + FILE *fd; + RtAudio *audio; + + // minimal command-line checking + if (argc != 3) usage(); + + chans = (int) atoi(argv[1]); + fs = (int) atoi(argv[2]); + + // Open the realtime output device + buffer_size = 512; + device = 0; // default device + try { + audio = new RtAudio(&stream, 0, 0, device, chans, + FORMAT, fs, &buffer_size, 8); + } + catch (RtAudioError &m) { + m.printMessage(); + exit(EXIT_FAILURE); + } + + fd = fopen("test.raw","wb"); + frames = (long) (fs * TIME); + + try { + buffer = (MY_TYPE *) audio->getStreamBuffer(stream); + audio->startStream(stream); + } + catch (RtAudioError &m) { + m.printMessage(); + goto cleanup; + } + + cout << "\nRecording for " << TIME << " seconds ... writing file test.raw." << endl; + while (counter < frames) { + + try { + audio->tickStream(stream); + } + catch (RtAudioError &m) { + m.printMessage(); + goto cleanup; + } + + fwrite(buffer, sizeof(MY_TYPE), chans * buffer_size, fd); + counter += buffer_size; + } + + try { + audio->stopStream(stream); + } + catch (RtAudioError &m) { + m.printMessage(); + } + + cleanup: + audio->closeStream(stream); + delete audio; + fclose(fd); + + return 0; +} diff --git a/tests/record_raw.dsp b/tests/record_raw.dsp new file mode 100644 index 0000000..4b1f1e4 --- /dev/null +++ b/tests/record_raw.dsp @@ -0,0 +1,110 @@ +# Microsoft Developer Studio Project File - Name="record_raw" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=record_raw - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "record_raw.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "record_raw.mak" CFG="record_raw - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "record_raw - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "record_raw - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "record_raw - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "record_raw - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "record_raw___Win32_Debug"
+# PROP BASE Intermediate_Dir "record_raw___Win32_Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "record_raw - Win32 Release"
+# Name "record_raw - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\record_raw.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=..\RtAudio.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=..\RtAudio.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/tests/twostreams.cpp b/tests/twostreams.cpp new file mode 100644 index 0000000..1f7a05d --- /dev/null +++ b/tests/twostreams.cpp @@ -0,0 +1,204 @@ +/******************************************/ +/* + twostreams.cpp + by Gary P. Scavone, 2001 + + Text executable for audio playback, + recording, duplex operation, stopping, + starting, and aborting operations. + Takes number of channels and sample + rate as input arguments. Runs input + and output through two separate streams. + Uses blocking functionality. +*/ +/******************************************/ + +#include "RtAudio.h" +#include <iostream.h> +#include <stdio.h> + +/* +typedef signed long MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT24 +#define SCALE 2147483647.0 + +typedef char MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT8 +#define SCALE 127.0 + +typedef signed short MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT16 +#define SCALE 32767.0 + +typedef signed long MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_SINT32 +#define SCALE 2147483647.0 + +typedef float MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_FLOAT32 +#define SCALE 1.0 +*/ + +typedef double MY_TYPE; +#define FORMAT RtAudio::RTAUDIO_FLOAT64 +#define SCALE 1.0 + +#define BASE_RATE 0.005 +#define TIME 2.0 + +void usage(void) { + /* Error function in case of incorrect command-line + argument specifications + */ + cout << "\nuseage: twostreams N fs\n"; + cout << " where N = number of channels,\n"; + cout << " and fs = the sample rate.\n\n"; + exit(0); +} + +int main(int argc, char *argv[]) +{ + int chans, fs, device, buffer_size, stream1, stream2; + long frames, counter = 0, i, j; + MY_TYPE *buffer1, *buffer2; + RtAudio *audio; + FILE *fd; + double *data; + + // minimal command-line checking + if (argc != 3) usage(); + + chans = (int) atoi(argv[1]); + fs = (int) atoi(argv[2]); + + // Open the realtime output device + buffer_size = 512; + device = 0; // default device + try { + audio = new RtAudio(); + } + catch (RtAudioError &m) { + m.printMessage(); + exit(EXIT_FAILURE); + } + + try { + stream1 = audio->openStream(device, chans, 0, 0, + FORMAT, fs, &buffer_size, 8); + stream2 = audio->openStream(0, 0, device, chans, + FORMAT, fs, &buffer_size, 8); + buffer1 = (MY_TYPE *) audio->getStreamBuffer(stream1); + buffer2 = (MY_TYPE *) audio->getStreamBuffer(stream2); + } + catch (RtAudioError &m) { + m.printMessage(); + goto cleanup; + } + + frames = (long) (fs * TIME); + data = (double *) calloc(chans, sizeof(double)); + + try { + audio->startStream(stream1); + } + catch (RtAudioError &m) { + m.printMessage(); + goto cleanup; + } + + cout << "\nStarting sawtooth playback stream for " << TIME << " seconds." << endl; + while (counter < frames) { + for (i=0; i<buffer_size; i++) { + for (j=0; j<chans; j++) { + buffer1[i*chans+j] = (MY_TYPE) (data[j] * SCALE); + data[j] += BASE_RATE * (j+1+(j*0.1)); + if (data[j] >= 1.0) data[j] -= 2.0; + } + } + + try { + audio->tickStream(stream1); + } + catch (RtAudioError &m) { + m.printMessage(); + goto cleanup; + } + + counter += buffer_size; + } + + cout << "\nStopping playback stream." << endl; + try { + audio->stopStream(stream1); + audio->startStream(stream2); + } + catch (RtAudioError &m) { + m.printMessage(); + goto cleanup; + } + + fd = fopen("test.raw","wb"); + + counter = 0; + cout << "\nStarting recording stream for " << TIME << " seconds." << endl; + while (counter < frames) { + + try { + audio->tickStream(stream2); + } + catch (RtAudioError &m) { + m.printMessage(); + goto cleanup; + } + + fwrite(buffer2, sizeof(MY_TYPE), chans * buffer_size, fd); + counter += buffer_size; + } + + fclose(fd); + cout << "\nAborting recording." << endl; + + try { + audio->abortStream(stream2); + audio->startStream(stream1); + audio->startStream(stream2); + } + catch (RtAudioError &m) { + m.printMessage(); + goto cleanup; + } + + counter = 0; + cout << "\nStarting playback and record streams (quasi-duplex) for " << TIME << " seconds." << endl; + while (counter < frames) { + + try { + audio->tickStream(stream2); + memcpy(buffer1, buffer2, sizeof(MY_TYPE) * chans * buffer_size); + audio->tickStream(stream1); + } + catch (RtAudioError &m) { + m.printMessage(); + goto cleanup; + } + + counter += buffer_size; + } + + cout << "\nStopping both streams." << endl; + try { + audio->stopStream(stream1); + audio->stopStream(stream2); + } + catch (RtAudioError &m) { + m.printMessage(); + } + + cleanup: + audio->closeStream(stream1); + audio->closeStream(stream2); + delete audio; + if (data) free(data); + + return 0; +} diff --git a/tests/twostreams.dsp b/tests/twostreams.dsp new file mode 100644 index 0000000..0e69ae2 --- /dev/null +++ b/tests/twostreams.dsp @@ -0,0 +1,110 @@ +# Microsoft Developer Studio Project File - Name="twostreams" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Console Application" 0x0103
+
+CFG=twostreams - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "twostreams.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "twostreams.mak" CFG="twostreams - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "twostreams - Win32 Release" (based on "Win32 (x86) Console Application")
+!MESSAGE "twostreams - Win32 Debug" (based on "Win32 (x86) Console Application")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "twostreams - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "twostreams___Win32_Release"
+# PROP BASE Intermediate_Dir "twostreams___Win32_Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O2 /I "../" /D "NDEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /machine:I386
+
+!ELSEIF "$(CFG)" == "twostreams - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "twostreams___Win32_Debug"
+# PROP BASE Intermediate_Dir "twostreams___Win32_Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir ""
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /I "../" /D "_DEBUG" /D "WIN32" /D "_CONSOLE" /D "_MBCS" /D "__WINDOWS_DS_" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib dsound.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "twostreams - Win32 Release"
+# Name "twostreams - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=..\RtAudio.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\twostreams.cpp
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=..\RtAudio.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
|
