Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replaced disable PSG sound channel core options with volume adjust (#160) #165

Merged
merged 2 commits into from
Sep 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions libretro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ static int turbo_counter[MAX_PLAYERS][MAX_BUTTONS] = {};
static int Turbo_Delay;
static int Turbo_Toggling = 1;
static bool turbo_toggle_alt = false;
static bool disabled_channels[6] = { false };
static int psg_channels_volume[6] = { 100, 100, 100, 100, 100, 100 };
static int turbo_toggle_down[MAX_PLAYERS][MAX_BUTTONS] = {};

static void check_variables(void)
Expand Down Expand Up @@ -1297,16 +1297,13 @@ static void check_variables(void)
log_cb(RETRO_LOG_INFO, "PCE CD Audio settings changed.\n");
}

char pce_disable_sound_channel_base_str[] = "pce_disable_sound_channel_0";
var.key = pce_disable_sound_channel_base_str;
char pce_sound_channel_volume_base_str[] = "pce_sound_channel_0_volume";
var.key = pce_sound_channel_volume_base_str;
for (unsigned c = 0; c < 6; c++) {;
pce_disable_sound_channel_base_str[26] = c+'0';
pce_sound_channel_volume_base_str[18] = c+'0';
if (environ_cb(RETRO_ENVIRONMENT_GET_VARIABLE, &var) && var.value)
{
if (strcmp(var.value, "enabled") == 0)
disabled_channels[c] = true;
else
disabled_channels[c] = false;
psg_channels_volume[c] = atoi(var.value);
}
}

Expand Down Expand Up @@ -1461,10 +1458,7 @@ bool retro_load_game(const struct retro_game_info *info)
}

for (unsigned c = 0; c < 6; c++) {
if(disabled_channels[c])
psg->DisableChannel(c);
else
psg->EnableChannel(c);
psg->SetChannelUserVolume(c, psg_channels_volume[c]);
}

mmaps.descriptors = descs;
Expand Down Expand Up @@ -1694,12 +1688,9 @@ void retro_run(void)
psg->SetVolume(0.678 * setting_pce_fast_cdpsgvolume / 100);
}

for (unsigned c = 0; c < 6; c++) {
if(disabled_channels[c])
psg->DisableChannel(c);
else
psg->EnableChannel(c);
}
for (unsigned c = 0; c < 6; c++) {
psg->SetChannelUserVolume(c, psg_channels_volume[c]);
}

