VGMStream: Add native support for 24/32 bps int

Signed-off-by: Christopher Snowhill <kode54@gmail.com>
This commit is contained in:
Christopher Snowhill 2025-04-20 21:34:11 -07:00
parent 4232fb3949
commit 47a749ace0
2 changed files with 13 additions and 7 deletions

View file

@ -35,6 +35,7 @@
double fadeTime; double fadeTime;
int sampleRate; int sampleRate;
int channels; int channels;
int bps;
int bitrate; int bitrate;
long totalFrames; long totalFrames;
long framesRead; long framesRead;

View file

@ -137,9 +137,12 @@ static NSString *get_description_tag(const char *description, const char *tag, c
} }
BOOL formatFloat; BOOL formatFloat;
int bps;
switch(stream->format->sample_format) { switch(stream->format->sample_format) {
case LIBVGMSTREAM_SFMT_PCM16: formatFloat = NO; break; case LIBVGMSTREAM_SFMT_PCM16: bps = 16; formatFloat = NO; break;
case LIBVGMSTREAM_SFMT_FLOAT: formatFloat = YES; break; case LIBVGMSTREAM_SFMT_PCM24: bps = 24; formatFloat = NO; break;
case LIBVGMSTREAM_SFMT_PCM32: bps = 32; formatFloat = NO; break;
case LIBVGMSTREAM_SFMT_FLOAT: bps = 32; formatFloat = YES; break;
default: default:
return; return;
} }
@ -147,7 +150,7 @@ static NSString *get_description_tag(const char *description, const char *tag, c
NSDictionary *properties = @{ @"bitrate": @(bitrate / 1000), NSDictionary *properties = @{ @"bitrate": @(bitrate / 1000),
@"sampleRate": @(sampleRate), @"sampleRate": @(sampleRate),
@"totalFrames": @(totalFrames), @"totalFrames": @(totalFrames),
@"bitsPerSample": @(formatFloat ? 32 : 16), @"bitsPerSample": @(bps),
@"floatingPoint": @(formatFloat), @"floatingPoint": @(formatFloat),
@"channels": @(channels), @"channels": @(channels),
@"seekable": @(YES), @"seekable": @(YES),
@ -278,8 +281,10 @@ static NSString *get_description_tag(const char *description, const char *tag, c
bitrate = stream->format->stream_bitrate; bitrate = stream->format->stream_bitrate;
switch(stream->format->sample_format) { switch(stream->format->sample_format) {
case LIBVGMSTREAM_SFMT_PCM16: formatFloat = NO; break; case LIBVGMSTREAM_SFMT_PCM16: bps = 16; formatFloat = NO; break;
case LIBVGMSTREAM_SFMT_FLOAT: formatFloat = YES; break; case LIBVGMSTREAM_SFMT_PCM24: bps = 24; formatFloat = NO; break;
case LIBVGMSTREAM_SFMT_PCM32: bps = 32; formatFloat = NO; break;
case LIBVGMSTREAM_SFMT_FLOAT: bps = 32; formatFloat = YES; break;
default: default:
libvgmstream_free(stream); libvgmstream_free(stream);
stream = NULL; stream = NULL;
@ -296,7 +301,7 @@ static NSString *get_description_tag(const char *description, const char *tag, c
return @{ @"bitrate": @(bitrate / 1000), return @{ @"bitrate": @(bitrate / 1000),
@"sampleRate": @(sampleRate), @"sampleRate": @(sampleRate),
@"totalFrames": @(totalFrames), @"totalFrames": @(totalFrames),
@"bitsPerSample": @(formatFloat ? 32 : 16), @"bitsPerSample": @(bps),
@"floatingPoint": @(formatFloat), @"floatingPoint": @(formatFloat),
@"channels": @(channels), @"channels": @(channels),
@"seekable": @(YES), @"seekable": @(YES),
@ -327,7 +332,7 @@ static NSString *get_description_tag(const char *description, const char *tag, c
continue; continue;
} }
const size_t bytes_per_sample = stream->format->channels * (formatFloat ? 4 : 2); const size_t bytes_per_sample = stream->format->channels * (bps / 8);
framesDone = bytes_done / bytes_per_sample; framesDone = bytes_done / bytes_per_sample;
framesRead += framesDone; framesRead += framesDone;