From 6ee927458284652fb0692d305bc2c2cf3bb4aec0 Mon Sep 17 00:00:00 2001 From: RichardG867 Date: Wed, 4 Aug 2021 01:00:44 -0300 Subject: [PATCH] VIA AC97: Change FM data format after an exhaustive probe --- src/sound/snd_ac97_via.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/sound/snd_ac97_via.c b/src/sound/snd_ac97_via.c index a09af6575..1707c0c9a 100644 --- a/src/sound/snd_ac97_via.c +++ b/src/sound/snd_ac97_via.c @@ -57,7 +57,7 @@ typedef struct _ac97_via_ { ac97_via_sgd_t sgd[6]; pc_timer_t timer_count, timer_count_fm; - uint64_t timer_latch; + uint64_t timer_latch, timer_latch_fm; int16_t out_l, out_r, fm_out_l, fm_out_r; int master_vol_l, master_vol_r, pcm_vol_l, pcm_vol_r, cd_vol_l, cd_vol_r; int32_t buffer[SOUNDBUFLEN * 2], fm_buffer[SOUNDBUFLEN * 2]; @@ -713,16 +713,18 @@ ac97_via_poll_fm(void *priv) /* Schedule next run if FM playback is enabled. */ if (dev->fm_enabled) - timer_advance_u64(&dev->timer_count_fm, dev->timer_latch); + timer_advance_u64(&dev->timer_count_fm, dev->timer_latch_fm); /* Update FM audio buffer. */ ac97_via_update_fm(dev); /* Feed next sample from the FIFO. - Unknown data format assumed to be 8-bit stereo. */ - if ((sgd->fifo_end - sgd->fifo_pos) >= 2) { - dev->fm_out_l = (sgd->fifo[sgd->fifo_pos++ & (sizeof(sgd->fifo) - 1)] ^ 0x80) << 8; - dev->fm_out_r = (sgd->fifo[sgd->fifo_pos++ & (sizeof(sgd->fifo) - 1)] ^ 0x80) << 8; + The data format is not documented, but it probes as 16-bit stereo at 24 KHz. */ + if ((sgd->fifo_end - sgd->fifo_pos) >= 4) { + dev->out_l = *((uint16_t *) &sgd->fifo[sgd->fifo_pos & (sizeof(sgd->fifo) - 1)]); + sgd->fifo_pos += 2; + dev->out_r = *((uint16_t *) &sgd->fifo[sgd->fifo_pos & (sizeof(sgd->fifo) - 1)]); + sgd->fifo_pos += 2; return; } @@ -772,6 +774,7 @@ ac97_via_speed_changed(void *priv) freq = 48000.0; dev->timer_latch = (uint64_t) ((double) TIMER_USEC * (1000000.0 / freq)); + dev->timer_latch_fm = (uint64_t) ((double) TIMER_USEC * (1000000.0 / 24000.0)); }