From adffea8dae3230cc43da194bf0a108462c6ca80e Mon Sep 17 00:00:00 2001 From: kub Date: Tue, 11 Jul 2023 21:43:00 +0000 Subject: [PATCH] 32x, improve pwm volume accuracy --- pico/32x/pwm.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pico/32x/pwm.c b/pico/32x/pwm.c index 1b10103a..e08ff026 100644 --- a/pico/32x/pwm.c +++ b/pico/32x/pwm.c @@ -34,7 +34,7 @@ void p32x_pwm_ctl_changed(void) // but mars test disagrees pwm.mult = 0; if ((control & 0x0f) != 0) - pwm.mult = 0x10000 / cycles; + pwm.mult = (0x10000<<8) / (cycles+1); pwm.irq_timer = (control & 0x0f00) >> 8; pwm.irq_timer = ((pwm.irq_timer - 1) & 0x0f) + 1; @@ -60,9 +60,7 @@ static int convert_sample(unsigned int v) { if (v > pwm.cycles) v = pwm.cycles; - if (v == 0) - return 0; - return v * pwm.mult - 0x10000/2; + return (v * pwm.mult >> 8) - 0x10000/2; } #define consume_fifo(sh2, m68k_cycles) { \ -- 2.39.5