Abs() private méthode

private Abs ( int n ) : int
n int
Résultat int
Exemple #1
0
        // Recalculates the total increment given our current tuning settings.
        public void Recalc()
        {
            // TODO:  once notes can be specified, consider storing separate fixed_hz and removing intermediary tuned_hz, maybe even base_hz --
            //          If we use 2 copies of the envelope state instead (one for temporary changes) in Operator, less instructions are used to recalc.
            //          OTOH, these intermediaries may be necessary to keep track of the LFO state, depending on how and where we adjust the phase....
            //          Channel-wide/Patch-wide LFO would track phase offset separately and add them in every requested sample.

            //      More LFO thoughts.... Pull full LFO cycle from the pg increment >> some amount based on PMS, then map the offset on a clock from
            //      ± the PMS output range.  Add this lfo value to the phase.  Consider creating a PMS ratio table to avoid divisions (pre-divide)
            //      if Rsh doesn't work to cull pitch to reasonable ranges.


            if (fixedFreq)
            {
                this.hz = this.tuned_hz = base_hz;
            }
            else
            {
                var transpose = Math.Clamp((coarse * 100) + fine, -1299, 1299);

                var t = Tables.transpose[Tools.Abs(transpose)];
                if (transpose < 0)
                {
                    t = 1 / t;                //Negative transpose values are equal to the reciprocal of the positive transpose ratio
                }
                this.hz = this.tuned_hz = base_hz * mult * lfoMult * t * detune_current;
            }

            tunedIncrement = IncOfFreq(this.tuned_hz);
            increment      = tunedIncrement + increment_offset;
        }
Exemple #2
0
        // public override void Clock()
        // {
        //     base.Clock();
        //     return;
        // }

        public override short RequestSample(ushort input, ushort am_offset)
        {
            var raw_output = Fold(input);  //Scaled to 14-bit for our processing table.

            flip = raw_output < 0;
            var    input_attenuation = Tables.vol2attenuation[Tools.Abs(raw_output)];
            ushort env_attenuation   = (ushort)(envelope_attenuation(am_offset) << 2);
            int    result            = Tables.attenuation_to_volume((ushort)(input_attenuation + env_attenuation));

            //Bit crush the result.
            var crush = eg.aux_func /*+ 1*/;  //Save an add by adjusting aux_func in the UI to skip first bit of crushing

            // result = result & ~(1<<(eg.aux_func+1));   //This function behaved oddly....
            result >>= crush;
            result <<= crush;

            return(flip? (short)-result : (short)result);
        }