Skip to content

Commit

Permalink
sound: fix ym2612 forgetting lfo state when dac is on
Browse files Browse the repository at this point in the history
for less bad audio in OD2
  • Loading branch information
notaz committed Jun 16, 2023
1 parent 8013663 commit 76e87f9
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pico/sound/ym2612.c
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,8 @@ typedef struct
UINT16 vol_out2;
UINT16 vol_out3;
UINT16 vol_out4;
UINT32 pad[2];
UINT32 lfo_init_sft16;
UINT32 pad;
UINT32 phase1; /* 10 */
UINT32 phase2;
UINT32 phase3;
Expand Down Expand Up @@ -1225,18 +1226,18 @@ static chan_rend_context crct;
static void chan_render_prep(void)
{
crct.eg_timer_add = ym2612.OPN.eg_timer_add;
crct.lfo_init_sft16 = g_lfo_ampm << 16;
crct.lfo_inc = ym2612.OPN.lfo_inc;
}

static void chan_render_finish(s32 *buffer, unsigned short length, int active_chans)
static void chan_render_finish(s32 *buffer, int length, int active_chans)
{
ym2612.OPN.eg_cnt = crct.eg_cnt;
ym2612.OPN.eg_timer = crct.eg_timer;
g_lfo_ampm = crct.pack >> 16; // need_save
ym2612.OPN.lfo_cnt = crct.lfo_cnt;
ym2612.OPN.lfo_cnt += ym2612.OPN.lfo_inc * length;
}

static UINT32 update_lfo_phase(FM_SLOT *SLOT, UINT32 block_fnum)
static UINT32 update_lfo_phase(const FM_SLOT *SLOT, UINT32 block_fnum)
{
UINT32 fnum_lfo;
INT32 lfo_fn_table_index_offset;
Expand Down Expand Up @@ -1273,7 +1274,7 @@ static int chan_render(s32 *buffer, int length, int c, UINT32 flags) // flags: s

if (crct.lfo_inc) {
flags |= 8;
flags |= g_lfo_ampm << 16;
flags |= crct.lfo_init_sft16;
flags |= crct.CH->AMmasks << 8;
if (crct.CH->ams == 8) // no ams
flags &= ~0xf00;
Expand Down Expand Up @@ -1809,6 +1810,7 @@ int YM2612UpdateOne_(s32 *buffer, int length, int stereo, int is_buf_empty)
if (ym2612.slot_mask & 0x00f000) active_chs |= chan_render(buffer, length, 3, flags|((pan&0x0c0)>>2)) << 3;
BIT_IF(flags, 1, (ym2612.ssg_mask & 0x0f0000) && (ym2612.OPN.ST.flags & 1));
if (ym2612.slot_mask & 0x0f0000) active_chs |= chan_render(buffer, length, 4, flags|((pan&0x300)>>4)) << 4;
g_lfo_ampm = crct.pack >> 16; // need_save; now because ch5 might skip updating it
BIT_IF(flags, 1, (ym2612.ssg_mask & 0xf00000) && (ym2612.OPN.ST.flags & 1));
if (ym2612.slot_mask & 0xf00000) active_chs |= chan_render(buffer, length, 5, flags|((pan&0xc00)>>6)|(!!ym2612.dacen<<2)) << 5;
#undef BIT_IF
Expand Down

0 comments on commit 76e87f9

Please sign in to comment.