mirror of
https://github.com/TwilitRealm/dusklight
synced 2026-05-26 23:26:45 -04:00
Allow decoding less PCM samples than a full frame
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user