예제 #1
0
        public void run()
        {
            TempoVector tv = new TempoVector();

            tv.Add(new TempoTableEntry(0, 500000, 0.0));
            tv.Add(new TempoTableEntry(1920, 500000, 0.0));
            tv.Add(new TempoTableEntry(3820, 500000, 0.0));
            tv.updateTempoInfo();
            for (int i = 0; i < tv.Count; i++)
            {
                TempoTableEntry itemi = tv[i];
                sout.println("   #" + i + "; " + itemi.Clock + "; " + itemi.Time + "; " + (60e6 / itemi.Tempo));
            }
            TempoVectorSearchContext c = new TempoVectorSearchContext();

            sout.println("getClockFromSec; time=1.0; c.mSec2ClockIndex=" + c.mSec2ClockIndex + "; c.mSec2ClockSec=" + c.mSec2ClockSec);
            double cl = tv.getClockFromSec(1.0, c);

            sout.println("cl=" + cl + "; c.mSec2ClockIndex=" + c.mSec2ClockIndex + "; c.mSec2ClockSec=" + c.mSec2ClockSec);

            sout.println("getClockFromSec; time=2.5; c.mSec2ClockIndex=" + c.mSec2ClockIndex + "; c.mSec2ClockSec=" + c.mSec2ClockSec);
            cl = tv.getClockFromSec(2.5, c);
            sout.println("cl=" + cl + "; c.mSec2ClockIndex=" + c.mSec2ClockIndex + "; c.mSec2ClockSec=" + c.mSec2ClockSec);

            sout.println("getClockFromSec; time=4.0; c.mSec2ClockIndex=" + c.mSec2ClockIndex + "; c.mSec2ClockSec=" + c.mSec2ClockSec);
            cl = tv.getClockFromSec(4.0, c);
            sout.println("cl=" + cl + "; c.mSec2ClockIndex=" + c.mSec2ClockIndex + "; c.mSec2ClockSec=" + c.mSec2ClockSec);
        }
예제 #2
0
        /// <summary>
        /// 指定した時刻におけるゲートタイムを取得します.
        /// このメソッドでは検索コンテキストを用い,取得したいtimeの値が順に大きくなる状況でこのメソッドの実行速度の高速化を図ります
        /// </summary>
        /// <param name="time">ゲートタイムを取得する時刻(秒)</param>
        /// <param name="context">計算を高速化するための検索コンテキスト</param>
        /// <returns>ゲートタイム</returns>
        public double getClockFromSec(double time, TempoVectorSearchContext context)
        {
            int    tempo      = baseTempo;
            double base_clock = 0;
            double base_time  = 0.0;
            int    c          = Count;

            if (c == 0)
            {
                tempo      = baseTempo;
                base_clock = 0;
                base_time  = 0.0;
            }
            else if (c == 1)
            {
                TempoTableEntry t0 = this[0];
                tempo      = t0.Tempo;
                base_clock = t0.Clock;
                base_time  = t0.Time;
            }
            else
            {
                int i0 = 0;
                if (context != null)
                {
                    if (time >= context.mSec2ClockSec)
                    {
                        // 探そうとしている時刻が前回検索時の時刻と同じかそれ以降の場合
                        i0 = context.mSec2ClockIndex;
                    }
                    else
                    {
                        // リセットする
                        context.mSec2ClockIndex = 0;
                    }
                    context.mSec2ClockSec = time;
                }
                TempoTableEntry prev = null;
                for (int i = i0; i < c; i++)
                {
                    TempoTableEntry item = this[i];
                    if (time <= item.Time)
                    {
                        if (context != null)
                        {
                            context.mSec2ClockIndex = i > 0 ? i - 1 : 0;
                        }
                        break;
                    }
                    prev = item;
                }
                if (prev != null)
                {
                    base_time  = prev.Time;
                    base_clock = prev.Clock;
                    tempo      = prev.Tempo;
                }
            }
            double dt = time - base_time;

            return(base_clock + dt * gatetimePerQuater * 1000000.0 / (double)tempo);
        }