Esempio n. 1
0
        public static int ms_mgau_mllr_transform(ps_mgau_t s,
                                                 Pointer <ps_mllr_t> mllr)
        {
            ms_mgau_model_t msg = (ms_mgau_model_t)s;

            return(ms_gauden.gauden_mllr_transform(msg.g, mllr, msg.config));
        }
Esempio n. 2
0
        public static void ms_mgau_free(ps_mgau_t mg)
        {
            ms_mgau_model_t msg = (ms_mgau_model_t)mg;

            if (msg == null)
            {
                return;
            }

            if (msg.g.IsNonNull)
            {
                ms_gauden.gauden_free(msg.g);
            }
            if (msg.s.IsNonNull)
            {
                ms_senone.senone_free(msg.s);
            }
            if (msg.dist.IsNonNull)
            {
                ckd_alloc.ckd_free_3d(msg.dist);
            }
            if (msg.mgau_active.IsNonNull)
            {
                ckd_alloc.ckd_free(msg.mgau_active);
            }
        }
Esempio n. 3
0
        public static int ptm_mgau_mllr_transform(ps_mgau_t ps,
                                                  Pointer <ps_mllr_t> mllr)
        {
            ptm_mgau_t s = (ptm_mgau_t)ps;

            return(ms_gauden.gauden_mllr_transform(s.g, mllr, s.config));
        }
Esempio n. 4
0
        public static void ptm_mgau_free(ps_mgau_t ps)
        {
            int        i;
            ptm_mgau_t s = (ptm_mgau_t)ps;

            logmath.logmath_free(s.lmath);
            logmath.logmath_free(s.lmath_8b);
            ckd_alloc.ckd_free_3d(s.mixw);
            ckd_alloc.ckd_free(s.sen2cb);

            for (i = 0; i < s.n_fast_hist; i++)
            {
                ckd_alloc.ckd_free_3d(s.hist[i].topn);
                bitvec.bitvec_free(s.hist[i].mgau_active);
            }
            ckd_alloc.ckd_free(s.hist);

            ms_gauden.gauden_free(s.g);
        }
Esempio n. 5
0
        public static int ms_cont_mgau_frame_eval(ps_mgau_t mg,
                                                  Pointer <short> senscr,
                                                  Pointer <byte> senone_active,
                                                  int n_senone_active,
                                                  Pointer <Pointer <float> > feats,
                                                  int frame,
                                                  int compallsen)
        {
            ms_mgau_model_t    msg = (ms_mgau_model_t)mg;
            int                gid;
            int                topn;
            int                best;
            Pointer <gauden_t> g;
            Pointer <senone_t> sen;

            topn = ms_mgau_topn(msg);
            g    = ms_mgau_gauden(msg);
            sen  = ms_mgau_senone(msg);

            if (compallsen != 0)
            {
                int s;

                for (gid = 0; gid < g.Deref.n_mgau; gid++)
                {
                    ms_gauden.gauden_dist(g, gid, topn, feats, msg.dist[gid]);
                }

                best = (int)0x7fffffff;
                for (s = 0; s < sen.Deref.n_sen; s++)
                {
                    senscr[s] = checked ((short)(ms_senone.senone_eval(sen, s, msg.dist[sen.Deref.mgau[s]], topn)));
                    if (best > senscr[s])
                    {
                        best = senscr[s];
                    }
                }

                /* Normalize senone scores */
                for (s = 0; s < sen.Deref.n_sen; s++)
                {
                    int bs = senscr[s] - best;
                    if (bs > 32767)
                    {
                        bs = 32767;
                    }
                    if (bs < -32768)
                    {
                        bs = -32768;
                    }
                    senscr[s] = checked ((short)bs);
                }
            }
            else
            {
                int i, n;
                /* Flag all active mixture-gaussian codebooks */
                for (gid = 0; gid < g.Deref.n_mgau; gid++)
                {
                    msg.mgau_active[gid] = 0;
                }

                n = 0;
                for (i = 0; i < n_senone_active; i++)
                {
                    /* senone_active consists of deltas. */
                    int s = senone_active[i] + n;
                    msg.mgau_active[sen.Deref.mgau[s]] = 1;
                    n = s;
                }

                /* Compute topn gaussian density values (for active codebooks) */
                for (gid = 0; gid < g.Deref.n_mgau; gid++)
                {
                    if (msg.mgau_active[gid] != 0)
                    {
                        ms_gauden.gauden_dist(g, gid, topn, feats, msg.dist[gid]);
                    }
                }

                best = (int)0x7fffffff;
                n    = 0;
                for (i = 0; i < n_senone_active; i++)
                {
                    int s = senone_active[i] + n;
                    senscr[s] = checked ((short)ms_senone.senone_eval(sen, s, msg.dist[sen.Deref.mgau[s]], topn));
                    if (best > senscr[s])
                    {
                        best = senscr[s];
                    }
                    n = s;
                }

                /* Normalize senone scores */
                n = 0;
                for (i = 0; i < n_senone_active; i++)
                {
                    int s  = senone_active[i] + n;
                    int bs = senscr[s] - best;
                    if (bs > 32767)
                    {
                        bs = 32767;
                    }
                    if (bs < -32768)
                    {
                        bs = -32768;
                    }
                    senscr[s] = checked ((short)bs);
                    n         = s;
                }
            }

            return(0);
        }
