From 503ca803e9ee1f18861cb1ecdec62b291b2e1574 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Fri, 21 Jul 2023 00:12:43 -0700 Subject: [PATCH] CUE: Fix playback position tracking for DSD DSD wasn't tracking the correct sample count, because DSD Audio Chunks store the byte count, rather than the bit count. This may be changed in the future, so I'll have to remember. Signed-off-by: Christopher Snowhill --- Plugins/CueSheet/CueSheetDecoder.h | 1 + Plugins/CueSheet/CueSheetDecoder.m | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Plugins/CueSheet/CueSheetDecoder.h b/Plugins/CueSheet/CueSheetDecoder.h index 338675dd6..485fcc6f7 100644 --- a/Plugins/CueSheet/CueSheetDecoder.h +++ b/Plugins/CueSheet/CueSheetDecoder.h @@ -20,6 +20,7 @@ NSURL *sourceURL; BOOL seekedToStart; + BOOL isDSD; int bytesPerFrame; // Number of bytes per frame, ie channels * (bitsPerSample/8) diff --git a/Plugins/CueSheet/CueSheetDecoder.m b/Plugins/CueSheet/CueSheetDecoder.m index ab9f4c78c..14d4cd802 100644 --- a/Plugins/CueSheet/CueSheetDecoder.m +++ b/Plugins/CueSheet/CueSheetDecoder.m @@ -165,6 +165,8 @@ static void *kCueSheetDecoderContext = &kCueSheetDecoderContext; int channels = [[properties objectForKey:@"channels"] intValue]; float sampleRate = [[properties objectForKey:@"sampleRate"] floatValue]; + isDSD = bitsPerSample == 1; + bytesPerFrame = ((bitsPerSample + 7) / 8) * channels; double _trackStart = [track time]; @@ -195,6 +197,8 @@ static void *kCueSheetDecoderContext = &kCueSheetDecoderContext; int bitsPerSample = [[properties objectForKey:@"bitsPerSample"] intValue]; int channels = [[properties objectForKey:@"channels"] intValue]; + isDSD = bitsPerSample == 1; + bytesPerFrame = ((bitsPerSample + 7) / 8) * channels; trackStart = 0; @@ -348,14 +352,16 @@ static void *kCueSheetDecoderContext = &kCueSheetDecoderContext; return nil; } + size_t frameScale = isDSD ? 8 : 1; + AudioChunk *chunk = [decoder readAudio]; - size_t n = chunk.frameCount; + size_t n = chunk.frameCount * frameScale; if(n > frames) { - [chunk setFrameCount:frames]; + [chunk setFrameCount:frames / frameScale]; } - framePosition += chunk.frameCount; + framePosition += chunk.frameCount * frameScale; return chunk; }