raw sample import fixes

This commit is contained in:
tildearrow 2022-08-13 06:25:11 -05:00
parent 91f9352eaf
commit 041a76ad81
4 changed files with 15 additions and 6 deletions

View file

@ -2639,7 +2639,7 @@ DivSample* DivEngine::sampleFromFile(const char* path) {
#endif #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) { if (song.sample.size()>=256) {
lastError="too many samples!"; lastError="too many samples!";
return NULL; return NULL;
@ -2780,7 +2780,11 @@ DivSample* DivEngine::sampleFromFileRaw(const char* path, DivSampleDepth depth,
int accum=0; int accum=0;
for (int j=0; j<channels; j++) { for (int j=0; j<channels; j++) {
if (pos+1>=len) break; if (pos+1>=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; pos+=2;
} }
accum/=channels; accum/=channels;
@ -2791,7 +2795,7 @@ DivSample* DivEngine::sampleFromFileRaw(const char* path, DivSampleDepth depth,
int accum=0; int accum=0;
for (int j=0; j<channels; j++) { for (int j=0; j<channels; j++) {
if (pos>=len) break; if (pos>=len) break;
accum+=(signed char)buf[pos++]; accum+=(signed char)(buf[pos++]^(unsign?0x80:0));
} }
accum/=channels; accum/=channels;
sample->data8[i]=accum; sample->data8[i]=accum;

View file

@ -725,7 +725,7 @@ class DivEngine {
DivSample* sampleFromFile(const char* path); DivSample* sampleFromFile(const char* path);
// get raw sample // 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 // delete sample
void delSample(int index); void delSample(int index);

View file

@ -4172,6 +4172,7 @@ bool FurnaceGUI::loop() {
if (ImGui::InputInt("##RSChans",&pendingRawSampleChannels)) { if (ImGui::InputInt("##RSChans",&pendingRawSampleChannels)) {
} }
ImGui::Text("(will be mixed down to mono)"); ImGui::Text("(will be mixed down to mono)");
ImGui::Checkbox("Unsigned",&pendingRawSampleUnsigned);
ImGui::EndDisabled(); ImGui::EndDisabled();
ImGui::BeginDisabled(pendingRawSampleDepth!=DIV_SAMPLE_DEPTH_16BIT); ImGui::BeginDisabled(pendingRawSampleDepth!=DIV_SAMPLE_DEPTH_16BIT);
@ -4179,7 +4180,7 @@ bool FurnaceGUI::loop() {
ImGui::EndDisabled(); ImGui::EndDisabled();
if (ImGui::Button("OK")) { 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) { if (s==NULL) {
showError(e->getLastError()); showError(e->getLastError());
} else { } else {
@ -4653,6 +4654,10 @@ FurnaceGUI::FurnaceGUI():
drawHalt(10), drawHalt(10),
macroPointSize(16), macroPointSize(16),
waveEditStyle(0), waveEditStyle(0),
pendingRawSampleDepth(8),
pendingRawSampleChannels(1),
pendingRawSampleUnsigned(false),
pendingRawSampleBigEndian(false),
globalWinFlags(0), globalWinFlags(0),
curFileDialog(GUI_FILE_OPEN), curFileDialog(GUI_FILE_OPEN),
warnAction(GUI_WARN_OPEN), warnAction(GUI_WARN_OPEN),

View file

@ -975,7 +975,7 @@ class FurnaceGUI {
String pendingRawSample; String pendingRawSample;
int pendingRawSampleDepth, pendingRawSampleChannels; int pendingRawSampleDepth, pendingRawSampleChannels;
bool pendingRawSampleBigEndian; bool pendingRawSampleUnsigned, pendingRawSampleBigEndian;
ImGuiWindowFlags globalWinFlags; ImGuiWindowFlags globalWinFlags;