Esempio n. 1
0
        public void MoveToStage(int currentStage)
        {
            currentStageIndex = currentStage;
            // color current
            var img = stages[currentStage].GetComponent <Image>();

            img.fillCenter = false;
            img.color      = neutralStageColor;

            // color left half
            for (int i = 0; i < currentStage; i++)
            {
                img            = stages[i].GetComponent <Image>();
                img.fillCenter = true;
                img.color      = teamOnTheLeft.Value.Color;
            }

            // color right half
            for (int i = currentStage + 1; i < stages.Length; i++)
            {
                img            = stages[i].GetComponent <Image>();
                img.fillCenter = true;
                img.color      = teamOnTheRight.Value.Color;
            }

            // put player on current stage ui
            foreach (var player in players)
            {
                player.Value.transform.SetParent(stages[currentStage].transform, false);
            }
        }
Esempio n. 2
0
        /* ITU-T G.729 Software Package Release 2 (November 2006) */

        /*
         * ITU-T G.729 Annex C - Reference C code for floating point
         *               implementation of G.729
         *               Version 1.01 of 15.September.98
         */

        /*
         * ----------------------------------------------------------------------
         *          COPYRIGHT NOTICE
         * ----------------------------------------------------------------------
         * ITU-T G.729 Annex C ANSI C source code
         * Copyright (C) 1998, AT&T, France Telecom, NTT, University of
         * Sherbrooke.  All rights reserved.
         *
         * ----------------------------------------------------------------------
         */

        /*
         * File : ACELP_CO.C
         * Used for the floating point version of G.729 main body
         * (not for G.729A)
         */

        /**
         *
         * @param x             (i)     :Target vector
         * @param h             (i)     :Impulse response of filters
         * @param t0            (i)     :Pitch lag
         * @param pitch_sharp   (i)     :Last quantized pitch gain
         * @param i_subfr       (i)     :Indicator of 1st subframe,
         * @param code          (o)     :Innovative codebook
         * @param y             (o)     :Filtered innovative codebook
         * @param sign          (o)     :Signs of 4 pulses
         * @return              index of pulses positions
         */

        public int ACELP_codebook(
            float[] x,
            float[] h,
            int t0,
            float pitch_sharp,
            int i_subfr,
            float[] code,
            float[] y,
            IntReference sign
            )
        {
            var DIM_RR  = Ld8k.DIM_RR;
            var L_SUBFR = Ld8k.L_SUBFR;

            int i, index;
            var dn = new float[L_SUBFR];
            var rr = new float[DIM_RR];

            /*----------------------------------------------------------------*
             * Include fixed-gain pitch contribution into impulse resp. h[]    *
             * Find correlations of h[] needed for the codebook search.        *
             *-----------------------------------------------------------------*/

            if (t0 < L_SUBFR)
            {
                for (i = t0; i < L_SUBFR; i++)
                {
                    h[i] += pitch_sharp * h[i - t0];
                }
            }

            cor_h(h, rr);

            /*----------------------------------------------------------------*
             * Compute correlation of target vector with impulse response.     *
             *-----------------------------------------------------------------*/

            CorFunc.cor_h_x(h, x, dn); /* backward filtered target vector dn */

            /*----------------------------------------------------------------*
             * Find innovative codebook.                                       *
             *-----------------------------------------------------------------*/

            index = d4i40_17(dn, rr, h, code, y, sign, i_subfr);

            /*------------------------------------------------------*
             * - Add the fixed-gain pitch contribution to code[].    *
             *-------------------------------------------------------*/

            if (t0 < L_SUBFR)
            {
                for (i = t0; i < L_SUBFR; i++)
                {
                    code[i] += pitch_sharp * code[i - t0];
                }
            }

            return(index);
        }
Esempio n. 3
0
 public void Args14()
 {
     AsyncContext.Run(async() =>
     {
         IntReference counter = new IntReference();
         await AsyncFactory.FromApm(BeginSuccess14, End, counter, counter, counter, counter, counter, counter, counter, counter, counter, counter, counter, counter, counter, counter);
         Assert.AreEqual(1, counter.Value);
     });
 }
Esempio n. 4
0
 public void addValue(IntReference PlayerMoney)
 {
     if (PlayerMoney.value >= upgradePrice)
     {
         PlayerMoney.value = PlayerMoney.value - upgradePrice;
         upgradeStat.value = upgradeStat.value * valueMultiplier;
         upgradePrice      = Mathf.CeilToInt(upgradePrice * priceMultiplier);
     }
 }
 public void Args9()
 {
     Test.Async(async() =>
     {
         IntReference counter = new IntReference();
         await AsyncFactory.FromApm(BeginSuccess9, End, counter, counter, counter, counter, counter, counter, counter, counter, counter);
         Assert.AreEqual(1, counter.Value);
     });
 }
Esempio n. 6
0
 public void RefreshOffer(IntReference playerMoney)
 {
     if (playerMoney >= _usableItem.Cost)
     {
         _name.color = Color.green;
     }
     else
     {
         _name.color = Color.red;
     }
 }
Esempio n. 7
0
 public MSpeedSet()
 {
     name               = "Set Name";
     states             = new List <StateID>();
     StartVerticalIndex = new IntReference(1);
     TopIndex           = new IntReference(2);
     Speeds             = new List <MSpeed>(1)
     {
         new MSpeed("SpeedName", 1, 4, 4)
     };
 }
Esempio n. 8
0
 private void Initialize()
 {
     //Init current stats
     _currentEnergy                    = baseStats.Energy;
     _currentMoveSpeedInAir            = baseStats.MoveSpeedInAir;
     _currentLoseStaminaAmount         = baseStats.LoseStaminaAmount;
     _currentMaxHealth                 = baseStats.MaxHealth;
     _currentMoveSpeedChaseAndComeBack = baseStats.MoveSpeedChaseAndComeBack;
     _currentGainStaminaAmount         = baseStats.GainStaminaAmount;
     _currentFrequencyLoseStamina      = baseStats.FrequencyLoseStamina;
     _currentFrequencyGainStamina      = baseStats.FrequencyGainStamina;
 }
Esempio n. 9
0
 public MarchingSquareIteratorAction(Vector3Reference pos,
                                     IntReference idxOffset,
                                     IntReference iteratorIdx,
                                     Vector3Reference cornerPos,
                                     IDefaultAction action)
 {
     m_pos         = pos;
     m_idxOffset   = idxOffset;
     m_iteratorIdx = iteratorIdx;
     m_cornerPos   = cornerPos;
     m_continue    = action;
 }
