From 83e7b2fbb8ff3c4f1a574fa5b8216040cc34e74d Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sun, 17 Mar 2024 12:24:19 -0500 Subject: [PATCH] prepare for IMA ADPCM --- papers/format.md | 4 ++++ papers/newIns.md | 2 ++ src/engine/sample.cpp | 28 ++++++++++++++++++++++++++++ src/engine/sample.h | 7 ++++++- src/engine/sysDef.cpp | 2 +- src/gui/guiConst.cpp | 2 +- 6 files changed, 42 insertions(+), 3 deletions(-) diff --git a/papers/format.md b/papers/format.md index 97c1f1302..e28a14773 100644 --- a/papers/format.md +++ b/papers/format.md @@ -564,9 +564,13 @@ size | description | - 4: QSound ADPCM | - 5: ADPCM-A | - 6: ADPCM-B + | - 7: K05 ADPCM | - 8: 8-bit PCM | - 9: BRR (SNES) | - 10: VOX + | - 11: 8-bit μ-law PCM + | - 12: C219 PCM + | - 13: IMA ADPCM | - 16: 16-bit PCM 1 | loop direction (>=123) or reserved | - 0: forward diff --git a/papers/newIns.md b/papers/newIns.md index d301d27c2..f37a54deb 100644 --- a/papers/newIns.md +++ b/papers/newIns.md @@ -124,6 +124,8 @@ the following instrument types are available: - 55: ESFM - 56: PowerNoise (noise) - 57: PowerNoise (slope) +- 58: Dave +- 59: NDS the following feature codes are recognized: diff --git a/src/engine/sample.cpp b/src/engine/sample.cpp index bb8a21d3f..8ce8dd16f 100644 --- a/src/engine/sample.cpp +++ b/src/engine/sample.cpp @@ -279,6 +279,9 @@ int DivSample::getSampleOffset(int offset, int length, DivSampleDepth depth) { case DIV_SAMPLE_DEPTH_C219: off=offset; break; + case DIV_SAMPLE_DEPTH_IMA_ADPCM: + off=(offset+1)/2; + break; case DIV_SAMPLE_DEPTH_16BIT: off=offset*2; break; @@ -338,6 +341,10 @@ int DivSample::getSampleOffset(int offset, int length, DivSampleDepth depth) { off=offset; len=length; break; + case DIV_SAMPLE_DEPTH_IMA_ADPCM: + off=(offset+1)/2; + len=(length+1)/2; + break; case DIV_SAMPLE_DEPTH_16BIT: off=offset*2; len=length*2; @@ -396,6 +403,9 @@ int DivSample::getEndPosition(DivSampleDepth depth) { case DIV_SAMPLE_DEPTH_C219: off=lengthC219; break; + case DIV_SAMPLE_DEPTH_IMA_ADPCM: + off=lengthIMA; + break; case DIV_SAMPLE_DEPTH_16BIT: off=length16; break; @@ -587,6 +597,12 @@ bool DivSample::initInternal(DivSampleDepth d, int count) { dataC219=new unsigned char[(count+4095)&(~0xfff)]; memset(dataC219,0,(count+4095)&(~0xfff)); break; + case DIV_SAMPLE_DEPTH_IMA_ADPCM: // IMA ADPCM + if (dataIMA!=NULL) delete[] dataIMA; + lengthIMA=(count+1)/2; + dataIMA=new unsigned char[lengthIMA]; + memset(dataIMA,0,lengthIMA); + break; case DIV_SAMPLE_DEPTH_16BIT: // 16-bit if (data16!=NULL) delete[] data16; length16=count*2; @@ -1271,6 +1287,9 @@ void DivSample::render(unsigned int formatMask) { if (dataC219[i]&0x80) data16[i]=-data16[i]; } break; + case DIV_SAMPLE_DEPTH_IMA_ADPCM: // IMA ADPCM + // TODO: decode + break; default: return; } @@ -1442,6 +1461,10 @@ void DivSample::render(unsigned int formatMask) { dataC219[i]=x|(negate?0x80:0); } } + if (NOT_IN_FORMAT(DIV_SAMPLE_DEPTH_IMA_ADPCM)) { // C219 + if (!initInternal(DIV_SAMPLE_DEPTH_IMA_ADPCM,samples)) return; + // TODO: encode + } } void* DivSample::getCurBuf() { @@ -1470,6 +1493,8 @@ void* DivSample::getCurBuf() { return dataMuLaw; case DIV_SAMPLE_DEPTH_C219: return dataC219; + case DIV_SAMPLE_DEPTH_IMA_ADPCM: + return dataIMA; case DIV_SAMPLE_DEPTH_16BIT: return data16; default: @@ -1504,6 +1529,8 @@ unsigned int DivSample::getCurBufLen() { return lengthMuLaw; case DIV_SAMPLE_DEPTH_C219: return lengthC219; + case DIV_SAMPLE_DEPTH_IMA_ADPCM: + return lengthIMA; case DIV_SAMPLE_DEPTH_16BIT: return length16; default: @@ -1616,4 +1643,5 @@ DivSample::~DivSample() { if (dataVOX) delete[] dataVOX; if (dataMuLaw) delete[] dataMuLaw; if (dataC219) delete[] dataC219; + if (dataIMA) delete[] dataIMA; } diff --git a/src/engine/sample.h b/src/engine/sample.h index 63d219259..cd4175e9d 100644 --- a/src/engine/sample.h +++ b/src/engine/sample.h @@ -46,6 +46,7 @@ enum DivSampleDepth: unsigned char { DIV_SAMPLE_DEPTH_VOX=10, DIV_SAMPLE_DEPTH_MULAW=11, DIV_SAMPLE_DEPTH_C219=12, + DIV_SAMPLE_DEPTH_IMA_ADPCM=13, DIV_SAMPLE_DEPTH_16BIT=16, DIV_SAMPLE_DEPTH_MAX // boundary for sample depth }; @@ -114,6 +115,7 @@ struct DivSample { // - 10: VOX ADPCM // - 11: 8-bit µ-law PCM // - 12: C219 "µ-law" PCM + // - 13: IMA ADPCM // - 16: 16-bit PCM DivSampleDepth depth; bool loop, brrEmphasis, dither; @@ -139,8 +141,9 @@ struct DivSample { unsigned char* dataVOX; // 10 unsigned char* dataMuLaw; // 11 unsigned char* dataC219; // 12 + unsigned char* dataIMA; // 13 - unsigned int length8, length16, length1, lengthDPCM, lengthZ, lengthQSoundA, lengthA, lengthB, lengthK, lengthBRR, lengthVOX, lengthMuLaw, lengthC219; + unsigned int length8, length16, length1, lengthDPCM, lengthZ, lengthQSoundA, lengthA, lengthB, lengthK, lengthBRR, lengthVOX, lengthMuLaw, lengthC219, lengthIMA; unsigned int samples; @@ -349,6 +352,7 @@ struct DivSample { dataVOX(NULL), dataMuLaw(NULL), dataC219(NULL), + dataIMA(NULL), length8(0), length16(0), length1(0), @@ -362,6 +366,7 @@ struct DivSample { lengthVOX(0), lengthMuLaw(0), lengthC219(0), + lengthIMA(0), samples(0) { for (int i=0; i