# HG changeset patch # User Michael Pavone # Date 1432797075 25200 # Node ID 25c9e9d39997c29a94844c1cd7e18ed6443c6322 # Parent 2317bdca03b4724b8dd208acc75fbb5720c9f5ac Fix LFO counter update speed and implement amplitude modulation diff -r 2317bdca03b4 -r 25c9e9d39997 ym2612.c --- a/ym2612.c Wed May 27 20:53:21 2015 -0700 +++ b/ym2612.c Thu May 28 00:11:15 2015 -0700 @@ -108,6 +108,8 @@ }; int16_t lfo_pm_table[128 * 32 * 8]; +uint16_t ams_shift[] = {8, 3, 1, 0}; + #define MAX_ENVELOPE 0xFFC #define YM_DIVIDER 2 #define CYCLE_NEVER 0xFFFFFFFF @@ -268,16 +270,16 @@ context->timer_b = context->timer_b_load; } } - } - //Update LFO - if (context->lfo_enable) { - if (context->lfo_counter) { - context->lfo_counter--; - } else { - context->lfo_counter = lfo_timer_values[context->lfo_freq]; - context->lfo_am_step += 2; - context->lfo_am_step &= 0xFE; - context->lfo_pm_step = context->lfo_am_step / 8; + //Update LFO + if (context->lfo_enable) { + if (context->lfo_counter) { + context->lfo_counter--; + } else { + context->lfo_counter = lfo_timer_values[context->lfo_freq]; + context->lfo_am_step += 2; + context->lfo_am_step &= 0xFE; + context->lfo_pm_step = context->lfo_am_step / 8; + } } } //Update Envelope Generator @@ -427,6 +429,10 @@ break; } uint16_t env = operator->envelope + operator->total_level; + if (operator->am) { + uint16_t base_am = (context->lfo_am_step & 0x80 ? context->lfo_am_step : ~context->lfo_am_step) & 0x7E; + env += base_am >> ams_shift[chan->ams]; + } if (env > MAX_ENVELOPE) { env = MAX_ENVELOPE; }