mirror of
https://github.com/libretro/Mu.git
synced 2026-09-23 07:05:37 +00:00
Change how inductor resets, fixes most popping when playing constant tones
This commit is contained in:
@@ -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 };
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -3,12 +3,6 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
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
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include <string.h>
|
||||
|
||||
#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);
|
||||
|
||||
@@ -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){
|
||||
|
||||
Reference in New Issue
Block a user