[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>
lastfm
Christopher Snowhill 2022-06-26 01:09:01 -07:00
parent c489d7ca91
commit aa3673ed33
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;
secondsLatency = 1.0;
started = NO;
restarted = NO;
[self synchronizerBlock];
}
@ -989,8 +990,13 @@ current_device_listener(AudioObjectID inObjectID, UInt32 inNumberAddresses, cons
if(latencySeconds < 0)
latencySeconds = 0;
latencyVis = latencySeconds - latencyVis;
if(latencyVis < 0)
latencyVis = 0;
if(latencyVis < 0 || latencyVis > 30.0) {
if(latencyVis > 30.0 && !self->restarted) {
self->restarted = YES;
[outputController setShouldReset:YES];
}
latencyVis = 0.0;
}
*latencySecondsOut = latencySeconds;
[visController postLatency:latencyVis];
}];

View File

@ -40,7 +40,7 @@ static VisualizationController *_sharedController = nil;
@synchronized(self) {
if(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));
if(visAudio && visAudioSize) {
if(visAudioSize > self->visAudioSize) {
@ -71,7 +71,7 @@ static VisualizationController *_sharedController = nil;
- (void)postLatency:(double)latency {
self->latency = latency;
assert(latency < 30.0);
assert(latency < 45.0);
}
- (double)readSampleRate {