Esempio n. 10
0
        /* ITU-T G.729 Software Package Release 2 (November 2006) */

        /*
         * ITU-T G.729 Annex C - Reference C code for floating point
         *               implementation of G.729
         *               Version 1.01 of 15.September.98
         */

        /*
         * ----------------------------------------------------------------------
         *          COPYRIGHT NOTICE
         * ----------------------------------------------------------------------
         * ITU-T G.729 Annex C ANSI C source code
         * Copyright (C) 1998, AT&T, France Telecom, NTT, University of
         * Sherbrooke.  All rights reserved.
         *
         * ----------------------------------------------------------------------
         */

        /*
         * File : DEC_LAG3.C
         * Used for the floating point version of both
         * G.729 main body and G.729A
         */

        /**
         * Decoding of fractional pitch lag with 1/3 resolution.
         * See the source for more details about the encoding procedure.
         *
         * @param index      input : received pitch index
         * @param pit_min    input : minimum pitch lag
         * @param pit_max    input : maximum pitch lag
         * @param i_subfr    input : subframe flag
         * @param T0         output: integer part of pitch lag
         * @param T0_frac    output: fractional part of pitch lag
         */

        public static void dec_lag3(
            int index,
            int pit_min,
            int pit_max,
            int i_subfr,
            IntReference T0,
            IntReference T0_frac
            )
        {
            int i;
            int _T0 = T0.value, _T0_frac = T0_frac.value;
            int T0_min, T0_max;

            if (i_subfr == 0) /* if 1st subframe */
            {
                if (index < 197)
                {
                    _T0      = (index + 2) / 3 + 19;
                    _T0_frac = index - _T0 * 3 + 58;
                }
                else
                {
                    _T0      = index - 112;
                    _T0_frac = 0;
                }
            }

            else /* second subframe */
            {
                /* find T0_min and T0_max for 2nd subframe */

                T0_min = _T0 - 5;
                if (T0_min < pit_min)
                {
                    T0_min = pit_min;
                }

                T0_max = T0_min + 9;
                if (T0_max > pit_max)
                {
                    T0_max = pit_max;
                    T0_min = T0_max - 9;
                }

                i        = (index + 2) / 3 - 1;
                _T0      = i + T0_min;
                _T0_frac = index - 2 - i * 3;
            }

            T0.value      = _T0;
            T0_frac.value = _T0_frac;
        }
Esempio n. 11
0
 public void Load()
 {
     if (PlayerPrefs.HasKey("level"))
     {
         SavedLevel = ScriptableObject.CreateInstance <IntReference>();
         // Debug.Log("Load saved level : " + PlayerPrefs.GetString("level"));
         SavedLevel = Helper.Deserialize <IntReference>(PlayerPrefs.GetString("level"));
         // Debug.Log(SavedLevel.value);
     }
     else
     {
         SavedLevel = ScriptableObject.CreateInstance <IntReference>();
         Save();
     }
 }
Esempio n. 12
0
 private IAsyncResult BeginSuccess8(IntReference a, IntReference a1, IntReference a2, IntReference a3, IntReference a4, IntReference a5, IntReference a6, IntReference a7, AsyncCallback callback, object state)
 {
     return AsyncFactory.ToBegin(Success8(a, a1, a2, a3, a4, a5, a6, a7), callback, state);
 }
Esempio n. 13
0
        /**
         * Quantization of pitch and codebook gains
         *
         * @param code          input : fixed codebook vector
         * @param g_coeff       input : correlation factors
         * @param l_subfr       input : fcb vector length
         * @param gain_pit      output: quantized acb gain
         * @param gain_code     output: quantized fcb gain
         * @param tameflag      input : flag set to 1 if taming is needed
         * @return              quantizer index
         */

        public int qua_gain(
            float[] code,
            float[] g_coeff,
            int l_subfr,
            FloatReference gain_pit,
            FloatReference gain_code,
            int tameflag
            )
        {
            var FLT_MAX_G729 = Ld8k.FLT_MAX_G729;
            var GP0999       = Ld8k.GP0999;
            var GPCLIP2      = Ld8k.GPCLIP2;
            var NCAN1        = Ld8k.NCAN1;
            var NCAN2        = Ld8k.NCAN2;
            var NCODE2       = Ld8k.NCODE2;
            var gbk1         = TabLd8k.gbk1;
            var gbk2         = TabLd8k.gbk2;
            var map1         = TabLd8k.map1;
            var map2         = TabLd8k.map2;

            /*
             * MA prediction is performed on the innovation energy (in dB with mean      *
             * removed).                                                                 *
             * An initial predicted gain, g_0, is first determined and the correction    *
             * factor     alpha = gain / g_0    is quantized.                            *
             * The pitch gain and the correction factor are vector quantized and the     *
             * mean-squared weighted error criterion is used in the quantizer search.    *
             *   CS Codebook , fast pre-selection version                                *
             */

            int   i, j, index1 = 0, index2 = 0;
            int   cand1, cand2;
            float gcode0;
            float dist, dist_min, g_pitch, g_code;
            var   best_gain = new float[2];
            float tmp;

            /*---------------------------------------------------*
            *-  energy due to innovation                       -*
            *-  predicted energy                               -*
            *-  predicted codebook gain => gcode0[exp_gcode0]  -*
            *---------------------------------------------------*/

            gcode0 = Gainpred.gain_predict(past_qua_en, code, l_subfr);

            /*-- pre-selection --*/
            tmp          = -1.0f / (4.0f * g_coeff[0] * g_coeff[2] - g_coeff[4] * g_coeff[4]);
            best_gain[0] = (2.0f * g_coeff[2] * g_coeff[1] - g_coeff[3] * g_coeff[4]) * tmp;
            best_gain[1] = (2.0f * g_coeff[0] * g_coeff[3] - g_coeff[1] * g_coeff[4]) * tmp;

            if (tameflag == 1)
            {
                if (best_gain[0] > GPCLIP2)
                {
                    best_gain[0] = GPCLIP2;
                }
            }

            /*----------------------------------------------*
            *   - presearch for gain codebook -            *
            *----------------------------------------------*/

            var cand1Ref = new IntReference();
            var cand2Ref = new IntReference();

            gbk_presel(best_gain, cand1Ref, cand2Ref, gcode0);
            cand1 = cand1Ref.value;
            cand2 = cand2Ref.value;

            /*-- selection --*/
            dist_min = FLT_MAX_G729;
            if (tameflag == 1)
            {
                for (i = 0; i < NCAN1; i++)
                {
                    for (j = 0; j < NCAN2; j++)
                    {
                        g_pitch = gbk1[cand1 + i][0] + gbk2[cand2 + j][0];
                        if (g_pitch < GP0999)
                        {
                            g_code = gcode0 * (gbk1[cand1 + i][1] + gbk2[cand2 + j][1]);
                            dist   = g_pitch * g_pitch * g_coeff[0]
                                     + g_pitch * g_coeff[1]
                                     + g_code * g_code * g_coeff[2]
                                     + g_code * g_coeff[3]
                                     + g_pitch * g_code * g_coeff[4];
                            if (dist < dist_min)
                            {
                                dist_min = dist;
                                index1   = cand1 + i;
                                index2   = cand2 + j;
                            }
                        }
                    }
                }
            }
            else
            {
                for (i = 0; i < NCAN1; i++)
                {
                    for (j = 0; j < NCAN2; j++)
                    {
                        g_pitch = gbk1[cand1 + i][0] + gbk2[cand2 + j][0];
                        g_code  = gcode0 * (gbk1[cand1 + i][1] + gbk2[cand2 + j][1]);
                        dist    = g_pitch * g_pitch * g_coeff[0]
                                  + g_pitch * g_coeff[1]
                                  + g_code * g_code * g_coeff[2]
                                  + g_code * g_coeff[3]
                                  + g_pitch * g_code * g_coeff[4];
                        if (dist < dist_min)
                        {
                            dist_min = dist;
                            index1   = cand1 + i;
                            index2   = cand2 + j;
                        }
                    }
                }
            }

            gain_pit.value  = gbk1[index1][0] + gbk2[index2][0];
            g_code          = gbk1[index1][1] + gbk2[index2][1];
            gain_code.value = g_code * gcode0;

            /*----------------------------------------------*
            * update table of past quantized energies      *
            *----------------------------------------------*/
            Gainpred.gain_update(past_qua_en, g_code);

            return(map1[index1] * NCODE2 + map2[index2]);
        }
