Allow decoding less PCM samples than a full frame

This commit is contained in:
PJB3005
2026-03-15 20:35:06 +01:00
parent 8b63858d9d
commit 07892dbe28
2 changed files with 6 additions and 3 deletions
+3 -2
View File
@@ -33,8 +33,7 @@ static s16 Clamp16(s32 value) {
void dusk::audio::Adpcm4ToPcm16(const u8* adpcm, size_t adpcmLength, s16* pcm, size_t pcmLength, s16& hist2, s16& hist1) {
assert (adpcmLength % AdpcmFrameSize == 0 && "ADPCM must be divisible by frame size");
const auto expectedPcmLength = (adpcmLength / AdpcmFrameSize) * 16;
assert (expectedPcmLength <= pcmLength && "PCM output buffer is too small!");
auto endPtr = pcm + pcmLength;
for (int i = 0; i < adpcmLength; i += AdpcmFrameSize) {
u8 header = adpcm[i];
@@ -55,6 +54,8 @@ void dusk::audio::Adpcm4ToPcm16(const u8* adpcm, size_t adpcmLength, s16* pcm, s
hist1 = sample;
*pcm++ = sample;
if (endPtr == pcm)
return;
}
}
}
+3 -1
View File
@@ -46,7 +46,9 @@ static u32 ConvertDataLengthToSamples(const JASDsp::TChannel& channel, u32 dataL
static u32 ConvertSamplesToDataLength(const JASDsp::TChannel& channel, u32 samples) {
if (samples % channel.mSamplesPerBlock != 0) {
CRASH("Indivisible sample count: %d\n", samples);
// Ensure we round up.
samples += channel.mSamplesPerBlock;
//CRASH("Indivisible sample count: %d\n", samples);
}
return (samples / channel.mSamplesPerBlock) * channel.mBytesPerBlock;