gigaherz' improved resampler

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@228 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
hrydgard 2008-08-16 22:28:33 +00:00
parent aa3fee8c60
commit 471bb025b2
1 changed files with 60 additions and 8 deletions

View File

@ -78,7 +78,10 @@ void Mixer_PushSamples(short *buffer, int num_stereo_samples, int sample_rate) {
// if (!f)
// f = fopen("d:\\hello.raw", "wb");
// fwrite(buffer, num_stereo_samples * 4, 1, f);
static int fraction = 0;
static int PV1l=0,PV2l=0,PV3l=0,PV4l=0;
static int PV1r=0,PV2r=0,PV3r=0,PV4r=0;
static int acc=0;
while (queue_size > queue_maxlength / 2) {
#ifdef _WIN32
@ -86,14 +89,63 @@ void Mixer_PushSamples(short *buffer, int num_stereo_samples, int sample_rate) {
#endif
Sleep(0);
}
//convert into config option?
const int mode = 2;
push_sync.Enter();
for (int i = 0; i < num_stereo_samples * 2; i++) {
while (fraction < 65536) {
sample_queue.push(buffer[i]);
queue_size++;
fraction += (65536ULL * sample_rate) / 48000;
while (num_stereo_samples)
{
acc += sample_rate;
while (num_stereo_samples && (acc>=48000))
{
PV4l=PV3l;
PV3l=PV2l;
PV2l=PV1l;
PV1l=*(buffer++); //32bit processing
PV4r=PV3r;
PV3r=PV2r;
PV2r=PV1r;
PV1r=*(buffer++); //32bit processing
num_stereo_samples--;
acc-=48000;
}
// defaults to nearest
s32 DataL = PV1l;
s32 DataR = PV1r;
if (mode==1) //linear
{
DataL = PV1l + ((PV2l - PV1l)*acc)/48000;
DataR = PV1r + ((PV2r - PV1r)*acc)/48000;
}
fraction &= 0xFFFF;
}
else if (mode==2) //cubic
{
s32 a0l = PV1l - PV2l - PV4l + PV3l;
s32 a0r = PV1r - PV2r - PV4r + PV3r;
s32 a1l = PV4l - PV3l - a0l;
s32 a1r = PV4r - PV3r - a0r;
s32 a2l = PV1l - PV4l;
s32 a2r = PV1r - PV4r;
s32 a3l = PV2l;
s32 a3r = PV2r;
s32 t0l = ((a0l )*acc)/48000;
s32 t0r = ((a0r )*acc)/48000;
s32 t1l = ((t0l+a1l)*acc)/48000;
s32 t1r = ((t0r+a1r)*acc)/48000;
s32 t2l = ((t1l+a2l)*acc)/48000;
s32 t2r = ((t1r+a2r)*acc)/48000;
s32 t3l = ((t2l+a3l));
s32 t3r = ((t2r+a3r));
DataL = t3l;
DataR = t3r;
}
sample_queue.push(DataL);
sample_queue.push(DataR);
queue_size++;
}
push_sync.Leave();
}