Esempio n. 14
0
        /**
         * Decoder
         *
         * @param parm          input : synthesis parameters (parm[0] = bfi)
         * @param voicing       input : voicing decision from previous frame
         * @param synth         output: synthesized speech
         * @param synth_offset  input : synthesized speech offset
         * @param A_t           output: two sets of A(z) coefficients length=2*MP1
         * @return              output: integer delay of first subframe
         */

        public int decod_ld8k(
            int[] parm,
            int voicing,
            float[] synth,
            int synth_offset,
            float[] A_t
            )
        {
            var parm_offset = 0;

            var t0_first = 0;                     /* output: integer delay of first subframe            */

            float[] Az;                           /* Pointer to A_t (LPC coefficients)  */
            int     Az_offset;
            var     lsp_new = new float[M];       /* LSPs                               */
            var     code    = new float[L_SUBFR]; /* algebraic codevector               */

            /* Scalars */
            int          i, i_subfr;
            IntReference t0 = new IntReference(), t0_frac = new IntReference();
            int          index;

            int bfi;
            int bad_pitch;

            /* Test bad frame indicator (bfi) */

            bfi = parm[parm_offset];
            parm_offset++;

            /* Decode the LSPs */

            lspdec.d_lsp(parm, parm_offset, lsp_new, bfi);
            parm_offset += 2; /* Advance synthesis parameters pointer */

            /* Interpolation of LPC for the 2 subframes */

            Lpcfunc.int_qlpc(lsp_old, lsp_new, A_t);

            /* update the LSFs for the next frame */

            Util.copy(lsp_new, lsp_old, M);

            /*------------------------------------------------------------------------*
            *          Loop for every subframe in the analysis frame                 *
            *------------------------------------------------------------------------*
            * The subframe size is L_SUBFR and the loop is repeated L_FRAME/L_SUBFR  *
            *  times                                                                 *
            *     - decode the pitch delay                                           *
            *     - decode algebraic code                                            *
            *     - decode pitch and codebook gains                                  *
            *     - find the excitation and compute synthesis speech                 *
            *------------------------------------------------------------------------*/

            Az        = A_t; /* pointer to interpolated LPC parameters */
            Az_offset = 0;

            for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR)
            {
                index = parm[parm_offset]; /* pitch index */
                parm_offset++;

                if (i_subfr == 0)
                {
                    /* if first subframe */
                    i = parm[parm_offset]; /* get parity check result */
                    parm_offset++;
                    bad_pitch = bfi + i;
                    if (bad_pitch == 0)
                    {
                        DecLag3.dec_lag3(index, PIT_MIN, PIT_MAX, i_subfr, t0, t0_frac);
                        old_t0 = t0.value;
                    }
                    else /* Bad frame, or parity error */
                    {
                        t0.value      = old_t0;
                        t0_frac.value = 0;
                        old_t0++;
                        if (old_t0 > PIT_MAX)
                        {
                            old_t0 = PIT_MAX;
                        }
                    }

                    t0_first = t0.value; /* If first frame */
                }
                else /* second subframe */
                {
                    if (bfi == 0)
                    {
                        DecLag3.dec_lag3(index, PIT_MIN, PIT_MAX, i_subfr, t0, t0_frac);
                        old_t0 = t0.value;
                    }
                    else
                    {
                        t0.value      = old_t0;
                        t0_frac.value = 0;
                        old_t0++;
                        if (old_t0 > PIT_MAX)
                        {
                            old_t0 = PIT_MAX;
                        }
                    }
                }

                /*-------------------------------------------------*
                 *  - Find the adaptive codebook vector.            *
                 *--------------------------------------------------*/

                PredLt3.pred_lt_3(exc, exc_offset + i_subfr, t0.value, t0_frac.value, L_SUBFR);

                /*-------------------------------------------------------*
                * - Decode innovative codebook.                         *
                * - Add the fixed-gain pitch contribution to code[].    *
                *-------------------------------------------------------*/

                if (bfi != 0)
                {
                    /* Bad Frame Error Concealment */
                    parm[parm_offset + 0] = Util.random_g729() & 0x1fff; /* 13 bits random*/
                    parm[parm_offset + 1] = Util.random_g729() & 0x000f; /*  4 bits random */
                }

                DeAcelp.decod_ACELP(parm[parm_offset + 1], parm[parm_offset + 0], code);
                parm_offset += 2;
                for (i = t0.value; i < L_SUBFR; i++)
                {
                    code[i] += sharp * code[i - t0.value];
                }

                /*-------------------------------------------------*
                * - Decode pitch and codebook gains.              *
                *-------------------------------------------------*/

                index = parm[parm_offset]; /* index of energy VQ */
                parm_offset++;
                decGain.dec_gain(index, code, L_SUBFR, bfi, gain_pitch, gain_code);

                /*-------------------------------------------------------------*
                * - Update pitch sharpening "sharp" with quantized gain_pitch *
                *-------------------------------------------------------------*/

                sharp = gain_pitch.value;
                if (sharp > SHARPMAX)
                {
                    sharp = SHARPMAX;
                }
                if (sharp < SHARPMIN)
                {
                    sharp = SHARPMIN;
                }

                /*-------------------------------------------------------*
                * - Find the total excitation.                          *
                *-------------------------------------------------------*/

                if (bfi != 0)
                {
                    if (voicing == 0)
                    {
                        for (i = 0; i < L_SUBFR; i++)
                        {
                            exc[exc_offset + i + i_subfr] = gain_code.value * code[i];
                        }
                    }
                    else
                    {
                        for (i = 0; i < L_SUBFR; i++)
                        {
                            exc[exc_offset + i + i_subfr] = gain_pitch.value * exc[exc_offset + i + i_subfr];
                        }
                    }
                }
                else
                {
                    /* No frame errors */
                    for (i = 0; i < L_SUBFR; i++)
                    {
                        exc[exc_offset + i + i_subfr] =
                            gain_pitch.value * exc[exc_offset + i + i_subfr] + gain_code.value * code[i];
                    }
                }

                /*-------------------------------------------------------*
                * - Find synthesis speech corresponding to exc[].       *
                *-------------------------------------------------------*/

                Filter.syn_filt(
                    Az,
                    Az_offset,
                    exc,
                    exc_offset + i_subfr,
                    synth,
                    synth_offset + i_subfr,
                    L_SUBFR,
                    mem_syn,
                    0,
                    1);

                Az_offset += MP1; /* interpolated LPC parameters for next subframe */
            }

            /*--------------------------------------------------*
            * Update signal for next frame.                    *
            * -> shift to the left by L_FRAME  exc[]           *
            *--------------------------------------------------*/
            Util.copy(old_exc, L_FRAME, old_exc, PIT_MAX + L_INTERPOL);
            return(t0_first);
        }
Esempio n. 15
0
 public static int LoadInt(IntReference reference)
 {
     return(PlayerPrefs.GetInt(reference.Variable.name));
 }
Esempio n. 16
0
 private Task Success9(IntReference a, IntReference a1, IntReference a2, IntReference a3, IntReference a4, IntReference a5, IntReference a6, IntReference a7, IntReference a8)
 {
     return(Task.Run(() => { a.Value = 1; }));
 }
Esempio n. 17
0
 private Task Success2(IntReference a, IntReference a1)
 {
     return(Task.Run(() => { a.Value = 1; }));
 }
Esempio n. 18
0
 private IAsyncResult BeginSuccess1(IntReference a, AsyncCallback callback, object state)
 {
     return AsyncFactory.ToBegin(Success1(a), callback, state);
 }
Esempio n. 19
0
 private Task Success14(IntReference a, IntReference a1, IntReference a2, IntReference a3, IntReference a4, IntReference a5, IntReference a6, IntReference a7, IntReference a8, IntReference a9, IntReference a10, IntReference a11, IntReference a12, IntReference a13)
 {
     return TaskShim.Run(() => { a.Value = 1; });
 }
Esempio n. 20
0
 private Task Success9(IntReference a, IntReference a1, IntReference a2, IntReference a3, IntReference a4, IntReference a5, IntReference a6, IntReference a7, IntReference a8)
 {
     return TaskShim.Run(() => { a.Value = 1; });
 }
