]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Sound filter + FPU side-effect quick workaround.
authorToni Wilen <twilen@winuae.net>
Wed, 7 Jun 2017 17:39:54 +0000 (20:39 +0300)
committerToni Wilen <twilen@winuae.net>
Wed, 7 Jun 2017 17:39:54 +0000 (20:39 +0300)
audio.cpp
fpp_native.cpp

index bcbbc01511f9617ce0379dbe985cd682ab4ff32b..2f3a8b8fc2dd87fcd368980b9346a569b4314b9b 100644 (file)
--- a/audio.cpp
+++ b/audio.cpp
@@ -401,7 +401,7 @@ static int filter (int input, struct filter_state *fs)
 
        case FILTER_MODEL_A500:
                fs->rc1 = a500e_filter1_a0 * input + (1 - a500e_filter1_a0) * fs->rc1 + DENORMAL_OFFSET;
-               fs->rc2 = a500e_filter2_a0 * fs->rc1 + (1-a500e_filter2_a0) * fs->rc2;
+               fs->rc2 = a500e_filter2_a0 * fs->rc1 + (1 - a500e_filter2_a0) * fs->rc2;
                normal_output = fs->rc2;
 
                fs->rc3 = filter_a0 * normal_output + (1 - filter_a0) * fs->rc3;
@@ -1747,6 +1747,8 @@ static int sound_prefs_changed (void)
        return 0;
 }
 
+double softfloat_tan(double v);
+
 /* This computes the 1st order low-pass filter term b0.
 * The a1 term is 1.0 - b0. The center frequency marks the -3 dB point. */
 #ifndef M_PI
@@ -1763,8 +1765,9 @@ static float rc_calculate_a0 (int sample_rate, int cutoff_freq)
        /* Compensate for the bilinear transformation. This allows us to specify the
        * stop frequency more exactly, but the filter becomes less steep further
        * from stopband. */
-       omega = tan (omega / 2) * 2;
-       return 1 / (1 + 1 / omega);
+       omega = softfloat_tan (omega / 2.0) * 2.0;
+       float out = 1.0 / (1.0 + 1.0 / omega);
+       return out;
 }
 
 void check_prefs_changed_audio (void)
@@ -1881,6 +1884,7 @@ void set_audio (void)
        a500e_filter1_a0 = rc_calculate_a0 (currprefs.sound_freq, 6200);
        a500e_filter2_a0 = rc_calculate_a0 (currprefs.sound_freq, 20000);
        filter_a0 = rc_calculate_a0 (currprefs.sound_freq, 7000);
+       memset (sound_filter_state, 0, sizeof sound_filter_state);
        led_filter_audio ();
 
        /* Select the right interpolation method.  */
index 143b5b88067153bcd15c15be06bf770d56a5517e..39f13f7a403a6ea70c8063d65fcbf2c453a657db 100644 (file)
@@ -1275,3 +1275,20 @@ void fp_init_native(void)
        fpp_tst = fp_tst;
        fpp_move = fp_move;
 }
+
+double softfloat_tan(double v)
+{
+       struct float_status f = { 0 };
+       uae_u32 w1, w2;
+       fpdata fpd = { 0 };
+
+       fpd.fp = v;
+       set_floatx80_rounding_precision(80, &f);
+       set_float_rounding_mode(float_round_to_zero, &f);
+       fp_from_double(&fpd, &w1, &w2);
+       floatx80 fv = float64_to_floatx80(((uae_u64)w1 << 32) | w2, &fs);
+       fv = floatx80_tan(fv, &fs);
+       float64 f64 = floatx80_to_float64(fv, &fs);
+       fp_to_double(&fpd, f64 >> 32, (uae_u32)f64);
+       return fpd.fp;
+}