Re: [hatari-devel] Improved YM2149 cycle accuracy |
[ Thread Index | Date Index | More lists.tuxfamily.org/hatari-devel Archives ]
Hi Nicolas,I looked at the code and found that some filter coefficients need tobe converted to 250 KHz. The enclosed patch does the job.I made the patch without testing or compiling because it issimple and I'm not set up for Hatari at the moment.Once the patch is applied, only YM2149_Next_Resample_Nearest()is needed (the best choice). The IIR filters are as efficient asthe YM2149_Next_Resample_Weighted_Average_N() method.Hatari should have the same good timbre as it did when the filterswere implemented a few years agoDavid Savinkoffps. If the sound is wrong, I'll have to double check the coefficients.
--- a/src/sound.c 2021-07-25 11:50:06.650166911 -0700 +++ b/src/sound.c 2021-07-25 12:18:56.516824122 -0700 @@ -399,17 +399,19 @@ /** * Get coefficients for different Fs (C10 is in ST only): - * Wc = 2*M_PI*4895.1; - * Fs = 44100; + * Wc = 2*M_PI*fc; + * Fs = 250000 Hz; * warp = Wc/tanf((Wc/2)/Fs); - * b = Wc/(warp+Wc); - * a = (Wc-warp)/(warp+Wc); + * b = Wc/(Wc+warp); + * a = (Wc-warp)/(Wc+warp); * + * Aside: 44100 Hz coefficients example * #define B_z (yms32)( 0.2667*(1<<15)) * #define A_z (yms32)(-0.4667*(1<<15)) * * y0 = (B_z*(x0 + x1) - A_z*y0) >> 15; * x1 = x0; + * /Aside * * The Lowpass Filter formed by C10 = 0.1 uF * and @@ -437,11 +439,11 @@ static yms32 y0 = 0, x1 = 0; if (x0 >= y0) - /* YM Pull up: fc = 7586.1 Hz (44.1 KHz), fc = 8257.0 Hz (48 KHz) */ - y0 = (3*(x0 + x1) + (y0<<1)) >> 3; + /* YM Pull up: fc is approx 7693.7 Hz (at 250 KHz rate) */ + y0 = ( 45*(x0 + x1) + 422*y0 ) >> 9; /* b= 45/512 a= 422/512 */ else - /* R8 Pull down: fc = 1992.0 Hz (44.1 KHz), fc = 2168.0 Hz (48 KHz) */ - y0 = ((x0 + x1) + (6*y0)) >> 3; + /* R8 Pull down: fc is approx 2096.6 Hz (at 250 KHz rate) */ + y0 = ( 13*(x0 + x1) + 486*y0 ) >> 9; /* b= 13/512 a= 486/512 */ x1 = x0; return y0; @@ -469,7 +471,7 @@ y0 = x0; else /* R8 Pull down */ - y0 = (3*(x0 + x1) + (y0<<1)) >> 3; + y0 = ( 45*(x0 + x1) + 422*y0 ) >> 9; /* b= 45/512 a= 422/512 */ x1 = x0; return y0;
Mail converted by MHonArc 2.6.19+ | http://listengine.tuxfamily.org/ |