Mercurial > repos > blastem
comparison ym2612.c @ 2284:5a53a8453241
Fix envelope key scaling when CH3 special mode is active. Fixes sound effects in Toy Story and Maui Mallard
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Fri, 13 Jan 2023 01:02:08 -0800 |
parents | 74112041b2c7 |
children | 8a918eb95ba8 |
comparison
equal
deleted
inserted
replaced
2283:6f6f21d0c396 | 2284:5a53a8453241 |
---|---|
414 context->timer_control &= ~BIT_TIMERB_LOAD; | 414 context->timer_control &= ~BIT_TIMERB_LOAD; |
415 context->timer_b = context->timer_b_load; | 415 context->timer_b = context->timer_b_load; |
416 } | 416 } |
417 context->sub_timer_b += 0x10; | 417 context->sub_timer_b += 0x10; |
418 //Update LFO | 418 //Update LFO |
419 uint8_t old_pm_step = context->lfo_pm_step; | |
419 if (context->lfo_enable) { | 420 if (context->lfo_enable) { |
420 if (context->lfo_counter) { | 421 if (context->lfo_counter >= lfo_timer_values[context->lfo_freq]) { |
421 context->lfo_counter--; | 422 context->lfo_counter = 0; |
422 } else { | |
423 context->lfo_counter = lfo_timer_values[context->lfo_freq]; | |
424 context->lfo_am_step += 2; | 423 context->lfo_am_step += 2; |
425 context->lfo_am_step &= 0xFE; | 424 context->lfo_am_step &= 0xFE; |
426 uint8_t old_pm_step = context->lfo_pm_step; | |
427 context->lfo_pm_step = context->lfo_am_step / 8; | 425 context->lfo_pm_step = context->lfo_am_step / 8; |
428 if (context->lfo_pm_step != old_pm_step) { | 426 } else { |
429 for (int chan = 0; chan < NUM_CHANNELS; chan++) | 427 context->lfo_counter--; |
428 } | |
429 } else { | |
430 context->lfo_am_step = context->lfo_pm_step = 0; | |
431 } | |
432 if (context->lfo_pm_step != old_pm_step) { | |
433 for (int chan = 0; chan < NUM_CHANNELS; chan++) | |
434 { | |
435 if (context->channels[chan].pms) { | |
436 for (int op = chan * 4; op < (chan + 1) * 4; op++) | |
430 { | 437 { |
431 if (context->channels[chan].pms) { | 438 context->operators[op].phase_inc = ym_calc_phase_inc(context, context->operators + op, op); |
432 for (int op = chan * 4; op < (chan + 1) * 4; op++) | |
433 { | |
434 context->operators[op].phase_inc = ym_calc_phase_inc(context, context->operators + op, op); | |
435 } | |
436 } | |
437 } | 439 } |
438 } | 440 } |
439 } | 441 } |
440 } | 442 } |
441 } | 443 } |
448 //operator->envelope = operator->sustain_level; | 450 //operator->envelope = operator->sustain_level; |
449 operator->env_phase = PHASE_SUSTAIN; | 451 operator->env_phase = PHASE_SUSTAIN; |
450 } | 452 } |
451 rate = operator->rates[operator->env_phase]; | 453 rate = operator->rates[operator->env_phase]; |
452 if (rate) { | 454 if (rate) { |
453 uint8_t ks = channel->keycode >> operator->key_scaling;; | 455 uint8_t keycode = channel->keycode; |
456 if (context->ch3_mode) { | |
457 int opnum = operator - context->operators; | |
458 if (opnum >= 2 * 4 && opnum < 2 * 4 + 3) { | |
459 opnum &= 3; | |
460 if (opnum < 2) { | |
461 opnum ^= 1; | |
462 } | |
463 keycode = context->ch3_supp[opnum].keycode; | |
464 } | |
465 } | |
466 uint8_t ks = keycode >> operator->key_scaling; | |
454 rate = rate*2 + ks; | 467 rate = rate*2 + ks; |
455 if (rate > 63) { | 468 if (rate > 63) { |
456 rate = 63; | 469 rate = 63; |
457 } | 470 } |
458 } | 471 } |
860 /*if ((value & 0x8) && !context->lfo_enable) { | 873 /*if ((value & 0x8) && !context->lfo_enable) { |
861 printf("LFO Enabled, Freq: %d\n", value & 0x7); | 874 printf("LFO Enabled, Freq: %d\n", value & 0x7); |
862 }*/ | 875 }*/ |
863 context->lfo_enable = value & 0x8; | 876 context->lfo_enable = value & 0x8; |
864 if (!context->lfo_enable) { | 877 if (!context->lfo_enable) { |
865 uint8_t old_pm_step = context->lfo_pm_step; | 878 context->lfo_counter = 0; |
866 context->lfo_am_step = context->lfo_pm_step = 0; | |
867 if (old_pm_step) { | |
868 for (int chan = 0; chan < NUM_CHANNELS; chan++) | |
869 { | |
870 if (context->channels[chan].pms) { | |
871 for (int op = chan * 4; op < (chan + 1) * 4; op++) | |
872 { | |
873 context->operators[op].phase_inc = ym_calc_phase_inc(context, context->operators + op, op); | |
874 } | |
875 } | |
876 } | |
877 } | |
878 } | 879 } |
879 context->lfo_freq = value & 0x7; | 880 context->lfo_freq = value & 0x7; |
880 | 881 |
881 break; | 882 break; |
882 case REG_TIMERA_HIGH: | 883 case REG_TIMERA_HIGH: |