// Setup a listener to detect a possible device disconnect.
property.mSelector = kAudioDevicePropertyDeviceIsAlive;
- property.mScope = kAudioObjectPropertyScopeGlobal;
result = AudioObjectAddPropertyListener( id , &property, disconnectListener, (void *) &stream_.callbackInfo );
if ( result != noErr ) {
+ AudioObjectRemovePropertyListener( id, &property, xrunListener, (void *) handle );
errorStream_ << "RtApiCore::probeDeviceOpen: system error setting disconnect listener for device (" << device << ").";
errorText_ = errorStream_.str();
goto error;
kAudioObjectPropertyElementMaster };
property.mSelector = kAudioDeviceProcessorOverload;
- property.mScope = kAudioObjectPropertyScopeGlobal;
if (AudioObjectRemovePropertyListener( handle->id[0], &property, xrunListener, (void *) handle ) != noErr) {
- errorText_ = "RtApiCore::closeStream(): error removing property listener!";
+ errorText_ = "RtApiCore::closeStream(): error removing xrun property listener!";
+ error( RtAudioError::WARNING );
+ }
+ property.mSelector = kAudioDevicePropertyDeviceIsAlive;
+ if (AudioObjectRemovePropertyListener( handle->id[0], &property, disconnectListener, (void *) &stream_.callbackInfo ) != noErr) {
+ errorText_ = "RtApiCore::closeStream(): error removing disconnect property listener!";
error( RtAudioError::WARNING );
}
}
kAudioObjectPropertyElementMaster };
property.mSelector = kAudioDeviceProcessorOverload;
- property.mScope = kAudioObjectPropertyScopeGlobal;
if (AudioObjectRemovePropertyListener( handle->id[1], &property, xrunListener, (void *) handle ) != noErr) {
- errorText_ = "RtApiCore::closeStream(): error removing property listener!";
+ errorText_ = "RtApiCore::closeStream(): error removing xrun property listener!";
+ error( RtAudioError::WARNING );
+ }
+ property.mSelector = kAudioDevicePropertyDeviceIsAlive;
+ if (AudioObjectRemovePropertyListener( handle->id[1], &property, disconnectListener, (void *) &stream_.callbackInfo ) != noErr) {
+ errorText_ = "RtApiCore::closeStream(): error removing disconnect property listener!";
error( RtAudioError::WARNING );
}
}
{
// 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 ) );
+ std::cerr << "\nerrorCallback: " << errorText << "\n\n";
}
unsigned int channels;
unsigned int frameCounter = 0;
bool checkCount = false;
unsigned int nFrames = 0;
-const unsigned int callbackReturnValue = 2;
+const unsigned int callbackReturnValue = 1; // 1 = stop and drain, 2 = abort
double streamTimePrintIncrement = 1.0; // seconds
double streamTimePrintTime = 1.0; // seconds
-//#define USE_INTERLEAVED
+#define USE_INTERLEAVED
#if defined( USE_INTERLEAVED )
// Interleaved buffers
-int saw( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
+int saw( void *outputBuffer, void * /*inputBuffer*/, unsigned int nBufferFrames,
double streamTime, RtAudioStreamStatus status, void *data )
{
unsigned int i, j;
#if !defined( USE_INTERLEAVED )
options.flags |= RTAUDIO_NONINTERLEAVED;
#endif
- // try {
- dac.openStream( &oParams, NULL, FORMAT, fs, &bufferFrames, &saw, (void *)data, &options, &errorCallback );
- if ( dac.isStreamOpen() == false ) goto cleanup;
- dac.startStream();
- // }
- // catch ( RtAudioError& e ) {
- // e.printMessage();
- //goto cleanup;
- // }
+
+ dac.openStream( &oParams, NULL, FORMAT, fs, &bufferFrames, &saw, (void *)data, &options, &errorCallback );
+ if ( dac.isStreamOpen() == false ) goto cleanup;
+
+ // Stream is open ... now start it.
+ dac.startStream();
if ( checkCount ) {
while ( dac.isStreamRunning() == true ) SLEEP( 100 );
std::cout << "\nPlaying ... press <enter> to quit (buffer size = " << bufferFrames << ").\n";
std::cin.get( input );
- //try {
- // Stop the stream
- dac.stopStream();
- //dac.abortStream();
- }
- /*
- catch ( RtAudioError& e ) {
- e.printMessage();
- }
+ // Block released ... stop the stream
+ dac.stopStream(); // or could call dac.abortStream();
}
- */
cleanup:
if ( dac.isStreamOpen() ) dac.closeStream();
RtAudio::StreamOptions options;
options.flags = RTAUDIO_HOG_DEVICE;
- try {
+ //try {
dac.openStream( &oParams, NULL, RTAUDIO_FLOAT64, fs, &bufferFrames, &sawi, (void *)data, &options );
std::cout << "\nStream latency = " << dac.getStreamLatency() << std::endl;
+ if ( !dac.isStreamOpen() ) goto cleanup;
// Start the stream
dac.startStream();
std::cout << "\nPlaying ... press <enter> to stop.\n";
std::cout << "Playing again ... press <enter> to close the stream.\n";
std::cin.get( input );
+ /*
}
catch ( RtAudioError& e ) {
e.printMessage();
goto cleanup;
}
+ */
if ( dac.isStreamOpen() ) dac.closeStream();
try {
dac.openStream( &oParams, NULL, RTAUDIO_FLOAT64, fs, &bufferFrames, &sawni, (void *)data, &options );
+ if ( !dac.isStreamOpen() ) goto cleanup;
+
std::cout << "Press <enter> to start non-interleaved playback.\n";
std::cin.get( input );
options.flags = RTAUDIO_NONINTERLEAVED;
try {
dac.openStream( &oParams, &iParams, RTAUDIO_SINT32, fs, &bufferFrames, &inout, (void *)&bufferBytes, &options );
-
+ if ( !dac.isStreamOpen() ) goto cleanup;
+
bufferBytes = bufferFrames * channels * 4;
std::cout << "Press <enter> to start duplex operation.\n";