Unverified Commit c03061b3 authored by kps501's avatar kps501 Committed by GitHub
Browse files

libretro: rework interpolation

remove float, fix overmax, adjust base volume
parent a24a1ae5
......@@ -67,7 +67,7 @@ static retro_input_state_t input_state_cb = NULL;
static bool lufia2_credits_hack = false;
static uint16 *gfx_blend;
static float audio_interp_max = 32767.0;
static int audio_interp_max = 32768;
static int audio_interp_mode = 2;
static void extract_basename(char *buf, const char *path, size_t size)
......@@ -327,7 +327,7 @@ static void update_variables(void)
audio_interp_mode = 4;
if (oldval != audio_interp_mode)
audio_interp_max = 32767.0f;
audio_interp_max = 32768;
}
int disabled_channels=0;
......@@ -824,7 +824,9 @@ static bool LoadBIOS(uint8 *biosrom, const char *biosname, size_t biossize)
size_t size;
fseek(fp,0,SEEK_END);
if(ftell(fp)-0x200 == biossize)
size = ftell(fp);
if (size + 0x200 == biossize)
fseek(fp,0x200,SEEK_SET);
else
fseek(fp,0,SEEK_SET);
......@@ -898,10 +900,9 @@ void retro_load_init_reset()
Memory.RAM[lcv] = rand()%256;
}
audio_interp_max = 32767.0;
audio_interp_max = 32768;
}
bool retro_load_game(const struct retro_game_info *game)
{
init_descriptors();
......@@ -1736,8 +1737,8 @@ int libretro_snes_interp(void *ptr)
// linear
case 1:
output = v->buf[offset + 0];
output += v->buf[offset + 1];
output = (v->buf[offset + 0]) >> 1;
output += (v->buf[offset + 1]) >> 1;
break;
// gaussian
......@@ -1757,31 +1758,32 @@ int libretro_snes_interp(void *ptr)
// 12-bit ==> 11-bit table
poffset = (v->interp_pos >> 1) & 0x7ff;
output = (audio_fir_lut[poffset*8 + 0] * v->buf[offset + 0]) >> 11;
output += (audio_fir_lut[poffset*8 + 1] * v->buf[offset + 1]) >> 11;
output += (audio_fir_lut[poffset*8 + 2] * v->buf[offset + 2]) >> 11;
output += (audio_fir_lut[poffset*8 + 3] * v->buf[offset + 3]) >> 11;
output += (audio_fir_lut[poffset*8 + 4] * v->buf[offset + 4]) >> 11;
output += (audio_fir_lut[poffset*8 + 5] * v->buf[offset + 5]) >> 11;
output += (audio_fir_lut[poffset*8 + 6] * v->buf[offset + 6]) >> 11;
output += (audio_fir_lut[poffset*8 + 7] * v->buf[offset + 7]) >> 11;
output = (audio_fir_lut[poffset*8 + 0] * v->buf[offset + 0]) >> 14;
output += (audio_fir_lut[poffset*8 + 1] * v->buf[offset + 1]) >> 14;
output += (audio_fir_lut[poffset*8 + 2] * v->buf[offset + 2]) >> 14;
output += (audio_fir_lut[poffset*8 + 3] * v->buf[offset + 3]) >> 14;
output += (audio_fir_lut[poffset*8 + 4] * v->buf[offset + 4]) >> 14;
output += (audio_fir_lut[poffset*8 + 5] * v->buf[offset + 5]) >> 14;
output += (audio_fir_lut[poffset*8 + 6] * v->buf[offset + 6]) >> 14;
output += (audio_fir_lut[poffset*8 + 7] * v->buf[offset + 7]) >> 14;
break;
}
float temp_f;
while(1)
{
temp_f = (float) output;
temp_f *= 32767.0f / audio_interp_max;
int output_max = output;
output *= 32768;
output /= audio_interp_max;
if( temp_f > 32767.0f ) audio_interp_max = output;
else if( temp_f < -32768.0f ) audio_interp_max = -output;
else break;
if( output > 32767 )
{
audio_interp_max = output_max;
output = 32767;
}
output = (int) temp_f;
if( output > 32767 ) output = 32767;
if( output < -32768 ) output = -32768;
else if( output < -32768 )
{
audio_interp_max = -output_max;
output = -32768;
}
return output;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment