From 471bb025b2a0718aca3eec33aef73df26c8d680a Mon Sep 17 00:00:00 2001 From: hrydgard Date: Sat, 16 Aug 2008 22:28:33 +0000 Subject: [PATCH] gigaherz' improved resampler git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@228 8ced0084-cf51-0410-be5f-012b33b47a6e --- .../Plugins/Plugin_DSP_HLE/Src/PCHW/Mixer.cpp | 68 ++++++++++++++++--- 1 file changed, 60 insertions(+), 8 deletions(-) diff --git a/Source/Plugins/Plugin_DSP_HLE/Src/PCHW/Mixer.cpp b/Source/Plugins/Plugin_DSP_HLE/Src/PCHW/Mixer.cpp index e2745d1bbf..2aa40a5eec 100644 --- a/Source/Plugins/Plugin_DSP_HLE/Src/PCHW/Mixer.cpp +++ b/Source/Plugins/Plugin_DSP_HLE/Src/PCHW/Mixer.cpp @@ -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(); }