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 <kode54@gmail.com>
This commit is contained in:
Christopher Snowhill 2023-07-21 00:18:20 -07:00
parent 7f0fe33f9d
commit 6cda7696f3
No known key found for this signature in database
2 changed files with 9 additions and 3 deletions

View file

@ -18,6 +18,8 @@
long trackEnd; // frames until end of track. long trackEnd; // frames until end of track.
long trackLength; // track len in frames long trackLength; // track len in frames
BOOL isDSD;
APLFile *apl; APLFile *apl;
} }

View file

@ -63,6 +63,8 @@
int channels = [[properties objectForKey:@"channels"] intValue]; int channels = [[properties objectForKey:@"channels"] intValue];
// float sampleRate = [[properties objectForKey:@"sampleRate"] floatValue]; // float sampleRate = [[properties objectForKey:@"sampleRate"] floatValue];
isDSD = bitsPerSample == 1;
bytesPerFrame = ((bitsPerSample + 7) / 8) * channels; bytesPerFrame = ((bitsPerSample + 7) / 8) * channels;
if([apl endBlock] > [apl startBlock]) if([apl endBlock] > [apl startBlock])
@ -119,12 +121,14 @@
return nil; return nil;
} }
size_t frameScale = isDSD ? 8 : 1;
AudioChunk *chunk = [decoder readAudio]; AudioChunk *chunk = [decoder readAudio];
if(chunk.frameCount > maxFrames) { if(chunk.frameCount * frameScale > maxFrames) {
[chunk setFrameCount:maxFrames]; [chunk setFrameCount:maxFrames / frameScale];
} }
framePosition += chunk.frameCount; framePosition += chunk.frameCount * frameScale;
return chunk; return chunk;
} }