Skip to content

Commit

Permalink
frontend: Restore linear interpolation for audio output resampling
Browse files Browse the repository at this point in the history
Also, do it smarter this time. This seems to have gone missing with the
doublemelon merge.
  • Loading branch information
nadiaholmquist committed Jul 7, 2024
1 parent 25b5ac9 commit 1302cbd
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/frontend/qt_sdl/EmuInstanceAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,21 @@ int EmuInstance::audioGetNumSamplesOut(int outlen)
void EmuInstance::audioResample(s16* inbuf, int inlen, s16* outbuf, int outlen, int volume)
{
float res_incr = inlen / (float)outlen;
float res_timer = 0;
float res_timer = -0.5;
int res_pos = 0;

for (int i = 0; i < outlen; i++)
{
outbuf[i*2 ] = (inbuf[res_pos*2 ] * volume) >> 8;
outbuf[i*2+1] = (inbuf[res_pos*2+1] * volume) >> 8;
s16 l1 = inbuf[res_pos * 2];
s16 l2 = inbuf[res_pos * 2 + 2];
s16 r1 = inbuf[res_pos * 2 + 1];
s16 r2 = inbuf[res_pos * 2 + 3];

float l = (float) l1 + ((l2 - l1) * res_timer);
float r = (float) r1 + ((r2 - r1) * res_timer);

outbuf[i*2 ] = (s16) (((s32) round(l) * volume) >> 8);
outbuf[i*2+1] = (s16) (((s32) round(r) * volume) >> 8);

res_timer += res_incr;
while (res_timer >= 1.0)
Expand Down

0 comments on commit 1302cbd

Please sign in to comment.