Esempio n. 6
0
        /**
         * Compute senone scores for the active senones.
         */
        public static int ptm_mgau_frame_eval(ps_mgau_t ps,
                                              Pointer <short> senone_scores,
                                              Pointer <byte> senone_active,
                                              int n_senone_active,
                                              Pointer <Pointer <float> > featbuf,
                                              int frame,
                                              int compallsen)
        {
            ptm_mgau_t s = (ptm_mgau_t)ps;
            int        fast_eval_idx;

            /* Find the appropriate frame in the rotating history buffer
             * corresponding to the requested input frame.  No bounds checking
             * is done here, which just means you'll get semi-random crap if
             * you request a frame in the future or one that's too far in the
             * past.  Since the history buffer is just used for fast match
             * that might not be fatal. */
            fast_eval_idx = frame % s.n_fast_hist;
            s.f           = s.hist + fast_eval_idx;

            /* Compute the top-N codewords for every codebook, unless this
             * is a past frame, in which case we already have them (we
             * hope!) */
            if (frame >= ps.frame_idx)
            {
                Pointer <ptm_fast_eval_t> lastf;

                /* Get the previous frame's top-N information (on the
                 * first frame of the input this is just all WORST_DIST,
                 * no harm in that) */
                if (fast_eval_idx == 0)
                {
                    lastf = s.hist + s.n_fast_hist - 1;
                }
                else
                {
                    lastf = s.hist + fast_eval_idx - 1;
                }
                /* Copy in initial top-N info */
                // LOGAN modified - need to do a deep copy of the data here because it is a struct
                for (int c = 0; c < s.g.Deref.n_mgau * s.g.Deref.n_feat * s.max_topn; c++)
                {
                    s.f.Deref.topn[0][0].Set(c, new ptm_topn_t()
                    {
                        cw    = lastf.Deref.topn[0][0][c].cw,
                        score = lastf.Deref.topn[0][0][c].score
                    });
                }

                /* Generate initial active codebook list (this might not be
                 * necessary) */
                ptm_mgau_calc_cb_active(s, senone_active, n_senone_active, compallsen);
                /* Now evaluate top-N, prune, and evaluate remaining codebooks. */
                ptm_mgau_codebook_eval(s, featbuf, frame);
                ptm_mgau_codebook_norm(s, featbuf, frame);
            }
            /* Evaluate intersection of active senones and active codebooks. */
            ptm_mgau_senone_eval(s, senone_scores, senone_active,
                                 n_senone_active, compallsen);

            return(0);
        }