diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index ffe2d6aa3..4c51f367f 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -2639,7 +2639,7 @@ DivSample* DivEngine::sampleFromFile(const char* path) { #endif } -DivSample* DivEngine::sampleFromFileRaw(const char* path, DivSampleDepth depth, int channels, bool bigEndian) { +DivSample* DivEngine::sampleFromFileRaw(const char* path, DivSampleDepth depth, int channels, bool bigEndian, bool unsign) { if (song.sample.size()>=256) { lastError="too many samples!"; return NULL; @@ -2780,7 +2780,11 @@ DivSample* DivEngine::sampleFromFileRaw(const char* path, DivSampleDepth depth, int accum=0; for (int j=0; j=len) break; - accum+=((short*)buf)[pos>>1]; + if (bigEndian) { + accum+=(short)(((short)((buf[pos]<<8)|buf[pos+1]))^(unsign?0x8000:0)); + } else { + accum+=(short)(((short)(buf[pos]|(buf[pos+1]<<8)))^(unsign?0x8000:0)); + } pos+=2; } accum/=channels; @@ -2791,7 +2795,7 @@ DivSample* DivEngine::sampleFromFileRaw(const char* path, DivSampleDepth depth, int accum=0; for (int j=0; j=len) break; - accum+=(signed char)buf[pos++]; + accum+=(signed char)(buf[pos++]^(unsign?0x80:0)); } accum/=channels; sample->data8[i]=accum; diff --git a/src/engine/engine.h b/src/engine/engine.h index a03c92432..3a73d7d24 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -725,7 +725,7 @@ class DivEngine { DivSample* sampleFromFile(const char* path); // get raw sample - DivSample* sampleFromFileRaw(const char* path, DivSampleDepth depth, int channels, bool bigEndian); + DivSample* sampleFromFileRaw(const char* path, DivSampleDepth depth, int channels, bool bigEndian, bool unsign); // delete sample void delSample(int index); diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 4d01f60ff..0ed0ffbe1 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -4172,6 +4172,7 @@ bool FurnaceGUI::loop() { if (ImGui::InputInt("##RSChans",&pendingRawSampleChannels)) { } ImGui::Text("(will be mixed down to mono)"); + ImGui::Checkbox("Unsigned",&pendingRawSampleUnsigned); ImGui::EndDisabled(); ImGui::BeginDisabled(pendingRawSampleDepth!=DIV_SAMPLE_DEPTH_16BIT); @@ -4179,7 +4180,7 @@ bool FurnaceGUI::loop() { ImGui::EndDisabled(); if (ImGui::Button("OK")) { - DivSample* s=e->sampleFromFileRaw(pendingRawSample.c_str(),(DivSampleDepth)pendingRawSampleDepth,pendingRawSampleChannels,pendingRawSampleBigEndian); + DivSample* s=e->sampleFromFileRaw(pendingRawSample.c_str(),(DivSampleDepth)pendingRawSampleDepth,pendingRawSampleChannels,pendingRawSampleBigEndian,pendingRawSampleUnsigned); if (s==NULL) { showError(e->getLastError()); } else { @@ -4653,6 +4654,10 @@ FurnaceGUI::FurnaceGUI(): drawHalt(10), macroPointSize(16), waveEditStyle(0), + pendingRawSampleDepth(8), + pendingRawSampleChannels(1), + pendingRawSampleUnsigned(false), + pendingRawSampleBigEndian(false), globalWinFlags(0), curFileDialog(GUI_FILE_OPEN), warnAction(GUI_WARN_OPEN), diff --git a/src/gui/gui.h b/src/gui/gui.h index e178efc9d..ff6dd93bb 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -975,7 +975,7 @@ class FurnaceGUI { String pendingRawSample; int pendingRawSampleDepth, pendingRawSampleChannels; - bool pendingRawSampleBigEndian; + bool pendingRawSampleUnsigned, pendingRawSampleBigEndian; ImGuiWindowFlags globalWinFlags;