From 2a2caa492cd2d71ac0af49bfc1bf77f5b7345e48 Mon Sep 17 00:00:00 2001 From: goyuken Date: Sun, 19 Aug 2012 17:46:13 +0000 Subject: [PATCH] add linear resampler (not activated in code). sounds about the same as the other two (ie, no major bugs) on the opening to Golden Axe --- BizHawk.Emulation/Sound/YM2612.cs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/BizHawk.Emulation/Sound/YM2612.cs b/BizHawk.Emulation/Sound/YM2612.cs index 08a5bc02c3..e9cfb9a161 100644 --- a/BizHawk.Emulation/Sound/YM2612.cs +++ b/BizHawk.Emulation/Sound/YM2612.cs @@ -1031,6 +1031,7 @@ namespace BizHawk.Emulation.Sound // downsample from native output rate to 44100. //CrappyNaiveResampler(nativeSamples, samples); MaybeBetterDownsampler(nativeSamples, samples); + //LinearDownsampler(nativeSamples, samples); } static void CrappyNaiveResampler(short[] input, short[] output) @@ -1052,6 +1053,30 @@ namespace BizHawk.Emulation.Sound return value - Math.Floor(value); } + /// + /// basic linear audio resampler. sampling rate is inferred from buffer sizes + /// + /// stereo s16 + /// stereo s16 + static void LinearDownsampler(short[] input, short[] output) + { + double samplefactor = input.Length / (double)output.Length; + + for (int i = 0; i < output.Length / 2; i++) + { + // exact position on input stream + double inpos = i * samplefactor; + // selected interpolation points and weights + int pt0 = (int)inpos; // pt1 = pt0 + 1 + double wt1 = inpos - pt0; // wt0 = 1 - wt1 + double wt0 = 1.0 - wt1; + + output[i * 2 + 0] = (short)(input[pt0 * 2 + 0] * wt0 + input[pt0 * 2 + 2] * wt1); + output[i * 2 + 1] = (short)(input[pt0 * 2 + 1] * wt0 + input[pt0 * 2 + 3] * wt1); + } + } + + static void MaybeBetterDownsampler(short[] input, short[] output) { // This is still not a good resampler. But it's better than the other one. Unsure how much difference it makes.