From 69ae4f56bde07d7260165944bd389ac714110408 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sun, 9 Nov 2025 17:47:37 -0500 Subject: [PATCH] total extinction of legacy sample mode, part 7 finish the conversion method --- src/engine/fileOps/dmf.cpp | 1 + src/engine/legacySample.cpp | 64 ++++++++++++++++++++++++++++++++++++- src/engine/sample.cpp | 1 + src/engine/sample.h | 2 ++ 4 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/engine/fileOps/dmf.cpp b/src/engine/fileOps/dmf.cpp index 4dbea03bf..06c0754ed 100644 --- a/src/engine/fileOps/dmf.cpp +++ b/src/engine/fileOps/dmf.cpp @@ -948,6 +948,7 @@ bool DivEngine::loadDMF(unsigned char* file, size_t len) { if (ds.version<=0x08) { sample->centerRate=ymuSampleRate*400; } + sample->legacyRate=sample->centerRate; if (ds.version>0x15) { sample->depth=(DivSampleDepth)reader.readC(); if (sample->depth!=DIV_SAMPLE_DEPTH_8BIT && sample->depth!=DIV_SAMPLE_DEPTH_16BIT) { diff --git a/src/engine/legacySample.cpp b/src/engine/legacySample.cpp index 2b0299d28..faf91086a 100644 --- a/src/engine/legacySample.cpp +++ b/src/engine/legacySample.cpp @@ -32,6 +32,61 @@ bool DivEngine::convertLegacySampleMode() { return false; } + // check which samples are used by instruments so we don't touch them + bool* isUsedByIns=new bool[MAX(1,song.sample.size())]; + memset(isUsedByIns,0,MAX(1,song.sample.size())*sizeof(bool)); + for (DivInstrument* ins: song.ins) { + bool canUse=false; + if (ins->type==DIV_INS_MSM6258 || + ins->type==DIV_INS_MSM6295 || + ins->type==DIV_INS_ADPCMA || + ins->type==DIV_INS_ADPCMB || + ins->type==DIV_INS_SEGAPCM || + ins->type==DIV_INS_QSOUND || + ins->type==DIV_INS_YMZ280B || + ins->type==DIV_INS_RF5C68 || + ins->type==DIV_INS_AMIGA || + ins->type==DIV_INS_MULTIPCM || + ins->type==DIV_INS_SNES || + ins->type==DIV_INS_ES5506 || + ins->type==DIV_INS_K007232 || + ins->type==DIV_INS_GA20 || + ins->type==DIV_INS_K053260 || + ins->type==DIV_INS_C140 || + ins->type==DIV_INS_C219 || + ins->type==DIV_INS_NDS || + ins->type==DIV_INS_GBA_DMA || + ins->type==DIV_INS_GBA_MINMOD || + ins->type==DIV_INS_NES || + ins->type==DIV_INS_SUPERVISION) { + canUse=true; + } + if (ins->type==DIV_INS_SU || + ins->type==DIV_INS_AY || + ins->type==DIV_INS_AY8930 || + ins->type==DIV_INS_MIKEY || + ins->type==DIV_INS_PCE || + ins->type==DIV_INS_X1_010 || + ins->type==DIV_INS_SWAN || + ins->type==DIV_INS_VRC6) { + if (ins->amiga.useSample) canUse=true; + } + + if (canUse) { + if (ins->amiga.useNoteMap) { + for (int i=0; i<120; i++) { + if (ins->amiga.noteMap[i].map>=0 && ins->amiga.noteMap[i].map<(int)song.sample.size()) { + isUsedByIns[ins->amiga.noteMap[i].map]=true; + } + } + } else { + if (ins->amiga.initSample>=0 && ins->amiga.initSample<(int)song.sample.size()) { + isUsedByIns[ins->amiga.initSample]=true; + } + } + } + } + auto initSampleInsIfNeeded=[this,&legacyInsInit]() { if (legacyInsInit==-1) { legacyInsInit=(int)song.ins.size(); @@ -293,8 +348,15 @@ bool DivEngine::convertLegacySampleMode() { // we've got a note if (sampleMode==1) { initSampleInsIfNeeded(); - //p->newData[k][DIV_PAT_NOTE]=60+12*sampleBank+(p->newData[k][DIV_PAT_NOTE]%12); p->newData[k][DIV_PAT_INS]=MIN(0xff,legacyInsInit+sampleBank); + + int involvedSample=12*sampleBank+(p->newData[k][DIV_PAT_NOTE]%12); + if (involvedSample>=0 && involvedSamplecenterRate=sample->legacyRate; + } + } } } else if (p->newData[k][DIV_PAT_NOTE]==DIV_NOTE_OFF && noteOffDisablesSampleMode) { sampleMode=0; diff --git a/src/engine/sample.cpp b/src/engine/sample.cpp index 03a6d1089..a52d937b7 100644 --- a/src/engine/sample.cpp +++ b/src/engine/sample.cpp @@ -118,6 +118,7 @@ DivDataErrors DivSample::readSampleData(SafeReader& reader, short version) { } // just in case it's not new sample, it's a very old version and we gotta read a rate. centerRate=reader.readI(); + legacyRate=centerRate; if (isNewSample) { centerRate=reader.readI(); diff --git a/src/engine/sample.h b/src/engine/sample.h index 9f30c44af..975eac6e0 100644 --- a/src/engine/sample.h +++ b/src/engine/sample.h @@ -104,6 +104,7 @@ struct DivSampleHistory { struct DivSample { String name; int centerRate, loopStart, loopEnd; + int legacyRate; // valid values are: // - 0: ZX Spectrum overlay drum (1-bit) // - 1: 1-bit NES DPCM (1-bit) @@ -338,6 +339,7 @@ struct DivSample { centerRate(8363), loopStart(-1), loopEnd(-1), + legacyRate(32000), depth(DIV_SAMPLE_DEPTH_16BIT), loop(false), brrEmphasis(true),