Skip to content

Commit

Permalink
added PSG channels volume core options (libretro#223)
Browse files Browse the repository at this point in the history
  • Loading branch information
eadmaster authored and eadmaster committed Nov 30, 2020
1 parent 681f3cd commit 0359e04
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 2 deletions.
13 changes: 11 additions & 2 deletions core/sound/psg.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ static struct
int chanDelta[4][2];
int chanOut[4][2];
int chanAmp[4][2];
int chanUserVolume[4];
} psg;

static void psg_update(unsigned int clocks);
Expand Down Expand Up @@ -378,6 +379,14 @@ void psg_write(unsigned int clocks, unsigned int data)
psg.regs[index] = data;
}

void psg_set_user_channel_volume(unsigned int channel, unsigned int volume)
{
if(channel > 3 || volume > 100) return; // invalid args
// else

psg.chanUserVolume[channel] = volume;
}

void psg_config(unsigned int clocks, unsigned int preamp, unsigned int panning)
{
int i;
Expand All @@ -398,8 +407,8 @@ void psg_config(unsigned int clocks, unsigned int preamp, unsigned int panning)
int volume = psg.regs[i*2+1];

/* update channel stereo amplification */
psg.chanAmp[i][0] = preamp * ((panning >> (i + 4)) & 1);
psg.chanAmp[i][1] = preamp * ((panning >> (i + 0)) & 1);
psg.chanAmp[i][0] = preamp * (psg.chanUserVolume[i]/100) * ((panning >> (i + 4)) & 1);
psg.chanAmp[i][1] = preamp * (psg.chanUserVolume[i]/100) * ((panning >> (i + 0)) & 1);

/* tone channels */
if (i < 3)
Expand Down
20 changes: 20 additions & 0 deletions libretro/libretro.c
Original file line number Diff line number Diff line change
Expand Up @@ -1540,6 +1540,26 @@ static void check_variables(bool first_run)
}
}

char sound_channel_volume_base_str[] = "genesis_plus_gx_psg_channel_0_volume";
var.key = sound_channel_volume_base_str;
for (unsigned c = 0; c < 4; c++) {
sound_channel_volume_base_str[28] = c+'0';
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var))
{
psg_set_user_channel_volume(c, atoi(var.value));
// need to recall config to have the settings applied
if ((system_hw & SYSTEM_PBC) == SYSTEM_MD)
{
psg_config(0, config.psg_preamp, 0xff);
}
else
{
psg_config(0, config.psg_preamp, io_reg[6]);
}
}
}


var.key = "genesis_plus_gx_fm_preamp";
environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var);
{
Expand Down
80 changes: 80 additions & 0 deletions libretro/libretro_core_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,86 @@ struct retro_core_option_definition option_defs_us[] = {
},
"disabled"
},
{
"genesis_plus_gx_psg_channel_0_volume",
"PSG Tone Channel 0 Volume %",
"",
{
{ "0", NULL },
{ "10", NULL },
{ "20", NULL },
{ "30", NULL },
{ "40", NULL },
{ "50", NULL },
{ "60", NULL },
{ "70", NULL },
{ "80", NULL },
{ "90", NULL },
{ "100", NULL },
{ NULL, NULL },
},
"100"
},
{
"genesis_plus_gx_psg_channel_1_volume",
"PSG Tone Channel 1 Volume %",
"",
{
{ "0", NULL },
{ "10", NULL },
{ "20", NULL },
{ "30", NULL },
{ "40", NULL },
{ "50", NULL },
{ "60", NULL },
{ "70", NULL },
{ "80", NULL },
{ "90", NULL },
{ "100", NULL },
{ NULL, NULL },
},
"100"
},
{
"genesis_plus_gx_psg_channel_2_volume",
"PSG Tone Channel 2 Volume %",
"",
{
{ "0", NULL },
{ "10", NULL },
{ "20", NULL },
{ "30", NULL },
{ "40", NULL },
{ "50", NULL },
{ "60", NULL },
{ "70", NULL },
{ "80", NULL },
{ "90", NULL },
{ "100", NULL },
{ NULL, NULL },
},
"100"
},
{
"genesis_plus_gx_psg_channel_3_volume",
"PSG Noise Channel 3 Volume %",
"",
{
{ "0", NULL },
{ "10", NULL },
{ "20", NULL },
{ "30", NULL },
{ "40", NULL },
{ "50", NULL },
{ "60", NULL },
{ "70", NULL },
{ "80", NULL },
{ "90", NULL },
{ "100", NULL },
{ NULL, NULL },
},
"100"
},
{ NULL, NULL, NULL, {{0}}, NULL },
};

Expand Down

0 comments on commit 0359e04

Please sign in to comment.