From 4c0f0ddd24c0e0ef0df2d035d9fcc337f7164082 Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 1 Apr 2025 06:42:14 +0200 Subject: [PATCH] VIA AC'97: Restore the 0x47 back (turns out it was *NOT* a mix-up), but divide by 208925 instead of by 32767, in order to keep the maximum in the -32768 to 32767 range even at +12 dB gain. --- src/sound/snd_ac97_codec.c | 2 +- src/sound/snd_ac97_via.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/sound/snd_ac97_codec.c b/src/sound/snd_ac97_codec.c index 7a9951289..ad535591f 100644 --- a/src/sound/snd_ac97_codec.c +++ b/src/sound/snd_ac97_codec.c @@ -537,7 +537,7 @@ ac97_codec_getattn(void *priv, uint8_t reg, int *l, int *r) uint8_t r_val = val; if (reg <= 0x06) { /* 6-bit level */ *l = codec_attn[0x3f - (l_val & 0x3f)]; - *r = codec_attn[0x3f - (r_val & 0x3f)]; + *r = codec_attn[0x47 - (r_val & 0x3f)]; } else { /* 5-bit gain */ /* Yes, 0x3f is correct, the 0x47 was most likely a decimal-hex mix-up. */ *l = codec_attn[0x3f - (l_val & 0x1f)]; diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index 68ef5fe5d..2d994b08f 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -536,8 +536,13 @@ ac97_via_remap_modem_codec(void *priv, uint16_t new_io_base, uint8_t enable) static void ac97_via_update_stereo(ac97_via_t *dev, ac97_via_sgd_t *sgd) { +#ifdef OLD_CODE int32_t l = (((sgd->out_l * sgd->vol_l) >> 15) * dev->master_vol_l) >> 15; int32_t r = (((sgd->out_r * sgd->vol_r) >> 15) * dev->master_vol_r) >> 15; +#else + int32_t l = (((sgd->out_l * sgd->vol_l) / 208925) * dev->master_vol_l) >> 15; + int32_t r = (((sgd->out_r * sgd->vol_r) / 208925) * dev->master_vol_r) >> 15; +#endif if (l < -32768) l = -32768;