Esempio n. 21
0
 private Task Success5(IntReference a, IntReference a1, IntReference a2, IntReference a3, IntReference a4)
 {
     return TaskShim.Run(() => { a.Value = 1; });
 }
Esempio n. 22
0
 private Task Success2(IntReference a, IntReference a1)
 {
     return TaskShim.Run(() => { a.Value = 1; });
 }
Esempio n. 23
0
 private IAsyncResult BeginSuccess14(IntReference a, IntReference a1, IntReference a2, IntReference a3, IntReference a4, IntReference a5, IntReference a6, IntReference a7, IntReference a8, IntReference a9, IntReference a10, IntReference a11, IntReference a12, IntReference a13, AsyncCallback callback, object state)
 {
     return AsyncFactory.ToBegin(Success14(a, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13), callback, state);
 }
Esempio n. 24
0
 private IAsyncResult BeginSuccess8(IntReference a, IntReference a1, IntReference a2, IntReference a3, IntReference a4, IntReference a5, IntReference a6, IntReference a7, AsyncCallback callback, object state)
 {
     return(AsyncFactory.ToBegin(Success8(a, a1, a2, a3, a4, a5, a6, a7), callback, state));
 }
Esempio n. 25
0
 private IAsyncResult BeginSuccess14(IntReference a, IntReference a1, IntReference a2, IntReference a3, IntReference a4, IntReference a5, IntReference a6, IntReference a7, IntReference a8, IntReference a9, IntReference a10, IntReference a11, IntReference a12, IntReference a13, AsyncCallback callback, object state)
 {
     return(AsyncFactory.ToBegin(Success14(a, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13), callback, state));
 }
Esempio n. 26
0
 public void Args14()
 {
     Test.Async(async () =>
     {
         IntReference counter = new IntReference();
         await AsyncFactory.FromApm(BeginSuccess14, End, counter, counter, counter, counter, counter, counter, counter, counter, counter, counter, counter, counter, counter, counter);
         Assert.AreEqual(1, counter.Value);
     });
 }
Esempio n. 27
0
 private Task Success5(IntReference a, IntReference a1, IntReference a2, IntReference a3, IntReference a4)
 {
     return(Task.Run(() => { a.Value = 1; }));
 }
Esempio n. 28
0
 private Task Success4(IntReference a, IntReference a1, IntReference a2, IntReference a3)
 {
     return Task.Run(() => { a.Value = 1; });
 }
Esempio n. 29
0
 private Task Success14(IntReference a, IntReference a1, IntReference a2, IntReference a3, IntReference a4, IntReference a5, IntReference a6, IntReference a7, IntReference a8, IntReference a9, IntReference a10, IntReference a11, IntReference a12, IntReference a13)
 {
     return(Task.Run(() => { a.Value = 1; }));
 }
Esempio n. 30
0
 public void Init(IEnumerable <Enemy> possibleEnemies, int newDifficulty)
 {
     possible   = possibleEnemies.ToArray();
     difficulty = new IntReference(newDifficulty);
 }
 public void Setup_References()
 {
     _primaryReference   = new IntReference(1);
     _secondaryReference = new IntReference(1);
 }
