WASAPI : Fixed issue where latency was introduced on stream stop / start
[rtaudio.git] / tests / playraw.cpp
index 3b70cdb869870787cb1269ea3f7240b78485e06c..f11f83c28f4b90738ca72cba6773dd30f52234f6 100644 (file)
 
 #include "RtAudio.h"
 #include <iostream>
+#include <cstdlib>
+#include <cstring>
+#include <stdio.h>
 
 /*
 typedef char  MY_TYPE;
 #define FORMAT RTAUDIO_SINT8
 #define SCALE  127.0
+*/
 
 typedef signed short  MY_TYPE;
 #define FORMAT RTAUDIO_SINT16
 #define SCALE  32767.0
 
-typedef signed long  MY_TYPE;
+/*
+typedef S24 MY_TYPE;
 #define FORMAT RTAUDIO_SINT24
 #define SCALE  8388607.0
 
-typedef signed long  MY_TYPE;
+typedef signed int  MY_TYPE;
 #define FORMAT RTAUDIO_SINT32
 #define SCALE  2147483647.0
-*/
 
 typedef float  MY_TYPE;
 #define FORMAT RTAUDIO_FLOAT32
 #define SCALE  1.0;
 
-/*
 typedef double  MY_TYPE;
 #define FORMAT RTAUDIO_FLOAT64
 #define SCALE  1.0;
 */
 
 // Platform-dependent sleep routines.
-#if defined( __WINDOWS_ASIO__ ) || defined( __WINDOWS_DS__ )
+#if defined( __WINDOWS_ASIO__ ) || defined( __WINDOWS_DS__ ) || defined( __WINDOWS_WASAPI__ )
   #include <windows.h>
   #define SLEEP( milliseconds ) Sleep( (DWORD) milliseconds ) 
 #else // Unix variants
@@ -58,7 +61,7 @@ void usage( void ) {
   std::cout << "    file = the raw file to play,\n";
   std::cout << "    device = optional device to use (default = 0),\n";
   std::cout << "    and channelOffset = an optional channel offset on the device (default = 0).\n\n";
-  exit(0);
+  exit( 0 );
 }
 
 struct OutputData {
@@ -67,8 +70,8 @@ struct OutputData {
 };
 
 // Interleaved buffers
-int output( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
-            double streamTime, RtAudioStreamStatus status, void *data )
+int output( void *outputBuffer, void * /*inputBuffer*/, unsigned int nBufferFrames,
+            double /*streamTime*/, RtAudioStreamStatus /*status*/, void *data )
 {
   OutputData *oData = (OutputData*) data;
 
@@ -106,13 +109,13 @@ int main( int argc, char *argv[] )
   if ( argc > 4 )
     device = (unsigned int) atoi( argv[4] );
   if ( argc > 5 )
-    offset = (unsigned int) atoi(argv[5]);
+    offset = (unsigned int) atoi( argv[5] );
 
   OutputData data;
   data.fd = fopen( file, "rb" );
   if ( !data.fd ) {
     std::cout << "Unable to find or open file!\n";
-    exit( 0 );
+    exit( 1 );
   }
 
   // Set our stream parameters for output only.
@@ -122,12 +125,15 @@ int main( int argc, char *argv[] )
   oParams.nChannels = channels;
   oParams.firstChannel = offset;
 
+  if ( device == 0 )
+    oParams.deviceId = dac.getDefaultOutputDevice();
+
   data.channels = channels;
   try {
     dac.openStream( &oParams, NULL, FORMAT, fs, &bufferFrames, &output, (void *)&data );
     dac.startStream();
   }
-  catch ( RtError& e ) {
+  catch ( RtAudioError& e ) {
     std::cout << '\n' << e.getMessage() << '\n' << std::endl;
     goto cleanup;
   }