コード例 #1
0
ファイル: Clock.cs プロジェクト: 8ude/FrogRhythms
        void Update()
        {
            if (!_initialized)
            {
                return;
            }
            if (TimeLineControlled)
            {
                //Time = Director.time;
                MBT newMBT = TimeToMBT((float)Time);

                Measures      = newMBT.Measure;
                Beats         = newMBT.Beat;
                Ticks         = newMBT.Tick;
                _measureCount = newMBT.Measure;
                int totalTicks = (int)(Time / TickLength);
                if (ticksLastFrame != totalTicks)
                {
                    UpdateBeats();
                    BuildBeatMask();
                    ticksLastFrame = totalTicks;
                }
            }
            else
            {
                Time = AudioSettings.dspTime - _startTime;
                if (_thirtySecondCount != _lastThirtySecondCount)
                {
                    BuildBeatMask();
                    _lastThirtySecondCount = _thirtySecondCount;
                }
            }
            TimeMS = Time * 1000;

            timeMSBuffer[_msBufferIndex % timeMSBuffer.Length] = TimeMS;
            //slight adjusting for frame-audio buffer de sync
            if (_msBufferIndex > 1 && TimeMS == timeMSBuffer[(_msBufferIndex - 1) % timeMSBuffer.Length])
            {
                //check one prior frame
                int numDuplicates = 1;
                if (_msBufferIndex > 2 && TimeMS == timeMSBuffer[(_msBufferIndex - 2) % timeMSBuffer.Length])
                {
                    numDuplicates = 2;
                }
                //Debug.Log("duplicate time");
                double timeMSAdjusted = TimeMS + (double)(UnityEngine.Time.deltaTime * numDuplicates);
                //Debug.Log("TimeMS: " + TimeMS);
            }
            else
            {
                //Debug.Log("not duplicate time");
            }
            _msBufferIndex += 1;

            if (TimeMS > 0 && !init)
            {
                init    = true;
                Running = true;
            }
        }
コード例 #2
0
ファイル: Clock.cs プロジェクト: 8ude/FrogRhythms
        public MBT TickToMBT(int tick)
        {
            MBT newMBT = new MBT(0, 0, 0);

            if (tick == 0)
            {
                return(newMBT);
            }
            newMBT.Measure = 1 + tick / (TicksPerBeat * 4);
            tick           = tick - (newMBT.Measure - 1) * TicksPerBeat * 4;
            newMBT.Beat    = 1 + tick / TicksPerBeat;
            newMBT.Tick    = (tick % TicksPerBeat) / 10;
            return(newMBT);
        }
コード例 #3
0
ファイル: Clock.cs プロジェクト: 8ude/FrogRhythms
        public int CompareTo(object obj)
        {
            MBT objMBT    = (MBT)obj;
            int objTicks  = objMBT.Measure * (4 * 96) + (objMBT.Beat * 96) + objMBT.Tick;
            int thisTicks = this.Measure * (4 * 96) + (this.Beat * 96) + this.Tick;

            if (thisTicks == objTicks)
            {
                return(0);
            }
            else if (thisTicks > objTicks)
            {
                return(-1);
            }
            else
            {
                return(1);
            }
        }
コード例 #4
0
ファイル: Clock.cs プロジェクト: 8ude/ImpromptuVisualizerTest
        void Update()
        {
            if (!_initialized)
            {
                return;
            }
            if (TimeLineControlled)
            {
                //Time = Director.time;
                MBT newMBT = TimeToMBT((float)Time);

                Measures      = newMBT.Measure;
                Beats         = newMBT.Beat;
                Ticks         = newMBT.Tick;
                _measureCount = newMBT.Measure;
                int totalTicks = (int)(Time / TickLength);
                if (ticksLastFrame != totalTicks)
                {
                    UpdateBeats();
                    BuildBeatMask();
                    ticksLastFrame = totalTicks;
                }
            }
            else
            {
                Time = AudioSettings.dspTime - startTime;
                if (_thirtySecondCount != _lastThirtySecondCount)
                {
                    BuildBeatMask();
                    _lastThirtySecondCount = _thirtySecondCount;
                }
            }
            TimeMS = Time * 1000;
            if (TimeMS > 0 && !init)
            {
                init    = true;
                Running = true;
            }
        }
コード例 #5
0
ファイル: Clock.cs プロジェクト: 8ude/FrogRhythms
        /// <summary>
        /// Time of and MBT (Measure-Beat-Tick). Usage: AudioSource.PlayScheduled(AtMBT(mbt))
        /// </summary>
        /// <param name="mbt"></param>
        /// <returns></returns>
        public double AtMBT(MBT mbt)
        {
            double value = mbt.GetTickValue() * (Clock.Instance.SamplesPerTick / AudioSettings.outputSampleRate) + _startTime;

            return(value);
        }