Esempio n. 32
0
        /**
         * Algebraic codebook search 17 bits; 4 pulses 40 sampleframe
         *
         * @param dn        (i) : backward filtered target vector
         * @param rr        (i) : autocorrelations of impulse response h[]
         * @param h         (i) : impulse response of filters
         * @param cod       (o) : selected algebraic codeword
         * @param y         (o) : output: selected algebraic codeword
         * @param signs     (o) : signs of 4 pulses
         * @param i_subfr   (i) subframe flag
         * @return          pulse positions
         */
        private int d4i40_17(
            float[] dn,
            float[] rr,
            float[] h,
            float[] cod,
            float[] y,
            IntReference signs,
            int i_subfr
            )
        {
            var L_SUBFR   = Ld8k.L_SUBFR;
            var MAX_TIME  = Ld8k.MAX_TIME;
            var MSIZE     = Ld8k.MSIZE;
            var NB_POS    = Ld8k.NB_POS;
            var STEP      = Ld8k.STEP;
            var THRESHFCB = Ld8k.THRESHFCB;

            /*
             * The code length is 40, containing 4 nonzero pulses i0, i1, i2, i3.
             * with pulse spacings of step = 5
             * Each pulses can have 8 possible positions (positive or negative):
             *
             * i0 (+-1) : 0, 5, 10, 15, 20, 25, 30, 35
             * i1 (+-1) : 1, 6, 11, 16, 21, 26, 31, 36
             * i2 (+-1) : 2, 7, 12, 17, 22, 27, 32, 37
             * i3 (+-1) : 3, 8, 13, 18, 23, 28, 33, 38
             *            4, 9, 14, 19, 24, 29, 34, 39
             *---------------------------------------------------------------------------
             */
            int   i0, i1, i2, i3, ip0, ip1, ip2, ip3;
            int   i, j, time;
            float ps0, ps1, ps2, ps3, alp0, alp1, alp2, alp3;
            float ps3c, psc, alpha;
            float average, max0, max1, max2, thres;
            var   p_sign = new float[L_SUBFR];

            int rri0i0, rri1i1, rri2i2, rri3i3, rri4i4;
            int rri0i1, rri0i2, rri0i3, rri0i4;
            int rri1i2, rri1i3, rri1i4;
            int rri2i3, rri2i4;

            int ptr_ri0i0, ptr_ri1i1, ptr_ri2i2, ptr_ri3i3, ptr_ri4i4;
            int ptr_ri0i1, ptr_ri0i2, ptr_ri0i3, ptr_ri0i4;
            int ptr_ri1i2, ptr_ri1i3, ptr_ri1i4;
            int ptr_ri2i3, ptr_ri2i4;

            /* Init pointers */

            rri0i0 = 0;
            rri1i1 = rri0i0 + NB_POS;
            rri2i2 = rri1i1 + NB_POS;
            rri3i3 = rri2i2 + NB_POS;
            rri4i4 = rri3i3 + NB_POS;

            rri0i1 = rri4i4 + NB_POS;
            rri0i2 = rri0i1 + MSIZE;
            rri0i3 = rri0i2 + MSIZE;
            rri0i4 = rri0i3 + MSIZE;
            rri1i2 = rri0i4 + MSIZE;
            rri1i3 = rri1i2 + MSIZE;
            rri1i4 = rri1i3 + MSIZE;
            rri2i3 = rri1i4 + MSIZE;
            rri2i4 = rri2i3 + MSIZE;

            /*-----------------------------------------------------------------------*
             * Reset max_time for 1st subframe.                                      *
             *-----------------------------------------------------------------------*
             */
            if (i_subfr == 0)
            {
                extra = 30;
            }

            /*----------------------------------------------------------------------*
             * Chose the signs of the impulses.                                      *
             *-----------------------------------------------------------------------*/

            for (i = 0; i < L_SUBFR; i++)
            {
                if (dn[i] >= 0.0f)
                {
                    p_sign[i] = 1.0f;
                }
                else
                {
                    p_sign[i] = -1.0f;
                    dn[i]     = -dn[i];
                }
            }

            /*-------------------------------------------------------------------*
            * - Compute the search threshold after three pulses                 *
            *-------------------------------------------------------------------*/

            average = dn[0] + dn[1] + dn[2];
            max0    = dn[0];
            max1    = dn[1];
            max2    = dn[2];
            for (i = 5; i < L_SUBFR; i += STEP)
            {
                average += dn[i] + dn[i + 1] + dn[i + 2];
                if (dn[i] > max0)
                {
                    max0 = dn[i];
                }
                if (dn[i + 1] > max1)
                {
                    max1 = dn[i + 1];
                }
                if (dn[i + 2] > max2)
                {
                    max2 = dn[i + 2];
                }
            }

            max0    += max1 + max2;
            average *= 0.125f; /* 1/8 */
            thres    = average + (max0 - average) * THRESHFCB;

            /*-------------------------------------------------------------------*
            * Modification of rrixiy to take into account signs.                *
            *-------------------------------------------------------------------*/
            ptr_ri0i1 = rri0i1;
            ptr_ri0i2 = rri0i2;
            ptr_ri0i3 = rri0i3;
            ptr_ri0i4 = rri0i4;

            for (i0 = 0; i0 < L_SUBFR; i0 += STEP)
            {
                for (i1 = 1; i1 < L_SUBFR; i1 += STEP)
                {
                    rr[ptr_ri0i1] *= p_sign[i0] * p_sign[i1];
                    ptr_ri0i1++;
                    rr[ptr_ri0i2] *= p_sign[i0] * p_sign[i1 + 1];
                    ptr_ri0i2++;
                    rr[ptr_ri0i3] *= p_sign[i0] * p_sign[i1 + 2];
                    ptr_ri0i3++;
                    rr[ptr_ri0i4] *= p_sign[i0] * p_sign[i1 + 3];
                    ptr_ri0i4++;
                }
            }

            ptr_ri1i2 = rri1i2;
            ptr_ri1i3 = rri1i3;
            ptr_ri1i4 = rri1i4;

            for (i1 = 1; i1 < L_SUBFR; i1 += STEP)
            {
                for (i2 = 2; i2 < L_SUBFR; i2 += STEP)
                {
                    rr[ptr_ri1i2] *= p_sign[i1] * p_sign[i2];
                    ptr_ri1i2++;
                    rr[ptr_ri1i3] *= p_sign[i1] * p_sign[i2 + 1];
                    ptr_ri1i3++;
                    rr[ptr_ri1i4] *= p_sign[i1] * p_sign[i2 + 2];
                    ptr_ri1i4++;
                }
            }

            ptr_ri2i3 = rri2i3;
            ptr_ri2i4 = rri2i4;

            for (i2 = 2; i2 < L_SUBFR; i2 += STEP)
            {
                for (i3 = 3; i3 < L_SUBFR; i3 += STEP)
                {
                    rr[ptr_ri2i3] *= p_sign[i2] * p_sign[i3];
                    ptr_ri2i3++;
                    rr[ptr_ri2i4] *= p_sign[i2] * p_sign[i3 + 1];
                    ptr_ri2i4++;
                }
            }

            /*-------------------------------------------------------------------*
            * Search the optimum positions of the four  pulses which maximize   *
            *     square(correlation) / energy                                  *
            * The search is performed in four  nested loops. At each loop, one  *
            * pulse contribution is added to the correlation and energy.        *
            *                                                                   *
            * The fourth loop is entered only if the correlation due to the     *
            *  contribution of the first three pulses exceeds the preset        *
            *  threshold.                                                       *
            *-------------------------------------------------------------------*/

            /* Default values */

            ip0   = 0;
            ip1   = 1;
            ip2   = 2;
            ip3   = 3;
            psc   = 0.0f;
            alpha = 1000000.0f;
            time  = MAX_TIME + extra;

            /* Four loops to search innovation code. */
            ptr_ri0i0 = rri0i0; /* Init. pointers that depend on first loop */
            ptr_ri0i1 = rri0i1;
            ptr_ri0i2 = rri0i2;
            ptr_ri0i3 = rri0i3;
            ptr_ri0i4 = rri0i4;

            for (i0 = 0; i0 < L_SUBFR; i0 += STEP) /* first pulse loop  */
            {
                ps0  = dn[i0];
                alp0 = rr[ptr_ri0i0];
                ptr_ri0i0++;

                ptr_ri1i1 = rri1i1; /* Init. pointers that depend on second loop */
                ptr_ri1i2 = rri1i2;
                ptr_ri1i3 = rri1i3;
                ptr_ri1i4 = rri1i4;

                for (i1 = 1; i1 < L_SUBFR; i1 += STEP) /* second pulse loop */
                {
                    ps1  = ps0 + dn[i1];
                    alp1 = alp0 + rr[ptr_ri1i1] + 2.0f * rr[ptr_ri0i1];
                    ptr_ri1i1++;
                    ptr_ri0i1++;

                    ptr_ri2i2 = rri2i2; /* Init. pointers that depend on third loop */
                    ptr_ri2i3 = rri2i3;
                    ptr_ri2i4 = rri2i4;

                    for (i2 = 2; i2 < L_SUBFR; i2 += STEP)
                    {
                        ps2  = ps1 + dn[i2];
                        alp2 = alp1 + rr[ptr_ri2i2] + 2.0f * (rr[ptr_ri0i2] + rr[ptr_ri1i2]);
                        ptr_ri2i2++;
                        ptr_ri0i2++;
                        ptr_ri1i2++;

                        if (ps2 > thres)
                        {
                            ptr_ri3i3 = rri3i3; /* Init. pointers that depend on 4th loop */

                            for (i3 = 3; i3 < L_SUBFR; i3 += STEP)
                            {
                                ps3  = ps2 + dn[i3];
                                alp3 = alp2 + rr[ptr_ri3i3] + 2.0f * (rr[ptr_ri1i3] + rr[ptr_ri0i3] + rr[ptr_ri2i3]);
                                ptr_ri3i3++;
                                ptr_ri1i3++;
                                ptr_ri0i3++;
                                ptr_ri2i3++;

                                ps3c = ps3 * ps3;
                                if (ps3c * alpha > psc * alp3)
                                {
                                    psc   = ps3c;
                                    alpha = alp3;
                                    ip0   = i0;
                                    ip1   = i1;
                                    ip2   = i2;
                                    ip3   = i3;
                                }
                            } /*  end of for i3 = */

                            ptr_ri0i3 -= NB_POS;
                            ptr_ri1i3 -= NB_POS;

                            ptr_ri4i4 = rri4i4; /* Init. pointers that depend on 4th loop */

                            for (i3 = 4; i3 < L_SUBFR; i3 += STEP)
                            {
                                ps3  = ps2 + dn[i3];
                                alp3 = alp2 + rr[ptr_ri4i4] + 2.0f * (rr[ptr_ri1i4] + rr[ptr_ri0i4] + rr[ptr_ri2i4]);
                                ptr_ri4i4++;
                                ptr_ri1i4++;
                                ptr_ri0i4++;
                                ptr_ri2i4++;

                                ps3c = ps3 * ps3;
                                if (ps3c * alpha > psc * alp3)
                                {
                                    psc   = ps3c;
                                    alpha = alp3;
                                    ip0   = i0;
                                    ip1   = i1;
                                    ip2   = i2;
                                    ip3   = i3;
                                }
                            } /*  end of for i3 = */

                            ptr_ri0i4 -= NB_POS;
                            ptr_ri1i4 -= NB_POS;

                            time--;
                            if (time <= 0)
                            {
                                goto end_search;            /* Maximum time finish */
                            }
                        } /* end of if >thres */
                        else
                        {
                            ptr_ri2i3 += NB_POS;
                            ptr_ri2i4 += NB_POS;
                        }
                    } /* end of for i2 = */

                    ptr_ri0i2 -= NB_POS;
                    ptr_ri1i3 += NB_POS;
                    ptr_ri1i4 += NB_POS;
                } /* end of for i1 = */

                ptr_ri0i2 += NB_POS;
                ptr_ri0i3 += NB_POS;
                ptr_ri0i4 += NB_POS;
            } /* end of for i0 = */

end_search:

            extra = time;

            /* Find the codeword corresponding to the selected positions */

            for (i = 0; i < L_SUBFR; i++)
            {
                cod[i] = 0.0f;
            }
            cod[ip0] = p_sign[ip0];
            cod[ip1] = p_sign[ip1];
            cod[ip2] = p_sign[ip2];
            cod[ip3] = p_sign[ip3];

            /* find the filtered codeword */

            for (i = 0; i < L_SUBFR; i++)
            {
                y[i] = 0.0f;
            }

            if (p_sign[ip0] > 0.0f)
            {
                for (i = ip0, j = 0; i < L_SUBFR; i++, j++)
                {
                    y[i] = h[j];
                }
            }
            else
            {
                for (i = ip0, j = 0; i < L_SUBFR; i++, j++)
                {
                    y[i] = -h[j];
                }
            }

            if (p_sign[ip1] > 0.0f)
            {
                for (i = ip1, j = 0; i < L_SUBFR; i++, j++)
                {
                    y[i] = y[i] + h[j];
                }
            }
            else
            {
                for (i = ip1, j = 0; i < L_SUBFR; i++, j++)
                {
                    y[i] = y[i] - h[j];
                }
            }

            if (p_sign[ip2] > 0.0f)
            {
                for (i = ip2, j = 0; i < L_SUBFR; i++, j++)
                {
                    y[i] = y[i] + h[j];
                }
            }
            else
            {
                for (i = ip2, j = 0; i < L_SUBFR; i++, j++)
                {
                    y[i] = y[i] - h[j];
                }
            }

            if (p_sign[ip3] > 0.0f)
            {
                for (i = ip3, j = 0; i < L_SUBFR; i++, j++)
                {
                    y[i] = y[i] + h[j];
                }
            }
            else
            {
                for (i = ip3, j = 0; i < L_SUBFR; i++, j++)
                {
                    y[i] = y[i] - h[j];
                }
            }

            /* find codebook index;  4 bit signs + 13 bit positions */

            i = 0;
            if (p_sign[ip0] > 0.0f)
            {
                i += 1;
            }
            if (p_sign[ip1] > 0.0f)
            {
                i += 2;
            }
            if (p_sign[ip2] > 0.0f)
            {
                i += 4;
            }
            if (p_sign[ip3] > 0.0f)
            {
                i += 8;
            }
            signs.value = i;

            ip0 = ip0 / 5;
            ip1 = ip1 / 5;
            ip2 = ip2 / 5;
            j   = ip3 % 5 - 3;
            ip3 = ((ip3 / 5) << 1) + j;

            i = ip0 + (ip1 << 3) + (ip2 << 6) + (ip3 << 9);

            return(i);
        }
