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 <kode54@gmail.com>
This commit is contained in:
Christopher Snowhill 2023-07-21 00:12:43 -07:00
parent 440ba24c57
commit 16072b3af3
No known key found for this signature in database
2 changed files with 10 additions and 3 deletions

View file

@ -20,6 +20,7 @@
NSURL *sourceURL;
BOOL seekedToStart;
BOOL isDSD;
int bytesPerFrame; // Number of bytes per frame, ie channels * (bitsPerSample/8)

View file

@ -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;
}