sound, add native rate mode, change resampling

This commit is contained in:
kub 2022-03-06 20:40:50 +00:00
parent d26d4c2965
commit 882f697ad4
11 changed files with 90 additions and 167 deletions

View file

@ -275,7 +275,7 @@ static int custom_read(menu_entry *me, const char *var, const char *val)
case MA_OPT_SOUND_QUALITY:
if (strcasecmp(var, "Sound Quality") != 0) return 0;
PicoIn.sndRate = strtoul(val, &tmp, 10);
if (PicoIn.sndRate < 8000 || PicoIn.sndRate > 44100)
if (PicoIn.sndRate < 8000 || PicoIn.sndRate > 53267)
PicoIn.sndRate = 22050;
if (*tmp == 'H' || *tmp == 'h') tmp++;
if (*tmp == 'Z' || *tmp == 'z') tmp++;

View file

@ -57,7 +57,7 @@ int pico_inp_mode;
int flip_after_sync;
int engineState = PGS_Menu;
static short __attribute__((aligned(4))) sndBuffer[2*44100/50];
static short __attribute__((aligned(4))) sndBuffer[2*53267/50];
/* tmp buff to reduce stack usage for plats with small stack */
static char static_buff[512];
@ -1328,6 +1328,9 @@ void emu_sound_start(void)
{
PicoIn.sndOut = NULL;
// auto-select rate?
if (PicoIn.sndRate > 52000)
PicoIn.sndRate = YM2612_NATIVE_RATE();
if (currentConfig.EmuOpt & EOPT_EN_SOUND)
{
int is_stereo = (PicoIn.opt & POPT_EN_STEREO) ? 1 : 0;

View file

@ -595,24 +595,24 @@ static int menu_loop_adv_options(int id, int keys)
static int sndrate_prevnext(int rate, int dir)
{
static const int rates[] = { 8000, 11025, 16000, 22050, 44100 };
static const int rates[] = { 8000, 11025, 16000, 22050, 44100, 53000 };
int i;
for (i = 0; i < 5; i++)
for (i = 0; i < 6; i++)
if (rates[i] == rate) break;
i += dir ? 1 : -1;
if (i > 4) {
if (i > 5) {
if (!(PicoIn.opt & POPT_EN_STEREO)) {
PicoIn.opt |= POPT_EN_STEREO;
return rates[0];
}
return rates[4];
return rates[5];
}
if (i < 0) {
if (PicoIn.opt & POPT_EN_STEREO) {
PicoIn.opt &= ~POPT_EN_STEREO;
return rates[4];
return rates[5];
}
return rates[0];
}
@ -630,7 +630,9 @@ static const char *mgn_opt_sound(int id, int *offs)
const char *str2;
*offs = -8;
str2 = (PicoIn.opt & POPT_EN_STEREO) ? "stereo" : "mono";
sprintf(static_buff, "%5iHz %s", PicoIn.sndRate, str2);
if (PicoIn.sndRate > 52000)
sprintf(static_buff, "native %s\n", str2);
else sprintf(static_buff, "%5iHz %s", PicoIn.sndRate, str2);
return static_buff;
}
@ -652,12 +654,14 @@ static const char *mgn_opt_alpha(int id, int *offs)
return static_buff;
}
static const char h_quality[] = "native is the FM sound chip rate (53267/52781 Hz),\n"
"select this for the best FM sound quality";
static const char h_lowpass[] = "Low pass filter for sound closer to real hardware";
static menu_entry e_menu_snd_options[] =
{
mee_onoff ("Enable sound", MA_OPT_ENABLE_SOUND, currentConfig.EmuOpt, EOPT_EN_SOUND),
mee_cust ("Sound Quality", MA_OPT_SOUND_QUALITY, mh_opt_snd, mgn_opt_sound),
mee_cust_h ("Sound Quality", MA_OPT_SOUND_QUALITY, mh_opt_snd, mgn_opt_sound, h_quality),
mee_onoff_h ("Sound filter", MA_OPT_SOUND_FILTER, PicoIn.opt, POPT_EN_SNDFILTER, h_lowpass),
mee_cust ("Filter strength", MA_OPT_SOUND_ALPHA, mh_opt_alpha, mgn_opt_alpha),
mee_end,
@ -667,6 +671,8 @@ static int menu_loop_snd_options(int id, int keys)
{
static int sel = 0;
if (PicoIn.sndRate > 52000)
PicoIn.sndRate = 53000;
me_loop(e_menu_snd_options, &sel);
return 0;