From 3c043bd100855af8570980513c663e18720c9987 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sat, 10 Jan 2026 18:58:06 -0500 Subject: [PATCH] pad ADPCM-A/B samples to 256 bytes upon conversion issue #1910 also warn if the sample is an ADPCM-A or ADPCM-B one and it is not padded --- src/engine/sample.cpp | 8 ++++---- src/gui/sampleEdit.cpp | 7 +++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/engine/sample.cpp b/src/engine/sample.cpp index a52d937b7..0bdcd2d47 100644 --- a/src/engine/sample.cpp +++ b/src/engine/sample.cpp @@ -579,13 +579,13 @@ bool DivSample::initInternal(DivSampleDepth d, int count) { break; case DIV_SAMPLE_DEPTH_ADPCM_A: // ADPCM-A if (dataA!=NULL) delete[] dataA; - lengthA=(count+1)/2; + lengthA=(((count+1)/2)+255)&(~0xff); dataA=new unsigned char[(lengthA+255)&(~0xff)]; memset(dataA,0x80,(lengthA+255)&(~0xff)); break; case DIV_SAMPLE_DEPTH_ADPCM_B: // ADPCM-B if (dataB!=NULL) delete[] dataB; - lengthB=(count+1)/2; + lengthB=(((count+1)/2)+255)&(~0xff); dataB=new unsigned char[(lengthB+255)&(~0xff)]; memset(dataB,0x80,(lengthB+255)&(~0xff)); break; @@ -872,10 +872,10 @@ void DivSample::convert(DivSampleDepth newDepth, unsigned int formatMask) { setSampleCount((samples+1)&(~1)); break; case DIV_SAMPLE_DEPTH_ADPCM_A: // ADPCM-A - setSampleCount((samples+1)&(~1)); + setSampleCount((samples+511)&(~511)); break; case DIV_SAMPLE_DEPTH_ADPCM_B: // ADPCM-B - setSampleCount((samples+1)&(~1)); + setSampleCount((samples+511)&(~511)); break; case DIV_SAMPLE_DEPTH_ADPCM_K: // K05 ADPCM setSampleCount((samples+1)&(~1)); diff --git a/src/gui/sampleEdit.cpp b/src/gui/sampleEdit.cpp index 9160fdfa9..8666bec5e 100644 --- a/src/gui/sampleEdit.cpp +++ b/src/gui/sampleEdit.cpp @@ -593,6 +593,13 @@ void FurnaceGUI::drawSampleEdit() { } } + // ADPCM-A/B specific warnings + if (sample->depth==DIV_SAMPLE_DEPTH_ADPCM_A || sample->depth==DIV_SAMPLE_DEPTH_ADPCM_B) { + if (sample->samples&511) { + SAMPLE_WARN(warnLength,_("ADPCM sample is not padded to 256 bytes!")); + } + } + // chips grid if (dispatch==NULL) continue;