X-Git-Url: https://git.carlh.net/gitweb/?a=blobdiff_plain;f=tests%2Fplaysaw.cpp;h=1f7bd52c5fe389528796cf609a37893db220da9e;hb=refs%2Fheads%2Ffix-wasapi-resampler-crash;hp=2117b5453d7a45ca35a179990e146310221a1db9;hpb=5d8514d7eb3918a947ec97b45f4105630c64468d;p=rtaudio.git diff --git a/tests/playsaw.cpp b/tests/playsaw.cpp index 2117b54..1f7bd52 100644 --- a/tests/playsaw.cpp +++ b/tests/playsaw.cpp @@ -13,35 +13,35 @@ #include /* -typedef signed long MY_TYPE; -#define FORMAT RTAUDIO_SINT24 -#define SCALE 2147483647.0 - -typedef char MY_TYPE; +typedef char MY_TYPE; #define FORMAT RTAUDIO_SINT8 #define SCALE 127.0 */ -typedef signed short MY_TYPE; +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; #define FORMAT RTAUDIO_SINT32 #define SCALE 2147483647.0 -typedef float MY_TYPE; +typedef float MY_TYPE; #define FORMAT RTAUDIO_FLOAT32 #define SCALE 1.0 -typedef double MY_TYPE; +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( WIN32 ) #include #define SLEEP( milliseconds ) Sleep( (DWORD) milliseconds ) #else // Unix variants @@ -64,6 +64,17 @@ void usage( void ) { exit( 0 ); } +void errorCallback( RtAudioError::Type type, const std::string &errorText ) +{ + // This example error handling function does exactly the same thing + // as the embedded RtAudio::error() function. + std::cout << "in errorCallback" << std::endl; + if ( type == RtAudioError::WARNING ) + std::cerr << '\n' << errorText << "\n\n"; + else if ( type != RtAudioError::WARNING ) + throw( RtAudioError( errorText, type ) ); +} + unsigned int channels; RtAudio::StreamOptions options; unsigned int frameCounter = 0; @@ -88,7 +99,7 @@ int saw( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames, for ( i=0; i= 1.0 ) lastValues[j] -= 2.0; } @@ -101,8 +112,8 @@ int saw( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames, #else // Use non-interleaved buffers -int saw( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames, - double streamTime, RtAudioStreamStatus status, void *data ) +int saw( void *outputBuffer, void * /*inputBuffer*/, unsigned int nBufferFrames, + double /*streamTime*/, RtAudioStreamStatus status, void *data ) { unsigned int i, j; extern unsigned int channels; @@ -116,7 +127,7 @@ int saw( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames, for ( j=0; j= 1.0 ) lastValues[j] -= 2.0; } @@ -163,16 +174,19 @@ int main( int argc, char *argv[] ) oParams.nChannels = channels; oParams.firstChannel = offset; - options.flags |= RTAUDIO_HOG_DEVICE; + if ( device == 0 ) + oParams.deviceId = dac.getDefaultOutputDevice(); + + options.flags = RTAUDIO_HOG_DEVICE; options.flags |= RTAUDIO_SCHEDULE_REALTIME; #if !defined( USE_INTERLEAVED ) options.flags |= RTAUDIO_NONINTERLEAVED; #endif try { - dac.openStream( &oParams, NULL, FORMAT, fs, &bufferFrames, &saw, (void *)data, &options ); + dac.openStream( &oParams, NULL, FORMAT, fs, &bufferFrames, &saw, (void *)data, &options, &errorCallback ); dac.startStream(); } - catch ( RtError& e ) { + catch ( RtAudioError& e ) { e.printMessage(); goto cleanup; } @@ -190,7 +204,7 @@ int main( int argc, char *argv[] ) // Stop the stream dac.stopStream(); } - catch ( RtError& e ) { + catch ( RtAudioError& e ) { e.printMessage(); } }