Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Core Audio output: Hopefully stop buffer looping on device stop
  • Loading branch information
kode54 committed Jan 22, 2022
1 parent 6011982 commit 502e52d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions Audio/Chain/OutputNode.m
Expand Up @@ -176,4 +176,5 @@ - (void)sustainHDCD
{
[output sustainHDCD];
}

@end
1 change: 1 addition & 0 deletions Audio/Output/OutputCoreAudio.h
Expand Up @@ -38,6 +38,7 @@
BOOL stopped;
BOOL started;
BOOL paused;
BOOL stopNext;

BOOL eqEnabled;

Expand Down
15 changes: 15 additions & 0 deletions Audio/Output/OutputCoreAudio.m
Expand Up @@ -160,6 +160,7 @@ - (id)initWithController:(OutputNode *)c
listenerapplied = NO;
running = NO;
started = NO;
stopNext = NO;

atomic_init(&bytesRendered, 0);
atomic_init(&bytesHdcdSustained, 0);
Expand Down Expand Up @@ -210,6 +211,7 @@ - (void)threadEntry:(id)arg
{
running = YES;
started = NO;
stopNext = NO;
size_t eventCount = 0;
atomic_store(&bytesRendered, 0);
NSMutableArray *delayedEvents = [[NSMutableArray alloc] init];
Expand Down Expand Up @@ -277,6 +279,10 @@ - (void)threadEntry:(id)arg
else
bytesBuffered -= CHUNK_SIZE;
}
else {
stopNext = YES;
break;
}
[delayedEvents addObject:[NSNumber numberWithLong:bytesBuffered]];
delayedEventsPopped = NO;
if (!started) {
Expand Down Expand Up @@ -554,6 +560,7 @@ - (BOOL)setup
stopping = NO;
stopped = NO;
paused = NO;
stopNext = NO;
outputDeviceID = -1;

AudioComponentDescription desc;
Expand Down Expand Up @@ -722,6 +729,14 @@ - (void)start

- (void)stop
{
if (stopNext && started && !paused) {
while (![[outputController buffer] isEmpty])
usleep(500);
}
if (stopNext) {
stopNext = NO;
[self signalEndOfStream];
}
stopInvoked = YES;
stopping = YES;
paused = NO;
Expand Down

0 comments on commit 502e52d

Please sign in to comment.