C140: help µ-law ISN'T WORKING

This commit is contained in:
tildearrow 2023-08-12 01:54:12 -05:00
parent 0311d712b1
commit 27e454e7aa
7 changed files with 66 additions and 11 deletions

View file

@ -269,6 +269,9 @@ int DivSample::getSampleOffset(int offset, int length, DivSampleDepth depth) {
case DIV_SAMPLE_DEPTH_VOX:
off=(offset+1)/2;
break;
case DIV_SAMPLE_DEPTH_MULAW:
off=offset;
break;
case DIV_SAMPLE_DEPTH_16BIT:
off=offset*2;
break;
@ -316,6 +319,10 @@ int DivSample::getSampleOffset(int offset, int length, DivSampleDepth depth) {
off=(offset+1)/2;
len=(length+1)/2;
break;
case DIV_SAMPLE_DEPTH_MULAW:
off=offset;
len=length;
break;
case DIV_SAMPLE_DEPTH_16BIT:
off=offset*2;
len=length*2;
@ -365,6 +372,9 @@ int DivSample::getEndPosition(DivSampleDepth depth) {
case DIV_SAMPLE_DEPTH_VOX:
off=lengthVOX;
break;
case DIV_SAMPLE_DEPTH_MULAW:
off=lengthMuLaw;
break;
case DIV_SAMPLE_DEPTH_16BIT:
off=length16;
break;
@ -538,6 +548,12 @@ bool DivSample::initInternal(DivSampleDepth d, int count) {
dataVOX=new unsigned char[lengthVOX];
memset(dataVOX,0,lengthVOX);
break;
case DIV_SAMPLE_DEPTH_MULAW: // 8-bit µ-law
if (dataMuLaw!=NULL) delete[] dataMuLaw;
lengthMuLaw=count;
dataMuLaw=new unsigned char[(count+4095)&(~0xfff)];
memset(dataMuLaw,0,(count+4095)&(~0xfff));
break;
case DIV_SAMPLE_DEPTH_16BIT: // 16-bit
if (data16!=NULL) delete[] data16;
length16=count*2;
@ -1155,6 +1171,13 @@ void DivSample::render(unsigned int formatMask) {
case DIV_SAMPLE_DEPTH_VOX: // VOX
oki_decode(dataVOX,data16,samples);
break;
case DIV_SAMPLE_DEPTH_MULAW: // 8-bit µ-law PCM
for (unsigned int i=0; i<samples; i++) {
unsigned int s=(dataMuLaw[i]^0xff);
s=0x3f800000+(((s<<24)&0x80000000)|((s&0x7f)<<19));
data16[i]=(short)((*(float*)&s)*128.0f);
}
break;
default:
return;
}
@ -1233,6 +1256,16 @@ void DivSample::render(unsigned int formatMask) {
if (!initInternal(DIV_SAMPLE_DEPTH_VOX,samples)) return;
oki_encode(data16,dataVOX,samples);
}
if (NOT_IN_FORMAT(DIV_SAMPLE_DEPTH_MULAW)) { // µ-law
if (!initInternal(DIV_SAMPLE_DEPTH_MULAW,samples)) return;
for (unsigned int i=0; i<samples; i++) {
float s=(float)-data16[i];
s/=32768.0f;
unsigned int si=*(unsigned int*)&s;
si-=0x3f800000;
dataMuLaw[i]=(((si&0x80000000)>>24)|((si&0x03f80000)>>19))^0xff;
}
}
}
void* DivSample::getCurBuf() {
@ -1255,6 +1288,8 @@ void* DivSample::getCurBuf() {
return dataBRR;
case DIV_SAMPLE_DEPTH_VOX:
return dataVOX;
case DIV_SAMPLE_DEPTH_MULAW:
return dataMuLaw;
case DIV_SAMPLE_DEPTH_16BIT:
return data16;
default:
@ -1283,6 +1318,8 @@ unsigned int DivSample::getCurBufLen() {
return lengthBRR;
case DIV_SAMPLE_DEPTH_VOX:
return lengthVOX;
case DIV_SAMPLE_DEPTH_MULAW:
return lengthMuLaw;
case DIV_SAMPLE_DEPTH_16BIT:
return length16;
default:
@ -1392,4 +1429,5 @@ DivSample::~DivSample() {
if (dataB) delete[] dataB;
if (dataBRR) delete[] dataBRR;
if (dataVOX) delete[] dataVOX;
if (dataMuLaw) delete[] dataMuLaw;
}