From bbd55993d590f9971a33310135949a048f2d533a Mon Sep 17 00:00:00 2001 From: meepingsnesroms Date: Mon, 12 Nov 2018 13:22:12 -0800 Subject: [PATCH] Change how inductor resets, fixes most popping when playing constant tones --- src/audio/blip_buf.c | 2 +- src/audio/inductor.c | 27 ++++----------------------- src/audio/inductor.h | 6 ------ src/emulator.c | 12 ------------ src/hardwareRegistersAccessors.c.h | 8 ++------ 5 files changed, 7 insertions(+), 48 deletions(-) diff --git a/src/audio/blip_buf.c b/src/audio/blip_buf.c index 362eede..f62be5a 100644 --- a/src/audio/blip_buf.c +++ b/src/audio/blip_buf.c @@ -42,7 +42,7 @@ enum { time_bits = pre_shift + 20 }; static fixed_t const time_unit = (fixed_t) 1 << time_bits; -enum { bass_shift = 9 }; /* affects high-pass filter breakpoint frequency */ +enum { bass_shift = 2 }; /* affects high-pass filter breakpoint frequency */ enum { end_frame_extra = 2 }; /* allows deltas slightly after frame length */ enum { half_width = 8 }; diff --git a/src/audio/inductor.c b/src/audio/inductor.c index b2d4103..0259e9c 100644 --- a/src/audio/inductor.c +++ b/src/audio/inductor.c @@ -9,40 +9,21 @@ #define INDUCTOR_SPEAKER_RANGE 0x6000//prevent hitting the top or bottom of the speaker when switching direction rapidly -float inductorCurrentCharge; -float inductorChargeAtLastSample; - - -void inductorReset(void){ - inductorCurrentCharge = 0.0; - inductorChargeAtLastSample = 0.0; -} - void inductorPwmDutyCycle(int32_t now, int32_t clocks, float dutyCycle){ int32_t onClocks = clocks * dutyCycle; int32_t offClocks = clocks * (1.00 - dutyCycle); + float inductorCurrentCharge; + float inductorChargeAtLastSample; #if !defined(EMU_NO_SAFETY) if(now + clocks >= AUDIO_CLOCK_RATE) return; #endif - inductorCurrentCharge = fMin(inductorCurrentCharge + onClocks * INDUCTOR_CLOCK_POWER, 1.0); - blip_add_delta(palmAudioResampler, now, (inductorCurrentCharge - inductorChargeAtLastSample) * INDUCTOR_SPEAKER_RANGE); + inductorCurrentCharge = fMin(onClocks * INDUCTOR_CLOCK_POWER, 1.0); + blip_add_delta(palmAudioResampler, now, inductorCurrentCharge * INDUCTOR_SPEAKER_RANGE); inductorChargeAtLastSample = inductorCurrentCharge; inductorCurrentCharge = fMax(-1.0, inductorCurrentCharge - offClocks * INDUCTOR_CLOCK_POWER); blip_add_delta(palmAudioResampler, now + onClocks, (inductorCurrentCharge - inductorChargeAtLastSample) * INDUCTOR_SPEAKER_RANGE); - inductorChargeAtLastSample = inductorCurrentCharge; -} - -void inductorPwmOff(int32_t now, int32_t clocks){ - //drift towards 0 - if(inductorCurrentCharge > 0.0) - inductorCurrentCharge = fMax(0.0, inductorCurrentCharge - clocks * INDUCTOR_CLOCK_POWER); - else - inductorCurrentCharge = fMin(inductorCurrentCharge + clocks * INDUCTOR_CLOCK_POWER, 0.0); - - blip_add_delta(palmAudioResampler, now, (inductorCurrentCharge - inductorChargeAtLastSample) * INDUCTOR_SPEAKER_RANGE); - inductorChargeAtLastSample = inductorCurrentCharge; } diff --git a/src/audio/inductor.h b/src/audio/inductor.h index 511da83..6b23bba 100644 --- a/src/audio/inductor.h +++ b/src/audio/inductor.h @@ -3,12 +3,6 @@ #include -extern float inductorCurrentCharge; -extern float inductorChargeAtLastSample; - -void inductorReset(void); - void inductorPwmDutyCycle(int32_t now, int32_t clocks, float dutyCycle); -void inductorPwmOff(int32_t now, int32_t clocks); #endif diff --git a/src/emulator.c b/src/emulator.c index 9ad4c01..9b9b88f 100644 --- a/src/emulator.c +++ b/src/emulator.c @@ -4,7 +4,6 @@ #include #include "audio/blip_buf.h" -#include "audio/inductor.h" #include "flx68000.h" #include "emulator.h" #include "hardwareRegisters.h" @@ -111,7 +110,6 @@ uint32_t emulatorInit(buffer_t palmRomDump, buffer_t palmBootDump, uint32_t spec sed1376Reset(); ads7846Reset(); pdiUsbD12Reset(); - inductorReset(); sandboxInit(); memset(&palmInput, 0x00, sizeof(palmInput)); @@ -157,7 +155,6 @@ void emulatorHardReset(void){ sed1376Reset(); ads7846Reset(); pdiUsbD12Reset(); - inductorReset(); setRtc(0, 0, 0, 0); } @@ -203,7 +200,6 @@ uint64_t emulatorGetStateSize(void){ size += sizeof(int32_t);//pwm1ClocksToNextSample size += sizeof(uint8_t) * 6;//pwm1Fifo[6] size += sizeof(uint8_t) * 2;//pwm1(Read/Write) - size += sizeof(uint64_t) * 2;//inductorCurrentCharge / inductorChargeAtLastSample size += sizeof(uint8_t) * 7;//palmMisc size += sizeof(uint32_t);//palmSdCard.command size += sizeof(uint8_t) * 2;//palmSdCard.response / palmSdCard.commandBitsRemaining @@ -330,10 +326,6 @@ bool emulatorSaveState(buffer_t buffer){ offset += sizeof(uint8_t); writeStateValue8(buffer.data + offset, pwm1WritePosition); offset += sizeof(uint8_t); - writeStateValueDouble(buffer.data + offset, inductorCurrentCharge); - offset += sizeof(uint64_t); - writeStateValueDouble(buffer.data + offset, inductorChargeAtLastSample); - offset += sizeof(uint64_t); //misc writeStateValueBool(buffer.data + offset, palmMisc.powerButtonLed); @@ -487,10 +479,6 @@ bool emulatorLoadState(buffer_t buffer){ offset += sizeof(uint8_t); pwm1WritePosition = readStateValue8(buffer.data + offset); offset += sizeof(uint8_t); - inductorCurrentCharge = readStateValueDouble(buffer.data + offset); - offset += sizeof(uint64_t); - inductorChargeAtLastSample = readStateValueDouble(buffer.data + offset); - offset += sizeof(uint64_t); //misc palmMisc.powerButtonLed = readStateValueBool(buffer.data + offset); diff --git a/src/hardwareRegistersAccessors.c.h b/src/hardwareRegistersAccessors.c.h index c04fd86..d72a896 100644 --- a/src/hardwareRegistersAccessors.c.h +++ b/src/hardwareRegistersAccessors.c.h @@ -621,8 +621,8 @@ static void samplePwm1(bool forClk32, double sysclks){ int32_t audioNow; int32_t audioClocks; - //check if enabled and validate clock mode, CLK32 is used if PLL is disabled as the inductor still needs to settle - if(forClk32 != !!(pwmc1 & 0x8000) && !(forClk32 && palmSysclksPerClk32 < 1.0)) + //check if enabled and validate clock mode + if(forClk32 != !!(pwmc1 & 0x8000)) return; //these calculations are fairly heavy, only do them after we know the clock mode is valid @@ -642,10 +642,6 @@ static void samplePwm1(bool forClk32, double sysclks){ audioNow += audioUsed; } } - else{ - //PWM1 not enabled - inductorPwmOff(audioNow, audioClocks); - } } static uint16_t getPwmc1(void){