comparison ym2612.c @ 740:25c9e9d39997

Fix LFO counter update speed and implement amplitude modulation
author Michael Pavone <pavone@retrodev.com>
date Thu, 28 May 2015 00:11:15 -0700
parents 2317bdca03b4
children 3a18b5f63afc
comparison
equal deleted inserted replaced
739:2317bdca03b4 740:25c9e9d39997
105 {0, 0, 8, 0xc,0x10,0x10,0x14,0x18}, 105 {0, 0, 8, 0xc,0x10,0x10,0x14,0x18},
106 {0, 0,0x10,0x18,0x20,0x20,0x28,0x30}, 106 {0, 0,0x10,0x18,0x20,0x20,0x28,0x30},
107 {0, 0,0x20,0x30,0x40,0x40,0x50,0x60} 107 {0, 0,0x20,0x30,0x40,0x40,0x50,0x60}
108 }; 108 };
109 int16_t lfo_pm_table[128 * 32 * 8]; 109 int16_t lfo_pm_table[128 * 32 * 8];
110
111 uint16_t ams_shift[] = {8, 3, 1, 0};
110 112
111 #define MAX_ENVELOPE 0xFFC 113 #define MAX_ENVELOPE 0xFFC
112 #define YM_DIVIDER 2 114 #define YM_DIVIDER 2
113 #define CYCLE_NEVER 0xFFFFFFFF 115 #define CYCLE_NEVER 0xFFFFFFFF
114 116
266 context->status |= BIT_STATUS_TIMERB; 268 context->status |= BIT_STATUS_TIMERB;
267 } 269 }
268 context->timer_b = context->timer_b_load; 270 context->timer_b = context->timer_b_load;
269 } 271 }
270 } 272 }
271 } 273 //Update LFO
272 //Update LFO 274 if (context->lfo_enable) {
273 if (context->lfo_enable) { 275 if (context->lfo_counter) {
274 if (context->lfo_counter) { 276 context->lfo_counter--;
275 context->lfo_counter--; 277 } else {
276 } else { 278 context->lfo_counter = lfo_timer_values[context->lfo_freq];
277 context->lfo_counter = lfo_timer_values[context->lfo_freq]; 279 context->lfo_am_step += 2;
278 context->lfo_am_step += 2; 280 context->lfo_am_step &= 0xFE;
279 context->lfo_am_step &= 0xFE; 281 context->lfo_pm_step = context->lfo_am_step / 8;
280 context->lfo_pm_step = context->lfo_am_step / 8; 282 }
281 } 283 }
282 } 284 }
283 //Update Envelope Generator 285 //Update Envelope Generator
284 if (!(context->current_op % 3)) { 286 if (!(context->current_op % 3)) {
285 uint32_t env_cyc = context->env_counter; 287 uint32_t env_cyc = context->env_counter;
425 break; 427 break;
426 } 428 }
427 break; 429 break;
428 } 430 }
429 uint16_t env = operator->envelope + operator->total_level; 431 uint16_t env = operator->envelope + operator->total_level;
432 if (operator->am) {
433 uint16_t base_am = (context->lfo_am_step & 0x80 ? context->lfo_am_step : ~context->lfo_am_step) & 0x7E;
434 env += base_am >> ams_shift[chan->ams];
435 }
430 if (env > MAX_ENVELOPE) { 436 if (env > MAX_ENVELOPE) {
431 env = MAX_ENVELOPE; 437 env = MAX_ENVELOPE;
432 } 438 }
433 if (first_key_on) { 439 if (first_key_on) {
434 dfprintf(debug_file, "op %d, base phase: %d, mod: %d, sine: %d, out: %d\n", op, phase, mod, sine_table[(phase+mod) & 0x1FF], pow_table[sine_table[phase & 0x1FF] + env]); 440 dfprintf(debug_file, "op %d, base phase: %d, mod: %d, sine: %d, out: %d\n", op, phase, mod, sine_table[(phase+mod) & 0x1FF], pow_table[sine_table[phase & 0x1FF] + env]);