From 05ff8464fd5f133112ec71090916c03c23e54857 Mon Sep 17 00:00:00 2001 From: bnnm Date: Sun, 20 Jun 2021 11:24:32 +0200 Subject: [PATCH] Extra helpers --- src/coding/coding.h | 4 +++- src/coding/pcm_decoder.c | 10 +++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/coding/coding.h b/src/coding/coding.h index 87d8d897..3a67caf2 100644 --- a/src/coding/coding.h +++ b/src/coding/coding.h @@ -90,7 +90,9 @@ void decode_ulaw(VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing, void decode_ulaw_int(VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do); void decode_alaw(VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do); void decode_pcmfloat(VGMSTREAMCHANNEL* stream, sample_t* outbuf, int channelspacing, int32_t first_sample, int32_t samples_to_do, int big_endian); -size_t pcm_bytes_to_samples(size_t bytes, int channels, int bits_per_sample); +int32_t pcm_bytes_to_samples(size_t bytes, int channels, int bits_per_sample); +int32_t pcm16_bytes_to_samples(size_t bytes, int channels); +int32_t pcm8_bytes_to_samples(size_t bytes, int channels); /* psx_decoder */ diff --git a/src/coding/pcm_decoder.c b/src/coding/pcm_decoder.c index cb86e2d1..c1bc2c0b 100644 --- a/src/coding/pcm_decoder.c +++ b/src/coding/pcm_decoder.c @@ -216,7 +216,15 @@ void decode_pcmfloat(VGMSTREAMCHANNEL * stream, sample_t * outbuf, int channelsp } } -size_t pcm_bytes_to_samples(size_t bytes, int channels, int bits_per_sample) { +int32_t pcm_bytes_to_samples(size_t bytes, int channels, int bits_per_sample) { if (channels <= 0 || bits_per_sample <= 0) return 0; return ((int64_t)bytes * 8) / channels / bits_per_sample; } + +int32_t pcm16_bytes_to_samples(size_t bytes, int channels) { + return pcm_bytes_to_samples(bytes, channels, 16); +} + +int32_t pcm8_bytes_to_samples(size_t bytes, int channels) { + return pcm_bytes_to_samples(bytes, channels, 8); +}