prepare for IMA ADPCM

This commit is contained in:
tildearrow 2024-03-17 12:24:19 -05:00
parent 8b3c48d42e
commit 83e7b2fbb8
6 changed files with 42 additions and 3 deletions

View file

@ -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;
}