diff --git a/src/engine/sample.cpp b/src/engine/sample.cpp index 21738b8a..61029740 100644 --- a/src/engine/sample.cpp +++ b/src/engine/sample.cpp @@ -1196,6 +1196,10 @@ unsigned char c219ShiftToVal[16]={ 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 7, 7, 8, 8, 8, 8 }; +signed char adpcmKTable[16]={ + 0, 1, 2, 4, 8, 16, 32, 64, -128, -64, -32, -16, -8, -4, -2, -1 +}; + void DivSample::render(unsigned int formatMask) { // step 1: convert to 16-bit if needed if (depth!=DIV_SAMPLE_DEPTH_16BIT) { @@ -1228,11 +1232,20 @@ void DivSample::render(unsigned int formatMask) { case DIV_SAMPLE_DEPTH_ADPCM_B: // ADPCM-B ymb_decode(dataB,data16,samples); break; - case DIV_SAMPLE_DEPTH_ADPCM_K: // K05 ADPCM + case DIV_SAMPLE_DEPTH_ADPCM_K: { // K05 ADPCM + signed char s=0; for (unsigned int i=0; i>1]; + if (i&1) { // TODO: is this right? + nibble>>=4; + } else { + nibble&=15; + } + s+=adpcmKTable[nibble]; + data16[i]=s<<8; } break; + } case DIV_SAMPLE_DEPTH_8BIT: // 8-bit PCM for (unsigned int i=0; i>8; + short delta=target-accum; + unsigned char next=0; + + if (delta!=0) { + int b=bsr((delta>=0)?delta:-delta); + if (delta>=0) { + if (b>7) b=7; + next=b&15; + + // test previous + if (next>1) { + const signed char t1=accum+adpcmKTable[next]; + const signed char t2=accum+adpcmKTable[next-1]; + const signed char d1=((t1-target)<0)?(target-t1):(t1-target); + const signed char d2=((t2-target)<0)?(target-t2):(t2-target); + + if (d28) b=8; + next=(16-b)&15; + + // test next + if (next<15) { + const signed char t1=accum+adpcmKTable[next]; + const signed char t2=accum+adpcmKTable[next+1]; + const signed char d1=((t1-target)<0)?(target-t1):(t1-target); + const signed char d2=((t2-target)<0)?(target-t2):(t2-target); + + if (d2=128 || accum+adpcmKTable[next]<-128) { + if (delta>=0) { + next--; + } else { + next++; + if (next>15) next=15; + } + }*/ + } + + out<<=4; + out|=next; + accum+=adpcmKTable[next]; + + if (i&1) { + dataK[i>>1]=out; + out=0; + } + } } if (NOT_IN_FORMAT(DIV_SAMPLE_DEPTH_8BIT)) { // 8-bit PCM if (!initInternal(DIV_SAMPLE_DEPTH_8BIT,samples)) return; diff --git a/src/engine/sysDef.cpp b/src/engine/sysDef.cpp index 59885807..9e7fafc0 100644 --- a/src/engine/sysDef.cpp +++ b/src/engine/sysDef.cpp @@ -1854,7 +1854,7 @@ void DivEngine::registerSystems() { ); sysDefs[DIV_SYSTEM_K053260]=new DivSysDef( - "Konami K053260", NULL, 0xcc, 0, 4, false, true, 0x161, false, 1U<