From 2e733034195915dd5fd065e01039b2a03e444bc2 Mon Sep 17 00:00:00 2001 From: meepingsnesroms Date: Sat, 20 Oct 2018 15:55:31 -0700 Subject: [PATCH] Fix how duty cycle is used --- src/emulator.h | 2 +- src/hardwareRegistersAccessors.c.h | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/emulator.h b/src/emulator.h index f853499..eb30f25 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -120,7 +120,7 @@ typedef struct{ //system constants #define CRYSTAL_FREQUENCY 32768 -#define AUDIO_AMPLITUDE INT16_MAX +#define AUDIO_AMPLITUDE 1000000 #define AUDIO_SAMPLES_PER_FRAME (AUDIO_SAMPLE_RATE / EMU_FPS) #define AUDIO_END_OF_FRAME 1000000000//used to convert the variable timing of SYSCLK and CLK32 to a fixed location in the current frame 0<->AUDIO_END_OF_FRAME #define AUDIO_WAIT_FOR_SAMPLE INT32_MIN diff --git a/src/hardwareRegistersAccessors.c.h b/src/hardwareRegistersAccessors.c.h index fda82ce..4a52a0b 100644 --- a/src/hardwareRegistersAccessors.c.h +++ b/src/hardwareRegistersAccessors.c.h @@ -85,19 +85,19 @@ int32_t pwm1FifoRunSample(int32_t now, int32_t clockOffset){ uint8_t prescaler = (pwmc1 >> 8 & 0x7F) + 1; uint8_t clockDivider = 2 << (pwmc1 & 0x03); uint8_t repeat = 1 << (pwmc1 >> 2 & 0x03); - double dutyCycle = dMin((double)sample / period, 1.0); int32_t audioStart = now + clockOffset; int32_t audioNow = audioStart; int32_t audioSampleDuration = usingClk32 ? audioGetFramePercentIncrementFromClk32s(period * prescaler * clockDivider) : audioGetFramePercentIncrementFromSysclks(period * prescaler * clockDivider); - int32_t audioDutyCycle = audioSampleDuration * dutyCycle; + int32_t audioDeew = dMin((double)sample / period, 1.0)/*dutyCycle*/ * AUDIO_AMPLITUDE; for(uint8_t times = 0; times < repeat; times++){ //At the beginning of a sample period cycle, the PWMO pin is set to 1 and the counter begins counting up from 0x00. //The sample value is compared on each count of the prescaler clock. //When the sample and count values match, the PWMO signal is cleared to 0. //MC68VZ328UM.pdf - blip_add_delta(palmAudioResampler, audioNow, AUDIO_AMPLITUDE); - blip_add_delta(palmAudioResampler, audioNow + audioDutyCycle, -AUDIO_AMPLITUDE); + //debugLog("Audio sample played, dutyCycle:%f, start:%d, end:%d\n", dutyCycle, audioNow, audioNow + audioDutyCycle); + blip_add_delta(palmAudioResampler, audioNow, audioDeew); + blip_add_delta(palmAudioResampler, audioNow + audioSampleDuration, -audioDeew); audioNow += audioSampleDuration; }