update_geometry(width, height);
}
Expand Down
162 changes: 108 additions & 54 deletions libretro_core_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,19 @@ struct retro_core_option_definition option_defs_us[] = {
},
"disabled"
},
{
"pce_cdspeed",
"(CD) CD Speed",
"Set the speed of the emulated CD drive.",
{
{ "1", NULL },
{ "2", NULL },
{ "4", NULL },
{ "8", NULL },
{ NULL, NULL },
},
"1"
},
{
"pce_cddavolume",
"(CD) CDDA Volume %",
Expand Down Expand Up @@ -319,83 +332,124 @@ struct retro_core_option_definition option_defs_us[] = {
"100"
},
{
"pce_disable_sound_channel_0",
"Disable Sound Channel 0",
"",
{
{ "disabled", NULL },
{ "enabled", NULL },
{ NULL, NULL },
},
"disabled"
},
{
"pce_disable_sound_channel_1",
"Disable Sound Channel 1",
"",
"pce_sound_channel_0_volume",
"PSG Sound Channel 0 Volume %",
"Modify PSG Sound Channel 0 Volume %",
{
{ "disabled", NULL },
{ "enabled", NULL },
{ NULL, NULL },
{ "0", NULL },
{ "10", NULL },
{ "20", NULL },
{ "30", NULL },
{ "40", NULL },
{ "50", NULL },
{ "60", NULL },
{ "70", NULL },
{ "80", NULL },
{ "90", NULL },
{ "100", NULL },
{ NULL, NULL },
},
"disabled"
"100"
},
{
"pce_disable_sound_channel_2",
"Disable Sound Channel 2",
"",
"pce_sound_channel_1_volume",
"PSG Sound Channel 1 Volume %",
"Modify PSG Sound Channel 1 Volume %",
{
{ "disabled", NULL },
{ "enabled", NULL },
{ NULL, NULL },
{ "0", NULL },
{ "10", NULL },
{ "20", NULL },
{ "30", NULL },
{ "40", NULL },
{ "50", NULL },
{ "60", NULL },
{ "70", NULL },
{ "80", NULL },
{ "90", NULL },
{ "100", NULL },
{ NULL, NULL },
},
"disabled"
"100"
},
{
"pce_disable_sound_channel_3",
"Disable Sound Channel 3",
"",
"pce_sound_channel_2_volume",
"PSG Sound Channel 2 Volume %",
"Modify PSG Sound Channel 2 Volume %",
{
{ "disabled", NULL },
{ "enabled", NULL },
{ NULL, NULL },
{ "0", NULL },
{ "10", NULL },
{ "20", NULL },
{ "30", NULL },
{ "40", NULL },
{ "50", NULL },
{ "60", NULL },
{ "70", NULL },
{ "80", NULL },
{ "90", NULL },
{ "100", NULL },
{ NULL, NULL },
},
"disabled"
"100"
},
{
"pce_disable_sound_channel_4",
"Disable Sound Channel 4",
"",
"pce_sound_channel_3_volume",
"PSG Sound Channel 3 Volume %",
"Modify PSG Sound Channel 3 Volume %",
{
{ "disabled", NULL },
{ "enabled", NULL },
{ NULL, NULL },
{ "0", NULL },
{ "10", NULL },
{ "20", NULL },
{ "30", NULL },
{ "40", NULL },
{ "50", NULL },
{ "60", NULL },
{ "70", NULL },
{ "80", NULL },
{ "90", NULL },
{ "100", NULL },
{ NULL, NULL },
},
"disabled"
"100"
},
{
"pce_disable_sound_channel_5",
"Disable Sound Channel 5",
"",
"pce_sound_channel_4_volume",
"PSG Sound Channel 4 Volume %",
"Modify PSG Sound Channel 4 Volume %",
{
{ "disabled", NULL },
{ "enabled", NULL },
{ NULL, NULL },
{ "0", NULL },
{ "10", NULL },
{ "20", NULL },
{ "30", NULL },
{ "40", NULL },
{ "50", NULL },
{ "60", NULL },
{ "70", NULL },
{ "80", NULL },
{ "90", NULL },
{ "100", NULL },
{ NULL, NULL },
},
"disabled"
"100"
},
{
"pce_cdspeed",
"(CD) CD Speed",
"Set the speed of the emulated CD drive.",
"pce_sound_channel_5_volume",
"PSG Sound Channel 5 Volume %",
"Modify PSG Sound Channel 5 Volume %",
{
{ "1", NULL },
{ "2", NULL },
{ "4", NULL },
{ "8", NULL },
{ "0", NULL },
{ "10", NULL },
{ "20", NULL },
{ "30", NULL },
{ "40", NULL },
{ "50", NULL },
{ "60", NULL },
{ "70", NULL },
{ "80", NULL },
{ "90", NULL },
{ "100", NULL },
{ NULL, NULL },
},
"1"
"100"
},
{
"pce_mouse_sensitivity",
Expand Down
40 changes: 12 additions & 28 deletions mednafen/pce_fast/psg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,11 @@ void PCEFast_PSG::SetVolume(double new_volume)
Blip_Synth_set_volume(&Synth, OutputVolume / 6, 8192);
}


void PCEFast_PSG::DisableChannel(int chnum)
void PCEFast_PSG::SetChannelUserVolume(int chnum, uint8 new_volume)
{
psg_channel *ch = &channel[chnum];
if(! ch ) return;
//printf("Disabled channel: %d\n", chnum);
if(chnum < 6)
ch->disabled = 1;
}

void PCEFast_PSG::EnableChannel(int chnum)
{
//printf("Enabled channel: %d\n", chnum);
if(chnum >=6 || new_volume > 100) return; // check valid args
psg_channel *ch = &channel[chnum];
if(! ch ) return;
if(chnum < 6)
ch->disabled = 0;
ch->user_volume = new_volume;
}

void PCEFast_PSG::UpdateOutput_Norm(const int32 timestamp, psg_channel *ch)
Expand All @@ -57,8 +45,8 @@ void PCEFast_PSG::UpdateOutput_Norm(const int32 timestamp, psg_channel *ch)
samp[0] = dbtable[ch->vl[0]][sv];
samp[1] = dbtable[ch->vl[1]][sv];

Blip_Synth_offset(&Synth, timestamp, samp[0] - ch->blip_prev_samp[0], sbuf[0]);
Blip_Synth_offset(&Synth, timestamp, samp[1] - ch->blip_prev_samp[1], sbuf[1]);
Blip_Synth_offset(&Synth, timestamp, (samp[0] - ch->blip_prev_samp[0]) * ch->user_volume / 100, sbuf[0]);
Blip_Synth_offset(&Synth, timestamp, (samp[1] - ch->blip_prev_samp[1]) * ch->user_volume / 100, sbuf[1]);

ch->blip_prev_samp[0] = samp[0];
ch->blip_prev_samp[1] = samp[1];
Expand All @@ -72,8 +60,8 @@ void PCEFast_PSG::UpdateOutput_Noise(const int32 timestamp, psg_channel *ch)
samp[0] = dbtable[ch->vl[0]][sv];
samp[1] = dbtable[ch->vl[1]][sv];

Blip_Synth_offset(&Synth, timestamp, samp[0] - ch->blip_prev_samp[0], sbuf[0]);
Blip_Synth_offset(&Synth, timestamp, samp[1] - ch->blip_prev_samp[1], sbuf[1]);
Blip_Synth_offset(&Synth, timestamp, (samp[0] - ch->blip_prev_samp[0]) * ch->user_volume / 100, sbuf[0]);
Blip_Synth_offset(&Synth, timestamp, (samp[1] - ch->blip_prev_samp[1]) * ch->user_volume / 100, sbuf[1]);

ch->blip_prev_samp[0] = samp[0];
ch->blip_prev_samp[1] = samp[1];
Expand All @@ -85,8 +73,8 @@ void PCEFast_PSG::UpdateOutput_Off(const int32 timestamp, psg_channel *ch)

samp[0] = samp[1] = 0;

Blip_Synth_offset(&Synth, timestamp, samp[0] - ch->blip_prev_samp[0], sbuf[0]);
Blip_Synth_offset(&Synth, timestamp, samp[1] - ch->blip_prev_samp[1], sbuf[1]);
Blip_Synth_offset(&Synth, timestamp, (samp[0] - ch->blip_prev_samp[0]) * ch->user_volume / 100, sbuf[0]);
Blip_Synth_offset(&Synth, timestamp, (samp[1] - ch->blip_prev_samp[1]) * ch->user_volume / 100, sbuf[1]);

ch->blip_prev_samp[0] = samp[0];
ch->blip_prev_samp[1] = samp[1];
Expand All @@ -100,8 +88,8 @@ void PCEFast_PSG::UpdateOutput_Accum(const int32 timestamp, psg_channel *ch)
samp[0] = ((int32)dbtable_volonly[ch->vl[0]] * ((int32)ch->samp_accum - 496)) >> (8 + 5);
samp[1] = ((int32)dbtable_volonly[ch->vl[1]] * ((int32)ch->samp_accum - 496)) >> (8 + 5);

Blip_Synth_offset(&Synth, timestamp, samp[0] - ch->blip_prev_samp[0], sbuf[0]);
Blip_Synth_offset(&Synth, timestamp, samp[1] - ch->blip_prev_samp[1], sbuf[1]);
Blip_Synth_offset(&Synth, timestamp, (samp[0] - ch->blip_prev_samp[0]) * ch->user_volume / 100, sbuf[0]);
Blip_Synth_offset(&Synth, timestamp, (samp[1] - ch->blip_prev_samp[1]) * ch->user_volume / 100, sbuf[1]);

ch->blip_prev_samp[0] = samp[0];
ch->blip_prev_samp[1] = samp[1];
Expand Down Expand Up @@ -246,8 +234,6 @@ void PCEFast_PSG::Write(int32 timestamp, uint8 A, uint8 V)

psg_channel *ch = &channel[select];

//if(ch->disabled) return;

//if(A == 0x01 || select == 5)
// printf("Write Ch: %d %04x %02x, %d\n", select, A, V, timestamp);

Expand Down Expand Up @@ -373,8 +359,6 @@ void PCEFast_PSG::RunChannel(int chc, int32 timestamp)
int32 run_time = timestamp - ch->lastts;

ch->lastts = timestamp;

if(ch->disabled) return;

if(!run_time)
return;
Expand Down Expand Up @@ -578,7 +562,7 @@ void PCEFast_PSG::Power(const int32 timestamp)
channel[ch].frequency = 0;
channel[ch].control = 0x00;
channel[ch].balance = 0;
channel[ch].disabled = 0;
channel[ch].user_volume = 100;
memset(channel[ch].waveform, 0, 32);
channel[ch].samp_accum = 0;

Expand Down
5 changes: 2 additions & 3 deletions mednafen/pce_fast/psg.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct psg_channel
uint16 frequency; /* Channel frequency */
uint8 balance; /* Channel balance */

bool disabled;
uint8 user_volume;
};

class PCEFast_PSG
Expand All @@ -47,8 +47,7 @@ class PCEFast_PSG
void Write(int32 timestamp, uint8 A, uint8 V);

void SetVolume(double new_volume) MDFN_COLD;
void EnableChannel(int chnum) MDFN_COLD;
void DisableChannel(int chnum) MDFN_COLD;
void SetChannelUserVolume(int chnum, uint8 new_volume) MDFN_COLD;

void EndFrame(int32 timestamp);

Expand Down