comparison ym2612.c @ 1656:804f13c090b4

Optimize YM operator modulation
author Mike Pavone <pavone@retrodev.com>
date Sun, 30 Dec 2018 18:48:08 -0800
parents 4637ab86be8c
children 5278b6e44fc1
comparison
equal deleted inserted replaced
1655:3128d4e0bc68 1656:804f13c090b4
464 ym_operator * operator = context->operators + op; 464 ym_operator * operator = context->operators + op;
465 ym_channel * chan = context->channels + channel; 465 ym_channel * chan = context->channels + channel;
466 uint16_t phase = operator->phase_counter >> 10 & 0x3FF; 466 uint16_t phase = operator->phase_counter >> 10 & 0x3FF;
467 operator->phase_counter += ym_calc_phase_inc(context, operator, context->current_op); 467 operator->phase_counter += ym_calc_phase_inc(context, operator, context->current_op);
468 int16_t mod = 0; 468 int16_t mod = 0;
469 switch (op % 4) 469 if (op & 3) {
470 { 470 if (operator->mod_src[0]) {
471 case 0://Operator 1 471 mod = *operator->mod_src[0];
472 if (operator->mod_src[1]) {
473 mod += *
474 operator->mod_src[1];
475 }
476 mod >>= YM_MOD_SHIFT;
477 }
478 } else {
472 if (chan->feedback) { 479 if (chan->feedback) {
473 mod = (chan->op1_old + operator->output) >> (10-chan->feedback); 480 mod = (chan->op1_old + operator->output) >> (10-chan->feedback);
474 } 481 }
475 break;
476 case 1://Operator 3
477 switch(chan->algorithm)
478 {
479 case 0:
480 case 2:
481 //modulate by operator 2
482 mod = context->operators[op+1].output >> YM_MOD_SHIFT;
483 break;
484 case 1:
485 //modulate by operator 1+2
486 mod = (context->operators[op-1].output + context->operators[op+1].output) >> YM_MOD_SHIFT;
487 break;
488 case 5:
489 //modulate by operator 1
490 mod = context->operators[op-1].output >> YM_MOD_SHIFT;
491 }
492 break;
493 case 2://Operator 2
494 if (chan->algorithm != 1 && chan->algorithm != 2 && chan->algorithm != 7) {
495 //modulate by Operator 1
496 mod = context->operators[op-2].output >> YM_MOD_SHIFT;
497 }
498 break;
499 case 3://Operator 4
500 switch(chan->algorithm)
501 {
502 case 0:
503 case 1:
504 case 4:
505 //modulate by operator 3
506 mod = context->operators[op-2].output >> YM_MOD_SHIFT;
507 break;
508 case 2:
509 //modulate by operator 1+3
510 mod = (context->operators[op-3].output + context->operators[op-2].output) >> YM_MOD_SHIFT;
511 break;
512 case 3:
513 //modulate by operator 2+3
514 mod = (context->operators[op-1].output + context->operators[op-2].output) >> YM_MOD_SHIFT;
515 break;
516 case 5:
517 //modulate by operator 1
518 mod = context->operators[op-3].output >> YM_MOD_SHIFT;
519 break;
520 }
521 break;
522 } 482 }
523 uint16_t env = operator->envelope; 483 uint16_t env = operator->envelope;
524 if (operator->ssg) { 484 if (operator->ssg) {
525 if (env >= SSG_CENTER) { 485 if (env >= SSG_CENTER) {
526 if (operator->ssg & SSG_ALTERNATE) { 486 if (operator->ssg & SSG_ALTERNATE) {
934 context->ch3_supp[channel].block_fnum_latch = value; 894 context->ch3_supp[channel].block_fnum_latch = value;
935 } 895 }
936 break; 896 break;
937 case REG_ALG_FEEDBACK: 897 case REG_ALG_FEEDBACK:
938 context->channels[channel].algorithm = value & 0x7; 898 context->channels[channel].algorithm = value & 0x7;
899 switch (context->channels[channel].algorithm)
900 {
901 case 0:
902 //operator 3 modulated by operator 2
903 context->operators[channel*4+1].mod_src[0] = &context->operators[channel*4+2].output;
904 context->operators[channel*4+1].mod_src[1] = NULL;
905
906 //operator 2 modulated by operator 1
907 context->operators[channel*4+2].mod_src[0] = &context->operators[channel*4+0].output;
908
909 //operator 4 modulated by operator 3
910 context->operators[channel*4+3].mod_src[0] = &context->operators[channel*4+1].output;
911 context->operators[channel*4+3].mod_src[1] = NULL;
912 break;
913 case 1:
914 //operator 3 modulated by operator 1+2
915 context->operators[channel*4+1].mod_src[0] = &context->operators[channel*4+0].output;
916 context->operators[channel*4+1].mod_src[1] = &context->operators[channel*4+2].output;
917
918 //operator 2 unmodulated
919 context->operators[channel*4+2].mod_src[0] = NULL;
920
921 //operator 4 modulated by operator 3
922 context->operators[channel*4+3].mod_src[0] = &context->operators[channel*4+1].output;
923 context->operators[channel*4+3].mod_src[1] = NULL;
924 break;
925 case 2:
926 //operator 3 modulated by operator 2
927 context->operators[channel*4+1].mod_src[0] = &context->operators[channel*4+2].output;
928 context->operators[channel*4+1].mod_src[1] = NULL;
929
930 //operator 2 unmodulated
931 context->operators[channel*4+2].mod_src[0] = NULL;
932
933 //operator 4 modulated by operator 1+3
934 context->operators[channel*4+3].mod_src[0] = &context->operators[channel*4+0].output;
935 context->operators[channel*4+3].mod_src[1] = &context->operators[channel*4+1].output;
936 break;
937 case 3:
938 //operator 3 unmodulated
939 context->operators[channel*4+1].mod_src[0] = NULL;
940 context->operators[channel*4+1].mod_src[1] = NULL;
941
942 //operator 2 modulated by operator 1
943 context->operators[channel*4+2].mod_src[0] = &context->operators[channel*4+0].output;
944
945 //operator 4 modulated by operator 2+3
946 context->operators[channel*4+3].mod_src[0] = &context->operators[channel*4+2].output;
947 context->operators[channel*4+3].mod_src[1] = &context->operators[channel*4+1].output;
948 break;
949 case 4:
950 //operator 3 unmodulated
951 context->operators[channel*4+1].mod_src[0] = NULL;
952 context->operators[channel*4+1].mod_src[1] = NULL;
953
954 //operator 2 modulated by operator 1
955 context->operators[channel*4+2].mod_src[0] = &context->operators[channel*4+0].output;
956
957 //operator 4 modulated by operator 3
958 context->operators[channel*4+3].mod_src[0] = &context->operators[channel*4+1].output;
959 context->operators[channel*4+3].mod_src[1] = NULL;
960 break;
961 case 5:
962 //operator 3 modulated by operator 1
963 context->operators[channel*4+1].mod_src[0] = &context->operators[channel*4+0].output;
964 context->operators[channel*4+1].mod_src[1] = NULL;
965
966 //operator 2 modulated by operator 1
967 context->operators[channel*4+2].mod_src[0] = &context->operators[channel*4+0].output;
968
969 //operator 4 modulated by operator 1
970 context->operators[channel*4+3].mod_src[0] = &context->operators[channel*4+0].output;
971 context->operators[channel*4+3].mod_src[1] = NULL;
972 break;
973 case 6:
974 //operator 3 unmodulated
975 context->operators[channel*4+1].mod_src[0] = NULL;
976 context->operators[channel*4+1].mod_src[1] = NULL;
977
978 //operator 2 modulated by operator 1
979 context->operators[channel*4+2].mod_src[0] = &context->operators[channel*4+0].output;
980
981 //operator 4 unmodulated
982 context->operators[channel*4+3].mod_src[0] = NULL;
983 context->operators[channel*4+3].mod_src[1] = NULL;
984 break;
985 case 7:
986 //everything is an output so no modulation (except for op 1 feedback)
987 context->operators[channel*4+1].mod_src[0] = NULL;
988 context->operators[channel*4+1].mod_src[1] = NULL;
989
990 context->operators[channel*4+2].mod_src[0] = NULL;
991
992 context->operators[channel*4+3].mod_src[0] = NULL;
993 context->operators[channel*4+3].mod_src[1] = NULL;
994 break;
995 }
939 context->channels[channel].feedback = value >> 3 & 0x7; 996 context->channels[channel].feedback = value >> 3 & 0x7;
940 //printf("Algorithm %d, feedback %d for channel %d\n", value & 0x7, value >> 3 & 0x7, channel); 997 //printf("Algorithm %d, feedback %d for channel %d\n", value & 0x7, value >> 3 & 0x7, channel);
941 break; 998 break;
942 case REG_LR_AMS_PMS: 999 case REG_LR_AMS_PMS:
943 context->channels[channel].pms = (value & 0x7) * 32; 1000 context->channels[channel].pms = (value & 0x7) * 32;