Esempio n. 33
0
 public static void SaveInt(IntReference reference)
 {
     PlayerPrefs.SetInt(reference.Variable.name, reference);
 }
Esempio n. 34
0
 private Task Success11(IntReference a, IntReference a1, IntReference a2, IntReference a3, IntReference a4, IntReference a5, IntReference a6, IntReference a7, IntReference a8, IntReference a9, IntReference a10)
 {
     return Task.Run(() => { a.Value = 1; });
 }
Esempio n. 35
0
        /**
         * Presearch for gain codebook
         *
         * @param best_gain     input : [0] unquantized pitch gain
         *                              [1] unquantized code gain
         * @param cand1         output: index of best 1st stage vector
         * @param cand2         output: index of best 2nd stage vector
         * @param gcode0        input : presearch for gain codebook
         */
        private void gbk_presel(
            float[] best_gain,
            IntReference cand1,
            IntReference cand2,
            float gcode0
            )
        {
            var INV_COEF = Ld8k.INV_COEF;
            var NCAN1    = Ld8k.NCAN1;
            var NCAN2    = Ld8k.NCAN2;
            var NCODE1   = Ld8k.NCODE1;
            var NCODE2   = Ld8k.NCODE2;
            var coef     = TabLd8k.coef;
            var thr1     = TabLd8k.thr1;
            var thr2     = TabLd8k.thr2;

            int _cand1 = cand1.value, _cand2 = cand2.value;

            float x, y;

            x = (best_gain[1] - (coef[0][0] * best_gain[0] + coef[1][1]) * gcode0) * INV_COEF;
            y = (coef[1][0] * (-coef[0][1] + best_gain[0] * coef[0][0]) * gcode0
                 - coef[0][0] * best_gain[1]) * INV_COEF;

            if (gcode0 > 0.0f)
            {
                /* pre select codebook #1 */
                _cand1 = 0;
                do
                {
                    if (y > thr1[_cand1] * gcode0)
                    {
                        _cand1++;
                    }
                    else
                    {
                        break;
                    }
                }while (_cand1 < NCODE1 - NCAN1);

                /* pre select codebook #2 */
                _cand2 = 0;
                do
                {
                    if (x > thr2[_cand2] * gcode0)
                    {
                        _cand2++;
                    }
                    else
                    {
                        break;
                    }
                }while (_cand2 < NCODE2 - NCAN2);
            }
            else
            {
                /* pre select codebook #1 */
                _cand1 = 0;
                do
                {
                    if (y < thr1[_cand1] * gcode0)
                    {
                        _cand1++;
                    }
                    else
                    {
                        break;
                    }
                }while (_cand1 < NCODE1 - NCAN1);

                /* pre select codebook #2 */
                _cand2 = 0;
                do
                {
                    if (x < thr2[_cand2] * gcode0)
                    {
                        _cand2++;
                    }
                    else
                    {
                        break;
                    }
                }while (_cand2 < NCODE2 - NCAN2);
            }

            cand1.value = _cand1;
            cand2.value = _cand2;
        }
Esempio n. 36
0
 private IAsyncResult BeginSuccess4(IntReference a, IntReference a1, IntReference a2, IntReference a3, AsyncCallback callback, object state)
 {
     return(AsyncFactory.ToBegin(Success4(a, a1, a2, a3), callback, state));
 }
