diff --git a/Audio/Chain/OutputNode.m b/Audio/Chain/OutputNode.m index 577a3398d..9f3903577 100644 --- a/Audio/Chain/OutputNode.m +++ b/Audio/Chain/OutputNode.m @@ -176,4 +176,5 @@ { [output sustainHDCD]; } + @end diff --git a/Audio/Output/OutputCoreAudio.h b/Audio/Output/OutputCoreAudio.h index 943e88c8d..0942d41d2 100644 --- a/Audio/Output/OutputCoreAudio.h +++ b/Audio/Output/OutputCoreAudio.h @@ -38,6 +38,7 @@ BOOL stopped; BOOL started; BOOL paused; + BOOL stopNext; BOOL eqEnabled; diff --git a/Audio/Output/OutputCoreAudio.m b/Audio/Output/OutputCoreAudio.m index a8f0fe533..ae9627ef1 100644 --- a/Audio/Output/OutputCoreAudio.m +++ b/Audio/Output/OutputCoreAudio.m @@ -160,6 +160,7 @@ static OSStatus renderCallback( void *inRefCon, AudioUnitRenderActionFlags *ioAc listenerapplied = NO; running = NO; started = NO; + stopNext = NO; atomic_init(&bytesRendered, 0); atomic_init(&bytesHdcdSustained, 0); @@ -210,6 +211,7 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const { running = YES; started = NO; + stopNext = NO; size_t eventCount = 0; atomic_store(&bytesRendered, 0); NSMutableArray *delayedEvents = [[NSMutableArray alloc] init]; @@ -277,6 +279,10 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const else bytesBuffered -= CHUNK_SIZE; } + else { + stopNext = YES; + break; + } [delayedEvents addObject:[NSNumber numberWithLong:bytesBuffered]]; delayedEventsPopped = NO; if (!started) { @@ -554,6 +560,7 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const stopping = NO; stopped = NO; paused = NO; + stopNext = NO; outputDeviceID = -1; AudioComponentDescription desc; @@ -722,6 +729,14 @@ default_device_changed(AudioObjectID inObjectID, UInt32 inNumberAddresses, const - (void)stop { + if (stopNext && started && !paused) { + while (![[outputController buffer] isEmpty]) + usleep(500); + } + if (stopNext) { + stopNext = NO; + [self signalEndOfStream]; + } stopInvoked = YES; stopping = YES; paused = NO;