[Audio Output] Better handle latency oddities

The visualization buffer now holds up to 45 seconds of loop, and the
latency measurement code now caps this at 30 seconds, and restarts the
output if latency exceeds 30 seconds, such as if a sound output is
reset.

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
swiftingly
Christopher Snowhill 2022-06-26 01:09:01 -07:00
parent 5f2335b796
commit 5f52a4be81
2 changed files with 10 additions and 4 deletions

View File

@ -340,6 +340,7 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
lastCheckpointPts = kCMTimeZero; lastCheckpointPts = kCMTimeZero;
secondsLatency = 1.0; secondsLatency = 1.0;
started = NO; started = NO;
restarted = NO;
[self synchronizerBlock]; [self synchronizerBlock];
} }
@ -989,8 +990,13 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
if(latencySeconds < 0) if(latencySeconds < 0)
latencySeconds = 0; latencySeconds = 0;
latencyVis = latencySeconds - latencyVis; latencyVis = latencySeconds - latencyVis;
if(latencyVis < 0) if(latencyVis < 0 || latencyVis > 30.0) {
latencyVis = 0; if(latencyVis > 30.0 && !self->restarted) {
self->restarted = YES;
[outputController setShouldReset:YES];
}
latencyVis = 0.0;
}
*latencySecondsOut = latencySeconds; *latencySecondsOut = latencySeconds;
[visController postLatency:latencyVis]; [visController postLatency:latencyVis];
}]; }];

View File

@ -40,7 +40,7 @@ static VisualizationController *_sharedController = nil;
@synchronized(self) { @synchronized(self) {
if(self->sampleRate != sampleRate) { if(self->sampleRate != sampleRate) {
self->sampleRate = sampleRate; self->sampleRate = sampleRate;
int visAudioSize = (int)(sampleRate * 30.0); int visAudioSize = (int)(sampleRate * 45.0);
void *visAudio = realloc(self->visAudio, visAudioSize * sizeof(float)); void *visAudio = realloc(self->visAudio, visAudioSize * sizeof(float));
if(visAudio && visAudioSize) { if(visAudio && visAudioSize) {
if(visAudioSize > self->visAudioSize) { if(visAudioSize > self->visAudioSize) {
@ -71,7 +71,7 @@ static VisualizationController *_sharedController = nil;
- (void)postLatency:(double)latency { - (void)postLatency:(double)latency {
self->latency = latency; self->latency = latency;
assert(latency < 30.0); assert(latency < 45.0);
} }
- (double)readSampleRate { - (double)readSampleRate {