Esempio n. 1
0
        public void KOSUpdate(double deltaTime)
        {
            if (!IsPlaying)
            {
                return;
            }

            // Be sure we use the same game clock here as in Voice.cs's Update():  (i.e. unscaledTime vs Time vs fixedTime):
            float now = Time.unscaledTime;

            if (Time.timeScale == 0f)          // game is frozen (i.e. the Escape Menu is up.)
            {
                if (freezeBeganTimestamp < 0f) // And we weren't frozen before so it's the start of a new freeze instance.
                {
                    freezeBeganTimestamp = now;
                }
                return; // do none of the rest of this work until the pause is over.
            }
            else // game is not frozen.
            {
                if (freezeBeganTimestamp >= 0f) // And we were frozen before so we just became unfrozen now
                {
                    // Push the timestamp ahead by the duration of the pause so it will continue what's left of the note
                    // instead of truncating it early:
                    float freezeDuration = now - freezeBeganTimestamp;
                    noteStartTimeStamp  += freezeDuration;
                    noteEndTimeStamp    += freezeDuration;
                    freezeBeganTimestamp = -1f;
                }
            }

            // If still playing prev note, return, doing nothing except maybe changing
            // the current note's frequency if it's a slidenote:
            if (now < noteEndTimeStamp)
            {
                NoteValue note = song[noteNum] as NoteValue;
                if (noteFreqTotalChange != 0.0)
                {
                    float durationPortion = (now - noteStartTimeStamp) / (noteEndTimeStamp - noteStartTimeStamp);
                    float newFreq         = note.Frequency + durationPortion * noteFreqTotalChange;
                    voice.ChangeFrequency(newFreq);
                }
                return;
            }

            AdvanceNote(now);
        }
Esempio n. 2
0
        public void KOSUpdate(double deltaTime)
        {
            if (!IsPlaying)
            {
                return;
            }

            // Be sure we use the same game clock here as in Voice.cs's Update():  (i.e. unscaledTime vs Time vs fixedTime):
            float now = Time.unscaledTime;

            if (Time.timeScale == 0f)          // game is frozen (i.e. the Escape Menu is up.)
            {
                if (freezeBeganTimestamp < 0f) // And we weren't frozen before so it's the start of a new freeze instance.
                {
                    freezeBeganTimestamp = now;
                }
                return; // do none of the rest of this work until the pause is over.
            }
            else // game is not frozen.
            {
                if (freezeBeganTimestamp >= 0f) // And we were frozen before so we just became unfrozen now
                {
                    // Push the timestamp ahead by the duration of the pause so it will continue what's left of the note
                    // instead of truncating it early:
                    float freezeDuration = now - freezeBeganTimestamp;
                    noteStartTimeStamp  += freezeDuration;
                    noteEndTimeStamp    += freezeDuration;
                    freezeBeganTimestamp = -1f;
                }
            }

            // If still playing prev note, do nothing except maybe change
            // its frequency if it's a slidenote:
            if (now < noteEndTimeStamp)
            {
                NoteValue note = song[noteNum] as NoteValue;
                if (noteFreqTotalChange != 0.0)
                {
                    float durationPortion = (now - noteStartTimeStamp) / (noteEndTimeStamp - noteStartTimeStamp);
                    float newFreq         = note.Frequency + durationPortion * noteFreqTotalChange;
                    voice.ChangeFrequency(newFreq);
                }
                return;
            }

            // Increment to next note and start playing it:
            ++noteNum;
            if (noteNum >= song.Count())
            {
                if (loop)
                {
                    noteNum          = -1;
                    noteEndTimeStamp = -1f;
                }
                else
                {
                    IsPlaying = false;
                }
            }
            else
            {
                curNote = song[noteNum] as NoteValue;
                if (curNote != null)
                {
                    noteStartTimeStamp  = now;
                    noteEndTimeStamp    = now + tempo * curNote.Duration;
                    noteFreqTotalChange = curNote.EndFrequency - curNote.Frequency;
                    voice.BeginProceduralSound(curNote.Frequency, tempo * curNote.KeyDownLength, curNote.Volume);
                }
            }
        }