From b812fc4041aea75fecd77b140d1d1a9a277c72c8 Mon Sep 17 00:00:00 2001 From: tildearrow Date: Thu, 27 Jan 2022 16:52:06 -0500 Subject: [PATCH] prepare for sample C-4 freq issue #70 --- papers/format.md | 3 ++- src/engine/engine.cpp | 13 +++++++++---- src/engine/engine.h | 4 ++-- src/engine/platform/pce.cpp | 21 +++++++++++++-------- src/engine/sample.h | 3 ++- src/gui/gui.cpp | 8 ++++++-- 6 files changed, 34 insertions(+), 18 deletions(-) diff --git a/papers/format.md b/papers/format.md index d60dc0a15..a9b7166bb 100644 --- a/papers/format.md +++ b/papers/format.md @@ -285,7 +285,8 @@ size | description 2 | volume 2 | pitch 1 | depth - 3 | reserved + 1 | reserved + 2 | C-4 rate (>=32) 4 | loop point (>=19) | - -1 means no loop 2?? | sample data (always 16-bit) diff --git a/src/engine/engine.cpp b/src/engine/engine.cpp index 17d1053f0..657fa79ef 100644 --- a/src/engine/engine.cpp +++ b/src/engine/engine.cpp @@ -1425,7 +1425,13 @@ bool DivEngine::loadFur(unsigned char* file, size_t len) { sample->depth=reader.readC(); // reserved - for (int j=0; j<3; j++) reader.readC(); + reader.readC(); + + if (ds.version>=32) { + sample->centerRate=reader.readS(); + } else { + reader.readS(); + } if (ds.version>=19) { sample->loopStart=reader.readI(); @@ -1757,9 +1763,8 @@ SafeWriter* DivEngine::saveFur() { w->writeS(sample->vol); w->writeS(sample->pitch); w->writeC(sample->depth); - for (int j=0; j<3; j++) { // reserved - w->writeC(0); - } + w->writeC(0); + w->writeS(sample->centerRate); w->writeI(sample->loopStart); w->write(sample->data,sample->length*2); diff --git a/src/engine/engine.h b/src/engine/engine.h index d79404713..340e38014 100644 --- a/src/engine/engine.h +++ b/src/engine/engine.h @@ -11,8 +11,8 @@ #include #include -#define DIV_VERSION "0.5pre2" -#define DIV_ENGINE_VERSION 31 +#define DIV_VERSION "0.5pre3" +#define DIV_ENGINE_VERSION 32 enum DivStatusView { DIV_STATUS_NOTHING=0, diff --git a/src/engine/platform/pce.cpp b/src/engine/platform/pce.cpp index 59ebc08f5..2b957928d 100644 --- a/src/engine/platform/pce.cpp +++ b/src/engine/platform/pce.cpp @@ -20,8 +20,8 @@ void DivPlatformPCE::acquire(short* bufL, short* bufR, size_t start, size_t len) // PCM part for (int i=0; i<6; i++) { if (chan[i].pcm && chan[i].dacSample!=-1) { - chan[i].dacPeriod-=6; - if (chan[i].dacPeriod<1) { + chan[i].dacPeriod+=chan[i].dacRate; + if (chan[i].dacPeriod>rate) { DivSample* s=parent->song.sample[chan[i].dacSample]; if (s->rendLength<=0) { chan[i].dacSample=-1; @@ -42,7 +42,7 @@ void DivPlatformPCE::acquire(short* bufL, short* bufR, size_t start, size_t len) chan[i].dacSample=-1; } } - chan[i].dacPeriod+=chan[i].dacRate; + chan[i].dacPeriod-=rate; } } } @@ -100,7 +100,11 @@ void DivPlatformPCE::tick() { chan[i].std.next(); if (chan[i].std.hadVol) { chan[i].outVol=((chan[i].vol&31)*chan[i].std.vol)>>5; - chWrite(i,0x04,0x80|chan[i].outVol); + if (chan[i].furnaceDac) { + // ignore for now + } else { + chWrite(i,0x04,0x80|chan[i].outVol); + } } if (chan[i].std.hadArp) { if (!chan[i].inPorta) { @@ -132,8 +136,8 @@ void DivPlatformPCE::tick() { //DivInstrument* ins=parent->getIns(chan[i].ins); chan[i].freq=parent->calcFreq(chan[i].baseFreq,chan[i].pitch,true); if (chan[i].furnaceDac) { - chan[i].dacRate=chan[i].freq; - if (dumpWrites) addWrite(0xffff0001+(i<<8),1789773/chan[i].dacRate); + chan[i].dacRate=1789773/chan[i].freq; + if (dumpWrites) addWrite(0xffff0001+(i<<8),chan[i].dacRate); } if (chan[i].freq>4095) chan[i].freq=4095; if (chan[i].note>0x5d) chan[i].freq=0x01; @@ -187,6 +191,7 @@ int DivPlatformPCE::dispatch(DivCommand c) { chan[c.chan].note=c.value; } chan[c.chan].active=true; + chan[c.chan].std.init(ins); //chan[c.chan].keyOn=true; chan[c.chan].furnaceDac=true; } else { @@ -200,10 +205,10 @@ int DivPlatformPCE::dispatch(DivCommand c) { } chan[c.chan].dacPos=0; chan[c.chan].dacPeriod=0; - chan[c.chan].dacRate=1789773/parent->song.sample[chan[c.chan].dacSample]->rate; + chan[c.chan].dacRate=parent->song.sample[chan[c.chan].dacSample]->rate; if (dumpWrites) { chWrite(c.chan,0x04,0xdf); - addWrite(0xffff0001+(c.chan<<8),1789773/chan[c.chan].dacRate); + addWrite(0xffff0001+(c.chan<<8),chan[c.chan].dacRate); } chan[c.chan].furnaceDac=false; } diff --git a/src/engine/sample.h b/src/engine/sample.h index 6d7581b44..7afb011e1 100644 --- a/src/engine/sample.h +++ b/src/engine/sample.h @@ -2,7 +2,7 @@ struct DivSample { String name; - int length, rate, loopStart, loopOffP; + int length, rate, centerRate, loopStart, loopOffP; signed char vol, pitch; unsigned char depth; short* data; @@ -15,6 +15,7 @@ struct DivSample { name(""), length(0), rate(32000), + centerRate(8363), loopStart(-1), loopOffP(0), vol(0), diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index e71a2797d..e4cd32322 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -1882,10 +1882,14 @@ void FurnaceGUI::drawSampleEdit() { DivSample* sample=e->song.sample[curSample]; ImGui::InputText("Name",&sample->name); ImGui::Text("Length: %d",sample->length); - if (ImGui::SliderInt("Rate",&sample->rate,4000,32000,"%dHz")) { - if (sample->rate<4000) sample->rate=4000; + if (ImGui::InputInt("Rate (Hz)",&sample->rate,10,200)) { + if (sample->rate<100) sample->rate=100; if (sample->rate>32000) sample->rate=32000; } + if (ImGui::InputInt("Pitch of C-4 (Hz)",&sample->centerRate,10,200)) { + if (sample->centerRate<100) sample->centerRate=100; + if (sample->centerRate>32000) sample->centerRate=32000; + } ImGui::Text("effective rate: %dHz",e->getEffectiveSampleRate(sample->rate)); bool doLoop=(sample->loopStart>=0); if (ImGui::Checkbox("Loop",&doLoop)) {