Skip to content

Commit

Permalink
Stop visualizer feed for stopped playback
Browse files Browse the repository at this point in the history
A stopped instance of OutputCoreAudio should not continue to feed the
visualization system with stale audio, potentially while another instance
is already starting up and feeding its own audio output.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
  • Loading branch information
kode54 committed Oct 3, 2023
1 parent 73738aa commit 791c9f9
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Audio/Output/OutputCoreAudio.m
Expand Up @@ -160,6 +160,9 @@ - (int)renderInput:(int)amountToRead toBuffer:(float *)buffer {
if(fabs(realStreamFormat.mSampleRate - lastVisRate) > 1e-5) {
if(rsvis) {
for(;;) {
if(stopping) {
break;
}
int samplesFlushed;
samplesFlushed = (int)rsstate_flush(rsvis, &visTemp[0], 8192);
if(samplesFlushed > 1) {
Expand All @@ -181,6 +184,9 @@ - (int)renderInput:(int)amountToRead toBuffer:(float *)buffer {
size_t inDone = 0;
size_t visFrameCount = frameCount;
do {
if(stopping) {
break;
}
int visTodo = (int)MIN(visFrameCount, visResamplerRemain + visFrameCount - 8192);
if(visTodo) {
cblas_scopy(visTodo, &visAudio[0], 1, &visResamplerInput[visResamplerRemain], 1);
Expand All @@ -202,6 +208,9 @@ - (int)renderInput:(int)amountToRead toBuffer:(float *)buffer {
}
} else if(rsvis) {
for(;;) {
if(stopping) {
break;
}
int samplesFlushed;
samplesFlushed = (int)rsstate_flush(rsvis, &visTemp[0], 8192);
if(samplesFlushed > 1) {
Expand All @@ -215,7 +224,7 @@ - (int)renderInput:(int)amountToRead toBuffer:(float *)buffer {
rsvis = NULL;
[visController postVisPCM:&visAudio[0] amount:frameCount];
visPushed += (double)frameCount / 44100.0;
} else {
} else if(!stopping) {
[visController postVisPCM:&visAudio[0] amount:frameCount];
visPushed += (double)frameCount / 44100.0;
}
Expand Down

0 comments on commit 791c9f9

Please sign in to comment.