コード例 #1
0
        public override void Reset()
        {
            volume  = 0;
            v3_mute = false;

            for (int v = 0; v < voice.Length; v++)
            {
                voice[v].wave     = SIDWaveForm.WAVE_NONE;
                voice[v].eg_state = EGState.EG_IDLE;
                voice[v].count    = voice[v].add = 0;
                voice[v].freq     = voice[v].pw = 0;
                voice[v].eg_level = voice[v].s_level = 0;
                voice[v].a_add    = voice[v].d_sub = voice[v].r_sub = EGTable[0];
                voice[v].gate     = voice[v].ring = voice[v].test = false;
                voice[v].filter   = voice[v].sync = false;
            }

            f_type = FilterType.FILT_NONE;
            f_freq = f_res = 0;

#if USE_FIXPOINT_MATHS
            f_ampl = FixPoint.FixNo(1);
            d1     = d2 = g1 = g2 = 0;
            xn1    = xn2 = yn1 = yn2 = 0;
#else
            f_ampl = 1.0f;
            d1     = d2 = g1 = g2 = 0.0f;
            xn1    = xn2 = yn1 = yn2 = 0.0f;
#endif

            sample_in_ptr = 0;
            Array.Clear(sample_buf, 0, sample_buf.Length);
        }
コード例 #2
0
        const int SAMPLE_BUF_SIZE = 0x138 * 2;              // Size of buffer for sampled voice (double buffered)

        #endregion

        #region Public methods

        public DigitalRenderer()
        {
            for (int i = 0; i < voice.Length; i++)
            {
                voice[i] = new DRVoice();
            }

            // Link voices together
            voice[0].mod_by = voice[2];
            voice[1].mod_by = voice[0];
            voice[2].mod_by = voice[1];
            voice[0].mod_to = voice[1];
            voice[1].mod_to = voice[2];
            voice[2].mod_to = voice[0];

            // Calculate triangle table
            for (int i = 0; i < 0x1000; i++)
            {
                TriTable[i]          = (UInt16)((i << 4) | (i >> 8));
                TriTable[0x1fff - i] = (UInt16)((i << 4) | (i >> 8));
            }

#if PRECOMPUTE_RESONANCE
#if USE_FIXPOINT_MATHS
            // slow floating point doesn't matter much on startup!
            for (int i = 0; i < 256; i++)
            {
                resonanceLP[i] = FixPoint.FixNo((227.755 - 1.7635 * i - 0.0176385 * i * i + 0.00333484 * i * i * i - 9.05683E-6 * i * i * i * i));
                resonanceHP[i] = FixPoint.FixNo((366.374 - 14.0052 * i + 0.603212 * i * i - 0.000880196 * i * i * i));
            }
            // Pre-compute the quotient. No problem since int-part is small enough
            sidquot = (Int32)((((double)SID_FREQ) * 65536) / SAMPLE_FREQ);
            // compute lookup table for Math.Sin and Math.Cos
            FixPoint.InitFixSinTab();
#else
            for (int i = 0; i < 256; i++)
            {
                resonanceLP[i] = (227.755 - 1.7635 * i - 0.0176385 * i * i + 0.00333484 * i * i * i - 9.05683E-6 * i * i * i * i);
                resonanceHP[i] = (366.374 - 14.0052 * i + 0.603212 * i * i - 0.000880196 * i * i * i);
            }
#endif
#endif

            Reset();

            // System specific initialization
            init_sound();
        }
コード例 #3
0
ファイル: FixPoint.cs プロジェクト: rudzen/sharp-c64
        //#define FIXPOINT_SIN_COS_GENERIC \
        //  if (angle >= 3*(1<<ldSINTAB)) {return(-SinTable[(1<<(ldSINTAB+2)) - angle]);}\
        //  if (angle >= 2*(1<<ldSINTAB)) {return(-SinTable[angle - 2*(1<<ldSINTAB)]);}\
        //  if (angle >= (1<<ldSINTAB)) {return(SinTable[2*(1<<ldSINTAB) - angle]);}\
        //  return(SinTable[angle]);


        // sin and cos: angle is fixpoint number 0 <= angle <= 2 (*PI)
        public static FixPoint fixsin(FixPoint x)
        {
            int angle = x;

            angle = (angle >> (FIXPOINT_PREC - ldSINTAB - 1)) & ((1 << (ldSINTAB + 2)) - 1);

            // FIXPOINT_SIN_COS_GENERIC macro
            if (angle >= 3 * (1 << ldSINTAB))
            {
                return(-SinTable[(1 << (ldSINTAB + 2)) - angle]);
            }
            if (angle >= 2 * (1 << ldSINTAB))
            {
                return(-SinTable[angle - 2 * (1 << ldSINTAB)]);
            }
            if (angle >= (1 << ldSINTAB))
            {
                return(SinTable[2 * (1 << ldSINTAB) - angle]);
            }
            return(SinTable[angle]);
        }
コード例 #4
0
        void calc_filter()
        {
#if USE_FIXPOINT_MATHS
            FixPoint fr, arg;

            if (f_type == FilterType.FILT_ALL)
            {
                d1 = 0; d2 = 0; g1 = 0; g2 = 0; f_ampl = FixPoint.FixNo(1); return;
            }
            else if (f_type == FilterType.FILT_NONE)
            {
                d1 = 0; d2 = 0; g1 = 0; g2 = 0; f_ampl = 0; return;
            }
#else
            float fr, arg;

            // Check for some trivial cases
            if (f_type == FilterType.FILT_ALL)
            {
                d1     = 0.0f; d2 = 0.0f;
                g1     = 0.0f; g2 = 0.0f;
                f_ampl = 1.0f;
                return;
            }
            else if (f_type == FilterType.FILT_NONE)
            {
                d1     = 0.0f; d2 = 0.0f;
                g1     = 0.0f; g2 = 0.0f;
                f_ampl = 0.0f;
                return;
            }
#endif

            // Calculate resonance frequency
            if (f_type == FilterType.FILT_LP || f_type == FilterType.FILT_LPBP)
#if PRECOMPUTE_RESONANCE
            { fr = resonanceLP[f_freq]; }
#else
            { fr = (float)(227.755 - 1.7635 * f_freq - 0.0176385 * f_freq * f_freq + 0.00333484 * f_freq * f_freq * f_freq - 9.05683E-6 * f_freq * f_freq * f_freq * f_freq); }
コード例 #5
0
ファイル: FixPoint.cs プロジェクト: archer87pl/sharp-c64
        public static FixPoint fixcos(FixPoint x)
        {
            int angle = x;

            // cos(x) = sin(x+PI/2)
            angle = (angle + (1 << (FIXPOINT_PREC - 1)) >> (FIXPOINT_PREC - ldSINTAB - 1)) & ((1 << (ldSINTAB + 2)) - 1);

            // FIXPOINT_SIN_COS_GENERIC macro
            if (angle >= 3 * (1 << ldSINTAB)) { return (-SinTable[(1 << (ldSINTAB + 2)) - angle]); }
            if (angle >= 2 * (1 << ldSINTAB)) { return (-SinTable[angle - 2 * (1 << ldSINTAB)]); }
            if (angle >= (1 << ldSINTAB)) { return (SinTable[2 * (1 << ldSINTAB) - angle]); }
            return (SinTable[angle]);

        }