Esempio n. 37
0
        /**
         * Encoder routine ( speech data should be in new_speech ).
         *
         * @param ana   output: analysis parameters
         */

        public void coder_ld8k(
            int[] ana
            )
        {
            /* LPC coefficients */
            var r    = new float[MP1];     /* Autocorrelations low and hi          */
            var A_t  = new float[MP1 * 2]; /* A(z) unquantized for the 2 subframes */
            var Aq_t = new float[MP1 * 2]; /* A(z)   quantized for the 2 subframes */
            var Ap1  = new float[MP1];     /* A(z) with spectral expansion         */
            var Ap2  = new float[MP1];     /* A(z) with spectral expansion         */

            float[] A, Aq;                 /* Pointer on A_t and Aq_t              */
            int     A_offset, Aq_offset;

            /* LSP coefficients */
            float[] lsp_new = new float[M], lsp_new_q = new float[M]; /* LSPs at 2th subframe                 */
            var     lsf_int = new float[M];                           /* Interpolated LSF 1st subframe.       */
            var     lsf_new = new float[M];

            /* Variable added for adaptive gamma1 and gamma2 of the PWF */

            var rc     = new float[M]; /* Reflection coefficients */
            var gamma1 = new float[2]; /* Gamma1 for 1st and 2nd subframes */
            var gamma2 = new float[2]; /* Gamma2 for 1st and 2nd subframes */

            /* Other vectors */
            var synth   = new float[L_FRAME]; /* Buffer for synthesis speech        */
            var h1      = new float[L_SUBFR]; /* Impulse response h1[]              */
            var xn      = new float[L_SUBFR]; /* Target vector for pitch search     */
            var xn2     = new float[L_SUBFR]; /* Target vector for codebook search  */
            var code    = new float[L_SUBFR]; /* Fixed codebook excitation          */
            var y1      = new float[L_SUBFR]; /* Filtered adaptive excitation       */
            var y2      = new float[L_SUBFR]; /* Filtered fixed codebook excitation */
            var g_coeff = new float[5];       /* Correlations between xn, y1, & y2:
                                               * <y1,y1>, <xn,y1>, <y2,y2>, <xn,y2>,<y1,y2>*/

            /* Scalars */

            int            i, j, i_gamma, i_subfr;
            var            iRef = new IntReference();
            int            T_op, t0;
            IntReference   t0_min = new IntReference(), t0_max = new IntReference(), t0_frac = new IntReference();
            int            index, taming;
            float          gain_pit, gain_code = 0.0f;
            FloatReference _gain_pit = new FloatReference(), _gain_code = new FloatReference();

            var ana_offset = 0;

            /*------------------------------------------------------------------------*
            *  - Perform LPC analysis:                                               *
            *       * autocorrelation + lag windowing                                *
            *       * Levinson-durbin algorithm to find a[]                          *
            *       * convert a[] to lsp[]                                           *
            *       * quantize and code the LSPs                                     *
            *       * find the interpolated LSPs and convert to a[] for the 2        *
            *         subframes (both quantized and unquantized)                     *
            *------------------------------------------------------------------------*/

            /* LP analysis */

            Lpc.autocorr(p_window, p_window_offset, M, r); /* Autocorrelations */
            Lpc.lag_window(M, r);                          /* Lag windowing    */
            Lpc.levinson(r, A_t, MP1, rc);                 /* Levinson Durbin  */
            Lpc.az_lsp(A_t, MP1, lsp_new, lsp_old);        /* From A(z) to lsp */

            /* LSP quantization */

            quaLsp.qua_lsp(lsp_new, lsp_new_q, ana);
            ana_offset += 2; /* Advance analysis parameters pointer */

            /*--------------------------------------------------------------------*
            * Find interpolated LPC parameters in all subframes (both quantized  *
            * and unquantized).                                                  *
            * The interpolated parameters are in array A_t[] of size (M+1)*4     *
            * and the quantized interpolated parameters are in array Aq_t[]      *
            *--------------------------------------------------------------------*/

            Lpcfunc.int_lpc(lsp_old, lsp_new, lsf_int, lsf_new, A_t);
            Lpcfunc.int_qlpc(lsp_old_q, lsp_new_q, Aq_t);

            /* update the LSPs for the next frame */

            for (i = 0; i < M; i++)
            {
                lsp_old[i]   = lsp_new[i];
                lsp_old_q[i] = lsp_new_q[i];
            }

            /*----------------------------------------------------------------------*
            * - Find the weighting factors                                         *
            *----------------------------------------------------------------------*/

            pwf.perc_var(gamma1, gamma2, lsf_int, lsf_new, rc);

            /*----------------------------------------------------------------------*
            * - Find the weighted input speech w_sp[] for the whole speech frame   *
            * - Find the open-loop pitch delay for the whole speech frame          *
            * - Set the range for searching closed-loop pitch in 1st subframe      *
            *----------------------------------------------------------------------*/

            Lpcfunc.weight_az(A_t, 0, gamma1[0], M, Ap1);
            Lpcfunc.weight_az(A_t, 0, gamma2[0], M, Ap2);
            Filter.residu(Ap1, 0, speech, speech_offset, wsp, wsp_offset, L_SUBFR);
            Filter.syn_filt(Ap2, 0, wsp, wsp_offset, wsp, wsp_offset, L_SUBFR, mem_w, 0, 1);

            Lpcfunc.weight_az(A_t, MP1, gamma1[1], M, Ap1);
            Lpcfunc.weight_az(A_t, MP1, gamma2[1], M, Ap2);
            Filter.residu(Ap1, 0, speech, speech_offset + L_SUBFR, wsp, wsp_offset + L_SUBFR, L_SUBFR);
            Filter.syn_filt(Ap2, 0, wsp, wsp_offset + L_SUBFR, wsp, wsp_offset + L_SUBFR, L_SUBFR, mem_w, 0, 1);

            /* Find open loop pitch lag for whole speech frame */

            T_op = Pitch.pitch_ol(wsp, wsp_offset, PIT_MIN, PIT_MAX, L_FRAME);

            /* range for closed loop pitch search in 1st subframe */

            t0_min.value = T_op - 3;
            if (t0_min.value < PIT_MIN)
            {
                t0_min.value = PIT_MIN;
            }
            t0_max.value = t0_min.value + 6;
            if (t0_max.value > PIT_MAX)
            {
                t0_max.value = PIT_MAX;
                t0_min.value = t0_max.value - 6;
            }

            /*------------------------------------------------------------------------*
            *          Loop for every subframe in the analysis frame                 *
            *------------------------------------------------------------------------*
            *  To find the pitch and innovation parameters. The subframe size is     *
            *  L_SUBFR and the loop is repeated L_FRAME/L_SUBFR times.               *
            *     - find the weighted LPC coefficients                               *
            *     - find the LPC residual signal                                     *
            *     - compute the target signal for pitch search                       *
            *     - compute impulse response of weighted synthesis filter (h1[])     *
            *     - find the closed-loop pitch parameters                            *
            *     - encode the pitch delay                                           *
            *     - update the impulse response h1[] by including fixed-gain pitch   *
            *     - find target vector for codebook search                           *
            *     - codebook search                                                  *
            *     - encode codebook address                                          *
            *     - VQ of pitch and codebook gains                                   *
            *     - find synthesis speech                                            *
            *     - update states of weighting filter                                *
            *------------------------------------------------------------------------*/

            A         = A_t;  /* pointer to interpolated LPC parameters           */
            A_offset  = 0;
            Aq        = Aq_t; /* pointer to interpolated quantized LPC parameters */
            Aq_offset = 0;

            i_gamma = 0;

            for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR)
            {
                /*---------------------------------------------------------------*
                * Find the weighted LPC coefficients for the weighting filter.  *
                *---------------------------------------------------------------*/

                Lpcfunc.weight_az(A, A_offset, gamma1[i_gamma], M, Ap1);
                Lpcfunc.weight_az(A, A_offset, gamma2[i_gamma], M, Ap2);
                i_gamma++;

                /*---------------------------------------------------------------*
                * Compute impulse response, h1[], of weighted synthesis filter  *
                *---------------------------------------------------------------*/

                for (i = 0; i <= M; i++)
                {
                    ai_zero[i] = Ap1[i];
                }
                Filter.syn_filt(Aq, Aq_offset, ai_zero, 0, h1, 0, L_SUBFR, zero, zero_offset, 0);
                Filter.syn_filt(Ap2, 0, h1, 0, h1, 0, L_SUBFR, zero, zero_offset, 0);

                /*------------------------------------------------------------------------*
                *                                                                        *
                *          Find the target vector for pitch search:                      *
                *          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                       *
                *                                                                        *
                *              |------|  res[n]                                          *
                *  speech[n]---| A(z) |--------                                          *
                *              |------|       |   |--------| error[n]  |------|          *
                *                    zero -- (-)--| 1/A(z) |-----------| W(z) |-- target *
                *                    exc          |--------|           |------|          *
                *                                                                        *
                * Instead of subtracting the zero-input response of filters from         *
                * the weighted input speech, the above configuration is used to          *
                * compute the target vector. This configuration gives better performance *
                * with fixed-point implementation. The memory of 1/A(z) is updated by    *
                * filtering (res[n]-exc[n]) through 1/A(z), or simply by subtracting     *
                * the synthesis speech from the input speech:                            *
                *    error[n] = speech[n] - syn[n].                                      *
                * The memory of W(z) is updated by filtering error[n] through W(z),      *
                * or more simply by subtracting the filtered adaptive and fixed          *
                * codebook excitations from the target:                                  *
                *     target[n] - gain_pit*y1[n] - gain_code*y2[n]                       *
                * as these signals are already available.                                *
                *                                                                        *
                *------------------------------------------------------------------------*/

                Filter.residu(
                    Aq,
                    Aq_offset,
                    speech,
                    speech_offset + i_subfr,
                    exc,
                    exc_offset + i_subfr,
                    L_SUBFR); /* LPC residual */

                Filter.syn_filt(Aq, Aq_offset, exc, exc_offset + i_subfr, error, error_offset, L_SUBFR, mem_err, 0, 0);

                Filter.residu(Ap1, 0, error, error_offset, xn, 0, L_SUBFR);

                Filter.syn_filt(Ap2, 0, xn, 0, xn, 0, L_SUBFR, mem_w0, 0, 0); /* target signal xn[]*/

                /*----------------------------------------------------------------------*
                *                 Closed-loop fractional pitch search                  *
                *----------------------------------------------------------------------*/

                t0 = Pitch.pitch_fr3(
                    exc,
                    exc_offset + i_subfr,
                    xn,
                    h1,
                    L_SUBFR,
                    t0_min.value,
                    t0_max.value,
                    i_subfr,
                    t0_frac);

                index = Pitch.enc_lag3(t0, t0_frac.value, t0_min, t0_max, PIT_MIN, PIT_MAX, i_subfr);

                ana[ana_offset] = index;
                ana_offset++;
                if (i_subfr == 0)
                {
                    ana[ana_offset] = PParity.parity_pitch(index);
                    ana_offset++;
                }

                /*-----------------------------------------------------------------*
                *   - find unity gain pitch excitation (adaptive codebook entry)  *
                *     with fractional interpolation.                              *
                *   - find filtered pitch exc. y1[]=exc[] convolve with h1[])     *
                *   - compute pitch gain and limit between 0 and 1.2              *
                *   - update target vector for codebook search                    *
                *   - find LTP residual.                                          *
                *-----------------------------------------------------------------*/

                PredLt3.pred_lt_3(exc, exc_offset + i_subfr, t0, t0_frac.value, L_SUBFR);

                Filter.convolve(exc, exc_offset + i_subfr, h1, y1, L_SUBFR);

                gain_pit = Pitch.g_pitch(xn, y1, g_coeff, L_SUBFR);

                /* clip pitch gain if taming is necessary */
                taming = this.taming.test_err(t0, t0_frac.value);

                if (taming == 1)
                {
                    if (gain_pit > GPCLIP)
                    {
                        gain_pit = GPCLIP;
                    }
                }

                for (i = 0; i < L_SUBFR; i++)
                {
                    xn2[i] = xn[i] - y1[i] * gain_pit;
                }

                /*-----------------------------------------------------*
                * - Innovative codebook search.                       *
                *-----------------------------------------------------*/

                iRef.value      = i;
                index           = acelpCo.ACELP_codebook(xn2, h1, t0, sharp, i_subfr, code, y2, iRef);
                i               = iRef.value;
                ana[ana_offset] = index; /* Positions index */
                ana_offset++;
                ana[ana_offset] = i;     /* Signs index     */
                ana_offset++;

                /*-----------------------------------------------------*
                * - Quantization of gains.                            *
                *-----------------------------------------------------*/
                CorFunc.corr_xy2(xn, y1, y2, g_coeff);

                _gain_pit.value  = gain_pit;
                _gain_code.value = gain_code;
                ana[ana_offset]  = quaGain.qua_gain(code, g_coeff, L_SUBFR, _gain_pit, _gain_code, taming);
                gain_pit         = _gain_pit.value;
                gain_code        = _gain_code.value;
                ana_offset++;

                /*------------------------------------------------------------*
                * - Update pitch sharpening "sharp" with quantized gain_pit  *
                *------------------------------------------------------------*/

                sharp = gain_pit;
                if (sharp > SHARPMAX)
                {
                    sharp = SHARPMAX;
                }
                if (sharp < SHARPMIN)
                {
                    sharp = SHARPMIN;
                }

                /*------------------------------------------------------*
                * - Find the total excitation                          *
                * - find synthesis speech corresponding to exc[]       *
                * - update filters' memories for finding the target    *
                *   vector in the next subframe                        *
                *   (update error[-m..-1] and mem_w0[])                *
                *   update error function for taming process           *
                *------------------------------------------------------*/

                for (i = 0; i < L_SUBFR; i++)
                {
                    exc[exc_offset + i + i_subfr] = gain_pit * exc[exc_offset + i + i_subfr] + gain_code * code[i];
                }

                this.taming.update_exc_err(gain_pit, t0);

                Filter.syn_filt(Aq, Aq_offset, exc, exc_offset + i_subfr, synth, i_subfr, L_SUBFR, mem_syn, 0, 1);

                for (i = L_SUBFR - M, j = 0; i < L_SUBFR; i++, j++)
                {
                    mem_err[j] = speech[speech_offset + i_subfr + i] - synth[i_subfr + i];
                    mem_w0[j]  = xn[i] - gain_pit * y1[i] - gain_code * y2[i];
                }

                A_offset  += MP1; /* interpolated LPC parameters for next subframe */
                Aq_offset += MP1;
            }

            /*--------------------------------------------------*
            * Update signal for next frame.                    *
            * -> shift to the left by L_FRAME:                 *
            *     speech[], wsp[] and  exc[]                   *
            *--------------------------------------------------*/

            Util.copy(old_speech, L_FRAME, old_speech, L_TOTAL - L_FRAME);
            Util.copy(old_wsp, L_FRAME, old_wsp, PIT_MAX);
            Util.copy(old_exc, L_FRAME, old_exc, PIT_MAX + L_INTERPOL);
        }
