예제 #1
0
 public void NoteFinderTest()
 {
     NoteFactory noteFactory = new NoteFactory();
     NoteFinder noteFinder = new NoteFinder(noteFactory);
     INote note = noteFactory.CreateNote(enote, octave);
     var actual = noteFinder.FindNearestNote(110);
     Assert.AreEqual(actual, note);
 }
예제 #2
0
 void Update()
 {
     while (pendingNotes.Count != 0 && pendingNotes.Peek().beginBeat < BeatTime.beat + noteShowOffsetBeat)
     {
         var note = pendingNotes.Dequeue();
         factory.CreateNote(note);
     }
 }
예제 #3
0
    void Update()
    {
        while (pendingNotes.Count != 0 && pendingNotes.Peek().beginBeat < BeatTime.beat + noteShowOffsetBeat)
        {
            var note = pendingNotes.Dequeue();
            factory.CreateNote(note);
        }
        float trackHeight = LaserParameters.TrackHeight;

        if (trackHeight != lastTrackHeight)
        {
            lastTrackHeight = trackHeight;
            Vector3 position = transform.localPosition;
            position.y = trackHeight / Mathf.Cos(Mathf.Deg2Rad * tiltAngle);
            transform.localPosition = position;
        }
        if (particles != null && particles.isEmitting && BeatTime.audioTime > particleStopTime)
        {
            particles.Stop();
        }
    }
예제 #4
0
    // Update is called once per frame
    void Update()
    {
        float freq = PitchDetectorGetFreq(0), deviation = 0.0f;

        frequency = freq.ToString() + " Hz";

        //when frequency changes average new frequency skipping frames for transition
        if (!freq.Equals(lastFreq))
        {
            freqChanged = true;
        }

        if (freqChanged)
        {
            frameCount++;
        }
        if (frameCount > 2)
        {
            float noteval = 57.0f + 12.0f * Mathf.Log10(freq / 440.0f) / Mathf.Log10(2.0f);
            noteVals.Add(noteval);
            //every x frames calculate note
            if (noteVals.Count > 5)
            {
                noteval = noteVals.Average();
                int   octave = (int)Mathf.Floor((noteval + 0.5f) / 12.0f);
                float f      = Mathf.Floor(noteval + 0.5f);
                deviation = Mathf.Floor((noteval - f) * 100.0f);
                int noteIndex = (int)f % 12;
                note = noteNames [noteIndex] + " " + octave;
                Debug.Log("Detected frequency: " + frequency + "\nDetected note: " + note + " (deviation: " + deviation + " cents)");
                noteFactory.CreateNote(note);
                //reset states to detect next note
                noteVals.Clear();
                freqChanged = false;
                frameCount  = 0;
            }
        }
        lastFreq = freq;
    }