diff --git a/src/engine/fileOpsSample.cpp b/src/engine/fileOpsSample.cpp index 8e16cc504..16c0432e3 100644 --- a/src/engine/fileOpsSample.cpp +++ b/src/engine/fileOpsSample.cpp @@ -505,6 +505,7 @@ DivSample* DivEngine::sampleFromFileRaw(const char* path, DivSampleDepth depth, case DIV_SAMPLE_DEPTH_ADPCM_B: case DIV_SAMPLE_DEPTH_ADPCM_K: case DIV_SAMPLE_DEPTH_VOX: + case DIV_SAMPLE_DEPTH_4BIT: samples=lenDivided*2; break; case DIV_SAMPLE_DEPTH_IMA_ADPCM: @@ -617,6 +618,7 @@ DivSample* DivEngine::sampleFromFileRaw(const char* path, DivSampleDepth depth, case DIV_SAMPLE_DEPTH_ADPCM_B: case DIV_SAMPLE_DEPTH_ADPCM_K: case DIV_SAMPLE_DEPTH_VOX: + case DIV_SAMPLE_DEPTH_4BIT: // swap nibbles for (unsigned int i=0; igetCurBufLen(); i++) { b[i]=(b[i]<<4)|(b[i]>>4); @@ -629,7 +631,7 @@ DivSample* DivEngine::sampleFromFileRaw(const char* path, DivSampleDepth depth, for (unsigned int i=0; igetCurBufLen(); i++) { b[i]=(((b[i]&7)<<4)|(((b[i]>>3)&15)^((b[i]&0x80)?15:0))|(b[i]&0x80))^0xff; } - break; + break;\ default: break; } diff --git a/src/engine/sample.cpp b/src/engine/sample.cpp index a8d1ba770..6a52ede6a 100644 --- a/src/engine/sample.cpp +++ b/src/engine/sample.cpp @@ -633,7 +633,7 @@ bool DivSample::initInternal(DivSampleDepth d, int count) { break; case DIV_SAMPLE_DEPTH_4BIT: if (data4!=NULL) delete[] data4; - length4=count; + length4=(count+1)/2; data4=new unsigned char[length4]; memset(data4,0,length4); break; @@ -1334,11 +1334,18 @@ void DivSample::render(unsigned int formatMask) { } } break; - case DIV_SAMPLE_DEPTH_4BIT: + case DIV_SAMPLE_DEPTH_4BIT: { + unsigned short nibble=0; for (unsigned int i=0; i>4; + } + data16[i]=(nibble<<12)^0x8000; } break; + } default: return; } @@ -1542,11 +1549,16 @@ void DivSample::render(unsigned int formatMask) { } if (NOT_IN_FORMAT(DIV_SAMPLE_DEPTH_4BIT)) { if (!initInternal(DIV_SAMPLE_DEPTH_4BIT,samples)) return; - for (unsigned int i=0; i>12)&0xf; - // if (i+1>12); - // } + unsigned char _sample=0, sample4=0; + unsigned short* samplePtr = (unsigned short*)data16; + for (unsigned int i=0; i>12; + sample4=_sample<<4; + if (i+1>12; + sample4|=_sample; + } + data4[i/2]=sample4; } } } diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 6f0aa455c..9a162c190 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -7010,6 +7010,7 @@ bool FurnaceGUI::loop() { ImGui::SameLine(); ImGui::SetNextItemWidth(120.0f*dpiScale); if (ImGui::InputInt("##RSChans",&pendingRawSampleChannels,1,2)) { + CLAMP_VAR(pendingRawSampleChannels, 1, 16) } ImGui::Text(_("(will be mixed down to mono)")); ImGui::Checkbox(_("Unsigned"),&pendingRawSampleUnsigned); @@ -7023,7 +7024,8 @@ bool FurnaceGUI::loop() { pendingRawSampleDepth==DIV_SAMPLE_DEPTH_QSOUND_ADPCM || pendingRawSampleDepth==DIV_SAMPLE_DEPTH_ADPCM_A || pendingRawSampleDepth==DIV_SAMPLE_DEPTH_ADPCM_B || - pendingRawSampleDepth==DIV_SAMPLE_DEPTH_VOX) { + pendingRawSampleDepth==DIV_SAMPLE_DEPTH_VOX || + pendingRawSampleDepth==DIV_SAMPLE_DEPTH_4BIT) { ImGui::Checkbox(_("Swap nibbles"),&pendingRawSampleSwapNibbles); } diff --git a/src/gui/sampleEdit.cpp b/src/gui/sampleEdit.cpp index 77121e641..bb1be9371 100644 --- a/src/gui/sampleEdit.cpp +++ b/src/gui/sampleEdit.cpp @@ -1917,7 +1917,18 @@ void FurnaceGUI::drawSampleEdit() { posX=samplePos+pos.x*sampleZoom; if (posX>(int)sample->samples) posX=-1; } - posY=(0.5-pos.y/rectSize.y)*((sample->depth==DIV_SAMPLE_DEPTH_8BIT)?255:65535); + switch (sample->depth) { + case DIV_SAMPLE_DEPTH_8BIT: + posY=(0.5-pos.y/rectSize.y)*255; + break; + case DIV_SAMPLE_DEPTH_4BIT: + posY=(1-pos.y/rectSize.y)*15; + break; + default: + posY=(0.5-pos.y/rectSize.y)*65535; + break; + } + if (posX>=0) { statusBar2=fmt::sprintf("(%d, %d)",posX,posY); }