Esempio n. 38
0
 private IAsyncResult BeginSuccess4(IntReference a, IntReference a1, IntReference a2, IntReference a3, AsyncCallback callback, object state)
 {
     return AsyncFactory.ToBegin(Success4(a, a1, a2, a3), callback, state);
 }
Esempio n. 39
0
        //public float FireRate
        //{
        //    get { return fireRate; }
        //    set { fireRate = value; }
        //}

        /// <summary>
        /// Set the total Ammo (Refill when you got some ammo)
        /// </summary>
        /// <param name="value"></param>
        public void SetTotalAmmo(int value)
        {
            Ammo = value;
        }
Esempio n. 40
0
 private Task Success1(IntReference a)
 {
     return Task.Run(() => { a.Value = 1; });
 }
Esempio n. 41
0
 private IAsyncResult BeginSuccess1(IntReference a, AsyncCallback callback, object state)
 {
     return(AsyncFactory.ToBegin(Success1(a), callback, state));
 }
Esempio n. 42
0
 private Task Success7(IntReference a, IntReference a1, IntReference a2, IntReference a3, IntReference a4, IntReference a5, IntReference a6)
 {
     return Task.Run(() => { a.Value = 1; });
 }
Esempio n. 43
0
 private void SetCurrentStage(int i)
 {
     CurrentStageIndex = i;
     currentStageChangedEvent.Raise(i);
 }
Esempio n. 44
0
 public void Args9()
 {
     AsyncContext.Run(async () =>
     {
         IntReference counter = new IntReference();
         await AsyncFactory.FromApm(BeginSuccess9, End, counter, counter, counter, counter, counter, counter, counter, counter, counter);
         Assert.AreEqual(1, counter.Value);
     });
 }