summaryrefslogtreecommitdiff
path: root/ym2612.c
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2015-05-28 00:11:15 -0700
committerMichael Pavone <pavone@retrodev.com>2015-05-28 00:11:15 -0700
commit391656eca9eb35b7e3937b2af1316460d5639306 (patch)
treef88c537f442116619101c789da2be9809511b846 /ym2612.c
parent38d85c1c95d0a4152a480baff4974622977dcfce (diff)
Fix LFO counter update speed and implement amplitude modulation
Diffstat (limited to 'ym2612.c')
-rw-r--r--ym2612.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/ym2612.c b/ym2612.c
index 2e273c0..a560c1a 100644
--- a/ym2612.c
+++ b/ym2612.c
@@ -108,6 +108,8 @@ uint8_t lfo_pm_base[][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 @@ void ym_run(ym2612_context * context, uint32_t to_cycle)
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 @@ void ym_run(ym2612_context * context, uint32_t to_cycle)
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;
}