Beispiel #1
0
        // The trivals are hardcoded in TrigramTable.dat and none of them check
        // true for the condition specified in this function.

/*		static Trival GetTrival(string vis2, string vis1, string vis0)
 *              {
 #if DEBUG
 *                      logfile.Log("FxeData.GetTrival() vis2= " + vis2 + " vis1= " + vis1 + " vis0= " + vis0);
 *                      return TriGramTable[vis2][vis1][vis0];
 #endif
 *                      Trival trival = TriGramTable[vis2][vis1][vis0];
 *                      if (Math.Abs(trival.length) < StaticData.EPSILON)
 *                      {
 *                              Trival trival0;
 *                              foreach (KeyValuePair<string, Dictionary<string, Dictionary<string, Trival>>> pair in TriGramTable)
 *                              {
 *                                      trival0 = pair.Value[vis1][vis0];
 *                                      if (trival0.count > trival.count)
 *                                      {
 #if DEBUG
 *                                              logfile.Log(". Remap TRIVAL");
 #endif
 *                                              trival = trival0;
 *                                      }
 *                              }
 *                      }
 *                      return trival;
 *              } */

        /// <summary>
        /// Adds lists of datablocks to an FXE-data dictionary.
        /// </summary>
        /// <param name="datablocks"></param>
        /// <param name="fxedata"></param>
        static void AddDatablocks(IList <FxeDataBlock> datablocks, Dictionary <string, List <FxeDataBlock> > fxedata)
        {
#if DEBUG
            logfile.Log("FxeData.AddDatablocks()");
#endif
            StaticData.CreateViscodeLists(fxedata);

            for (int i = 0; i != datablocks.Count; ++i)
            {
                FxeDataBlock datablock = datablocks[i];

                if (i != 0 && Math.Abs(datablock.Point - datablocks[i - 1].Point) < StaticData.EPSILON)
                {
                    // force the x-values (stop values) to never be equal
//					if (i + 1 < datablocks.Count)
//					{
//						datablock.Point += Math.Min(StaticData.STOP_INCR,
//													(datablocks[i + 1].Point - datablock.Weight) / 2f); // TODO: wtf.
//					}
//					else
                    datablock.Point += StaticData.STOP_INCR;
                }

                fxedata[datablock.Label].Add(datablock);
            }
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="datablocks"></param>
        /// <param name="datablock"></param>
        /// <param name="id"></param>
        static void InsertIntersectionPoint(IList <FxeDataBlock> datablocks, FxeDataBlock datablock, int id)
        {
            while (datablock.Point > datablocks[id].Point && id < datablocks.Count)
            {
                ++id;
            }

            if (id < datablocks.Count)
            {
                datablocks.Insert(id, datablock);
            }
            else
            {
                datablocks.Add(datablock);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Generates FXE-data.
        /// </summary>
        /// <param name="ars">a list of <see cref="OrthographicResult"/></param>
        /// <param name="fxedata">a dictionary of lists of <see cref="FxeDataBlock"/>'s
        /// mapped to viscodes</param>
        internal static void GenerateData(List <OrthographicResult> ars, Dictionary <string, List <FxeDataBlock> > fxedata)
        {
#if DEBUG
            logfile.Log();
            logfile.Log("FxeData.GenerateData() ars.Count= " + ars.Count);
#endif
            var visuals = new List <KeyValuePair <string, decimal> >();

            string phon;
            foreach (OrthographicResult ar in ars)
            {
#if DEBUG
                logfile.Log(". word= " + ar.Orthography);
#endif
                for (int i = 0; i != ar.Phons.Count; ++i)
                {
                    if ((phon = ar.Phons[i]) != StaticData.SIL &&
                        phon != "~")                            // nasalvowel signifier
                    {
#if DEBUG
                        string log = ". . " + phon + " -> ";
#endif
                        if (StaticData.Vices.ContainsKey(phon))                         // fudge ->
                        {
                            string vis = StaticData.Vices[phon];
#if DEBUG
                            log += vis + " " + ar.phStops[i];
#endif
                            visuals.Add(new KeyValuePair <string, decimal>(vis, ar.phStops[i]));
                        }
#if DEBUG
                        else
                        {
                            log += "INVALID";
                        }
                        logfile.Log(log);
#endif
                    }
                }
            }

#if DEBUG
            logfile.Log();
#endif

            var datablocks = new List <FxeDataBlock>();

            Trival trival;
            string vis2 = "S";
            string vis1 = "S";
            int    id   = 0;

            foreach (KeyValuePair <string, decimal> visual in visuals)
            {
                string vis0 = visual.Key;                               // viscode
                float  stop = (float)visual.Value;                      // phStop

                trival = TriGramTable[vis2][vis1][vis0];                //GetTrival(vis2, vis1, vis0)
                float strt = Math.Max(0f, stop - trival.duration);
                float midl = Math.Max(0f, stop - trival.duration / 2f); // TODO: this could be t=0 -> should be deleted.

                var blocka = new FxeDataBlock(vis0, strt, 0f, FxeDataType.Strt, id);
                var blockb = new FxeDataBlock(vis0, midl, trival.weight, FxeDataType.Midl, id);
                var blockc = new FxeDataBlock(vis0, stop, 0f, FxeDataType.Stop, id);
#if DEBUG
                logfile.Log("viscode= [" + vis2 + "][" + vis1 + "][" + vis0 + "] trival.duration= " + trival.duration);
                logfile.Log("BLOCK A");
                logfile.Log(blocka.ToString());
                logfile.Log("BLOCK B");
                logfile.Log(blockb.ToString());
                logfile.Log("BLOCK C");
                logfile.Log(blockc.ToString());
#endif
                datablocks.Add(blocka);
                datablocks.Add(blockb);
                datablocks.Add(blockc);
                ++id;

                vis2 = vis1;
                vis1 = vis0;
            }
            datablocks.Sort();

            AddDatablocks(datablocks, fxedata);
            SmoothTransitions(fxedata);             // TODO - test
        }
Beispiel #4
0
        static bool _d;         // debug.
#endif
        #endregion fields (static)


        #region write methods (static)
        /// <summary>
        /// Reads an FXE-file and stores its data in a dictionary.
        /// </summary>
        /// <param name="pfe">fullpath of the FXE-file input</param>
        /// <param name="fxedata">pointer to store the data</param>
        /// <returns>true if the FXE-file exists</returns>
        internal static bool ReadFile(string pfe, Dictionary <string, List <FxeDataBlock> > fxedata)
        {
#if DEBUG
            _d = true;
            logfile.Log("FxeReader.ReadFile()");
            logfile.Log(". pfe= " + pfe);
#endif
            if (File.Exists(pfe))
            {
                StaticData.CreateViscodeLists(fxedata);

                using (var fs = new FileStream(pfe, FileMode.Open, FileAccess.Read, FileShare.Read))
                {
                    _br = new BinaryReader(fs);
#if DEBUG
                    if (_d)
                    {
                        logfile.Log(". _br.length= " + _br.BaseStream.Length);
                    }
#endif
                    fs.Seek(85, SeekOrigin.Begin);
                    string head = GetString();
                    if (head == null)
                    {
                        return(false);
                    }
#if DEBUG
                    logfile.Log(". head= " + head);
#endif
                    fs.Seek(34, SeekOrigin.Current);
                    string label = GetString();
                    if (label == null)
                    {
                        return(false);
                    }
#if DEBUG
                    logfile.Log(". label= " + label);
#endif
                    fs.Seek(8, SeekOrigin.Current);
                    short viscodecount = _br.ReadInt16();
#if DEBUG
                    logfile.Log(". viscodecount= " + viscodecount);
#endif
                    fs.Seek(8, SeekOrigin.Current);

                    // Each block is identified by a viscode.
                    // NOTE: there are 25 blocks but the last 10 are facial
                    // gestures that are not used.
                    // But they are not necessarily in the order you'd expect
                    // ... the OC uses all 25 viscodes but SoZ uses the last 10
                    // viscodes only.
                    // TODO: bypass facial gestures - blocks #15..#24
//					for (int i = 0; i != 15; ++i)
                    for (int i = 0; i != viscodecount; ++i)
                    {
#if DEBUG
                        if (_d)
                        {
                            logfile.Log();
                            logfile.Log(". . i= " + i);
                        }
#endif
                        string viscode = GetString();
                        if (viscode == null)
                        {
                            return(false);
                        }
#if DEBUG
                        if (_d)
                        {
                            logfile.Log(". . viscode= " + viscode);
                        }
#endif
                        fs.Seek(8, SeekOrigin.Current);                                                 // 8 bytes of zeroes
                        short blockcount = _br.ReadInt16();
#if DEBUG
                        if (_d)
                        {
                            logfile.Log(". . blockcount= " + blockcount);
                        }
#endif
                        fs.Seek(4, SeekOrigin.Current);                                                 // 4 bytes of zeroes

                        for (short j = 0; j != blockcount; ++j)
                        {
#if DEBUG
                            if (_d)
                            {
                                logfile.Log(". . . j= " + j);
                            }
#endif
                            float val1 = _br.ReadSingle();
                            float val2 = _br.ReadSingle();
#if DEBUG
                            if (_d)
                            {
                                logfile.Log(". . . val1= " + val1);
                            }
                            if (_d)
                            {
                                logfile.Log(". . . val2= " + val2);
                            }
#endif
                            fs.Seek(10, SeekOrigin.Current);                                            // 10 bytes of zeroes

                            var block = new FxeDataBlock(viscode, val1, val2, FxeDataType.Strt, 0);
                            fxedata[viscode].Add(block);
                        }
                        fs.Seek(4, SeekOrigin.Current);                                                 // 4 bytes of zeroes
                    }
                    _br.Close();
                }
                return(true);
            }
            return(false);
        }