Fix how duty cycle is used

This commit is contained in:
meepingsnesroms
2018-10-20 15:55:31 -07:00
parent 0a9a7ae3a1
commit 2e73303419
2 changed files with 5 additions and 5 deletions

View File

@@ -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

View File

@@ -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;
}