VIC-20: add an option to disable filters

This commit is contained in:
Natt Akuma 2024-10-18 03:17:04 +07:00 committed by tildearrow
parent 9fbb7df674
commit 665b722f31
5 changed files with 36 additions and 6 deletions

View file

@ -92,6 +92,7 @@ int vic_sound_machine_calculate_samples(sound_vic20_t *snd, int16_t *pbuf, int n
int s = 0;
int i;
float o;
float v;
int16_t vicbuf;
int samples_to_do;
@ -100,9 +101,14 @@ int vic_sound_machine_calculate_samples(sound_vic20_t *snd, int16_t *pbuf, int n
snd->leftover_cycles += samples_to_do - snd->cycles_per_sample;
vic_sound_clock(snd, samples_to_do);
o = snd->lowpassbuf - snd->highpassbuf;
snd->highpassbuf += snd->highpassbeta * (snd->lowpassbuf - snd->highpassbuf);
snd->lowpassbuf += snd->lowpassbeta * (voltagefunction[(((snd->accum * 7) / snd->accum_cycles) + 1) * snd->volume] - snd->lowpassbuf);
v = voltagefunction[(((snd->accum * 7) / snd->accum_cycles) + 1) * snd->volume];
if (snd->filter_off) {
o = v;
} else {
o = snd->lowpassbuf - snd->highpassbuf;
snd->highpassbuf += snd->highpassbeta * (snd->lowpassbuf - snd->highpassbuf);
snd->lowpassbuf += snd->lowpassbeta * (v - snd->lowpassbuf);
}
if (o < -32768) {
vicbuf = -32768;
@ -202,7 +208,7 @@ void vic_sound_machine_store(sound_vic20_t *snd, uint16_t addr, uint8_t value)
}
}
int vic_sound_machine_init(sound_vic20_t *snd, int speed, int cycles_per_sec)
int vic_sound_machine_init(sound_vic20_t *snd, int speed, int cycles_per_sec, bool filter_off)
{
uint32_t i;
float dt;
@ -214,6 +220,7 @@ int vic_sound_machine_init(sound_vic20_t *snd, int speed, int cycles_per_sec)
snd->lowpassbuf = 0.0f;
snd->highpassbuf = 0.0f;
snd->filter_off = filter_off;
snd->speed = speed;

View file

@ -32,6 +32,7 @@ extern "C" {
#endif
#include <stdint.h>
#include <stdbool.h>
struct sound_vic20_s {
unsigned char div;
@ -56,13 +57,14 @@ struct sound_vic20_s {
float highpassbeta;
float lowpassbuf;
float lowpassbeta;
bool filter_off;
uint16_t noise_LFSR;
uint8_t noise_LFSR0_old;
};
typedef struct sound_vic20_s sound_vic20_t;
int vic_sound_machine_init(sound_vic20_t *snd, int speed, int cycles_per_sec);
int vic_sound_machine_init(sound_vic20_t *snd, int speed, int cycles_per_sec, bool filter_off);
void vic_sound_machine_store(sound_vic20_t *snd, uint16_t addr, uint8_t value);
int vic_sound_machine_calculate_samples(sound_vic20_t *snd, int16_t *pbuf, int nr, int soc, int scc, uint32_t delta_t);
void vic_sound_clock(sound_vic20_t *snd, uint32_t cycles);

View file

@ -317,7 +317,7 @@ void DivPlatformVIC20::reset() {
chan[i]=Channel();
chan[i].std.setEngine(parent);
}
vic_sound_machine_init(vic,rate,chipClock);
vic_sound_machine_init(vic,rate,chipClock,filterOff);
hasWaveWrite=false;
rWrite(14,15);
// hack: starting noise channel right away after this would result in a dead
@ -336,6 +336,7 @@ void DivPlatformVIC20::notifyInsDeletion(void* ins) {
}
void DivPlatformVIC20::setFlags(const DivConfig& flags) {
filterOff=flags.getBool("filterOff",false);
if (flags.getInt("clockSel",0)) {
chipClock=COLOR_PAL/4.0;
} else {

View file

@ -37,6 +37,7 @@ class DivPlatformVIC20: public DivDispatch {
DivDispatchOscBuffer* oscBuf[4];
bool isMuted[4];
bool hasWaveWrite;
bool filterOff;
unsigned char regPool[16];
sound_vic20_t* vic;

View file

@ -2612,6 +2612,25 @@ bool FurnaceGUI::drawSysConf(int chan, int sysPos, DivSystem type, DivConfig& fl
}
break;
}
case DIV_SYSTEM_VIC20: {
bool sysPal=flags.getInt("clockSel",0);
bool filterOff=flags.getBool("filterOff",false);
if (ImGui::Checkbox(_("PAL"),&sysPal)) {
altered=true;
}
if (ImGui::Checkbox(_("Disable filtering"),&filterOff)) {
altered=true;
}
if (altered) {
e->lockSave([&]() {
flags.set("clockSel",(int)sysPal);
flags.set("filterOff",filterOff);
});
}
break;
}
case DIV_SYSTEM_SWAN:
case DIV_SYSTEM_BUBSYS_WSG:
case DIV_SYSTEM_PET: