Last active
January 21, 2017 02:16
-
-
Save fengye/0502b863292c66520e4fd0830495a5d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (midiNote > 0) | |
{ | |
int octave = midiNote / 12; | |
int noteNum = midiNote % 12; | |
int normalizedNote; | |
if (octave % 2 == 0) | |
{ | |
normalizedNote = noteNum; | |
} | |
else | |
{ | |
normalizedNote = (12 - 1) - noteNum; | |
} | |
// normalizedNote range == [0, 11] | |
// int normalizedNote = midiNote - 50; | |
// normalizedNote = (int)Mathf.Clamp(normalizedNote, -4, 4); | |
normalizedNote -= 6; | |
// normalizedNote range == [-6, 5] | |
if (turningPolicy == TurningPolicy.DIRECT || | |
turningPolicy == TurningPolicy.DIRECT_SILENCE_TO_NEUTRAL) | |
{ | |
cachedTargetRotation.eulerAngles = new Vector3(0, 0, -normalizedNote * 15.0f); | |
} | |
lastNormalizedNote = normalizedNote; | |
// transform.rotation = rot; | |
// Debug.Log("Detected note: " + midiNote); | |
Debug.Log("Detected freq: " + freq + " - Note: " + midiNote); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment