Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- float freq = DetectPitch();
- if (freq > 0)
- {
- float targetFreq = stringFreqs[selectedStringIndex];
- float midiFloat = FrequencyToMidi(freq);
- int octave;
- string note = MidiToNoteName(midiFloat, out octave);
- float cents = 1200f * Mathf.Log(freq / targetFreq, 2f);
- if (freqText) freqText.SetText("{0:F1} Hz", freq);
- if (noteText) noteText.text = $"{note}{octave}";
- if (centsText) centsText.SetText("{0:+0.0;-0.0}¢", cents);
- if (instructionText)
- {
- float absCents = Mathf.Abs(cents);
- if (absCents <= tuningToleranceCents)
- instructionText.text = "В строю";
- else if (cents > 0)
- instructionText.text = "Сделай ниже";
- else
- instructionText.text = "Сделай выше";
- }
- if (tuningNeedle)
- {
- float angle = Mathf.Clamp(cents, -50f, 50f) / 50f * 45f;
- tuningNeedle.rectTransform.localRotation = Quaternion.Euler(0, 0, -angle);
- if (Mathf.Abs(cents) <= tuningToleranceCents)
- tuningNeedle.color = Color.green;
- else if (cents > 0)
- tuningNeedle.color = new Color(1f, 0.7f, 0.2f);
- else
- tuningNeedle.color = new Color(0.3f, 0.7f, 1f);
- }
- }
- else
- {
- if (freqText) freqText.SetText("-- Hz");
- if (noteText) noteText.SetText("-");
- if (centsText) centsText.SetText("");
- if (instructionText)
- instructionText.text = "Ждём звук...";
- if (tuningNeedle)
- {
- tuningNeedle.rectTransform.localRotation = Quaternion.Euler(0, 0, 0);
- tuningNeedle.color = Color.white;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment