From 6cda7696f3df7b4f80dbb2ad1e1fe9dee457eef5 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Fri, 21 Jul 2023 00:18:20 -0700 Subject: [PATCH] APL: Fix position handling for DSD Correctly scale the AudioChunk frame counts. This more and more makes me think I should be scaling this in the AudioChunk code instead, but then code may not know about the special case of every 8 frames only being one byte per channel. Signed-off-by: Christopher Snowhill --- Plugins/APL/APLDecoder.h | 2 ++ Plugins/APL/APLDecoder.m | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Plugins/APL/APLDecoder.h b/Plugins/APL/APLDecoder.h index 4fb0ec651..56697beab 100644 --- a/Plugins/APL/APLDecoder.h +++ b/Plugins/APL/APLDecoder.h @@ -18,6 +18,8 @@ long trackEnd; // frames until end of track. long trackLength; // track len in frames + BOOL isDSD; + APLFile *apl; } diff --git a/Plugins/APL/APLDecoder.m b/Plugins/APL/APLDecoder.m index cec402fa6..bb8db04ef 100644 --- a/Plugins/APL/APLDecoder.m +++ b/Plugins/APL/APLDecoder.m @@ -63,6 +63,8 @@ int channels = [[properties objectForKey:@"channels"] intValue]; // float sampleRate = [[properties objectForKey:@"sampleRate"] floatValue]; + isDSD = bitsPerSample == 1; + bytesPerFrame = ((bitsPerSample + 7) / 8) * channels; if([apl endBlock] > [apl startBlock]) @@ -119,12 +121,14 @@ return nil; } + size_t frameScale = isDSD ? 8 : 1; + AudioChunk *chunk = [decoder readAudio]; - if(chunk.frameCount > maxFrames) { - [chunk setFrameCount:maxFrames]; + if(chunk.frameCount * frameScale > maxFrames) { + [chunk setFrameCount:maxFrames / frameScale]; } - framePosition += chunk.frameCount; + framePosition += chunk.frameCount * frameScale; return chunk; }