From 38bb36363d07a40f2d0e2b20b974337143917caf Mon Sep 17 00:00:00 2001 From: tildearrow Date: Sat, 19 Nov 2022 22:12:05 -0500 Subject: [PATCH] new ins format, part 4 --- papers/newIns.md | 4 +- src/engine/instrument.cpp | 167 +++++++++++++++++++++++++++++++++++++- src/engine/instrument.h | 4 +- 3 files changed, 170 insertions(+), 5 deletions(-) diff --git a/papers/newIns.md b/papers/newIns.md index 2250f0623..8ae5f6d82 100644 --- a/papers/newIns.md +++ b/papers/newIns.md @@ -308,7 +308,7 @@ size | description | - bit 4-6: decay | - bit 0-3: attack 1 | sustain/release - | - bit 5-6: sustain + | - bit 5-7: sustain | - bit 0-4: release 1 | flags | - bit 4: envelope on @@ -369,6 +369,7 @@ size | description size | description -----|------------------------------------ 1 | number of samples + 1?? | sample indexes... 4?? | pointers to samples... | - these use the Furnace sample format. ``` @@ -379,6 +380,7 @@ size | description size | description -----|------------------------------------ 1 | number of wavetables + 1?? | wavetable indexes... 4?? | pointers to wavetables... | - these use the Furnace wavetable format. ``` diff --git a/src/engine/instrument.cpp b/src/engine/instrument.cpp index df4390226..a11a9dabc 100644 --- a/src/engine/instrument.cpp +++ b/src/engine/instrument.cpp @@ -492,33 +492,196 @@ void DivInstrument::writeFeatureLD(SafeWriter* w) { } void DivInstrument::writeFeatureSN(SafeWriter* w) { + FEATURE_BEGIN("SN"); + + w->writeC(((snes.d&7)<<4)|(snes.a&15)); + w->writeC(((snes.s&7)<<5)|(snes.r&31)); + + w->writeC( + (snes.useEnv?16:0)| + (snes.sus?8:0)| + (snes.gainMode) + ); + + w->writeC(snes.gain); + + FEATURE_END; } void DivInstrument::writeFeatureN1(SafeWriter* w) { + FEATURE_BEGIN("N1"); + + w->writeI(n163.wave); + w->writeC(n163.wavePos); + w->writeC(n163.waveLen); + w->writeC(n163.waveMode); + + FEATURE_END; } void DivInstrument::writeFeatureFD(SafeWriter* w) { + FEATURE_BEGIN("FD"); + + w->writeI(fds.modSpeed); + w->writeI(fds.modDepth); + w->writeC(fds.initModTableWithFirstWave); + w->write(fds.modTable,32); + + FEATURE_END; } void DivInstrument::writeFeatureWS(SafeWriter* w) { + FEATURE_BEGIN("WS"); + + w->writeI(ws.wave1); + w->writeI(ws.wave2); + w->writeC(ws.rateDivider); + w->writeC(ws.effect); + w->writeC(ws.enabled); + w->writeC(ws.global); + w->writeC(ws.speed); + w->writeC(ws.param1); + w->writeC(ws.param2); + w->writeC(ws.param3); + w->writeC(ws.param4); + + FEATURE_END; } -void DivInstrument::writeFeatureSL(SafeWriter* w, std::vector& list, const DivSong* song) { +size_t DivInstrument::writeFeatureSL(SafeWriter* w, std::vector& list, const DivSong* song) { + FEATURE_BEGIN("SL"); + + bool sampleUsed[256]; + memset(sampleUsed,0,256*sizeof(bool)); + + if (amiga.initSample>=0 && amiga.initSample<(int)song->sample.size()) { + sampleUsed[amiga.initSample]=true; + } + + if (amiga.useNoteMap) { + for (int i=0; i<120; i++) { + if (amiga.noteMap[i].map>=0 && amiga.noteMap[i].map<(int)song->sample.size()) { + sampleUsed[amiga.noteMap[i].map]=true; + } + } + } + + for (size_t i=0; isample.size(); i++) { + if (sampleUsed[i]) { + list.push_back(i); + } + } + + w->writeC(list.size()); + + for (int i: list) { + w->writeC(i); + } + + size_t ret=w->tell(); + + // pointers (these will be filled later) + for (size_t i=0; iwriteI(0); + } + + FEATURE_END; + + return ret; } -void DivInstrument::writeFeatureWL(SafeWriter* w, std::vector& list, const DivSong* song) { +size_t DivInstrument::writeFeatureWL(SafeWriter* w, std::vector& list, const DivSong* song) { + FEATURE_BEGIN("WL"); + + bool waveUsed[256]; + memset(waveUsed,0,256*sizeof(bool)); + + for (int i=0; i=0 && std.waveMacro.val[i]<(int)song->wave.size()) { + waveUsed[std.waveMacro.val[i]]=true; + } + } + + if (ws.enabled) { + if (ws.wave1>=0 && ws.wave1<(int)song->wave.size()) { + waveUsed[ws.wave1]=true; + } + if ((ws.effect&0x80) && ws.wave2>=0 && ws.wave2<(int)song->wave.size()) { + waveUsed[ws.wave2]=true; + } + } + + for (size_t i=0; iwave.size(); i++) { + if (waveUsed[i]) { + list.push_back(i); + } + } + + w->writeC(list.size()); + + for (int i: list) { + w->writeC(i); + } + + size_t ret=w->tell(); + + // pointers (these will be filled later) + for (size_t i=0; iwriteI(0); + } + + FEATURE_END; + + return ret; } void DivInstrument::writeFeatureMP(SafeWriter* w) { + FEATURE_BEGIN("MP"); + + w->writeC(multipcm.ar); + w->writeC(multipcm.d1r); + w->writeC(multipcm.dl); + w->writeC(multipcm.d2r); + w->writeC(multipcm.rr); + w->writeC(multipcm.rc); + w->writeC(multipcm.lfo); + w->writeC(multipcm.vib); + w->writeC(multipcm.am); + + FEATURE_END; } void DivInstrument::writeFeatureSU(SafeWriter* w) { + FEATURE_BEGIN("SU"); + + w->writeC(su.switchRoles); + + FEATURE_END; } void DivInstrument::writeFeatureES(SafeWriter* w) { + FEATURE_BEGIN("ES"); + + w->writeC(es5506.filter.mode); + w->writeS(es5506.filter.k1); + w->writeS(es5506.filter.k2); + w->writeS(es5506.envelope.ecount); + w->writeC(es5506.envelope.lVRamp); + w->writeC(es5506.envelope.rVRamp); + w->writeC(es5506.envelope.k1Ramp); + w->writeC(es5506.envelope.k2Ramp); + w->writeC(es5506.envelope.k1Slow); + w->writeC(es5506.envelope.k2Slow); + + FEATURE_END; } void DivInstrument::writeFeatureX1(SafeWriter* w) { + FEATURE_BEGIN("X1"); + + w->writeI(x1_010.bankSlot); + + FEATURE_END; } void DivInstrument::putInsData2(SafeWriter* w, bool fui, const DivSong* song) { diff --git a/src/engine/instrument.h b/src/engine/instrument.h index 8fac58e0f..030a59043 100644 --- a/src/engine/instrument.h +++ b/src/engine/instrument.h @@ -655,8 +655,8 @@ struct DivInstrument { void writeFeatureN1(SafeWriter* w); void writeFeatureFD(SafeWriter* w); void writeFeatureWS(SafeWriter* w); - void writeFeatureSL(SafeWriter* w, std::vector& list, const DivSong* song); - void writeFeatureWL(SafeWriter* w, std::vector& list, const DivSong* song); + size_t writeFeatureSL(SafeWriter* w, std::vector& list, const DivSong* song); + size_t writeFeatureWL(SafeWriter* w, std::vector& list, const DivSong* song); void writeFeatureMP(SafeWriter* w); void writeFeatureSU(SafeWriter* w); void writeFeatureES(SafeWriter* w);