コード例 #1
0
        /// <summary>
        /// The pitch was detected - add the record
        /// </summary>
        /// <param name="pitch"></param>
        private void AddPitchRecord(float pitch)
        {
            var midiNote  = 0;
            var midiCents = 0;

            PitchDsp.PitchToMidiNote(pitch, out midiNote, out midiCents);

            var record = new PitchRecord();

            record.RecordIndex = m_curPitchIndex;
            record.Pitch       = pitch;
            record.MidiNote    = midiNote;
            record.MidiCents   = midiCents;

            m_curPitchRecord = record;

            if (m_recordPitchRecords)
            {
                if (m_pitchRecordHistorySize > 0 && m_pitchRecords.Count >= m_pitchRecordHistorySize)
                {
                    m_pitchRecords.RemoveAt(0);
                }

                m_pitchRecords.Add(record);
            }

            if (this.PitchDetected != null)
            {
                this.PitchDetected(this, record);
            }
        }
コード例 #2
0
        private void CalibrateLowPitch()
        {
            MicrophoneManager.Instance.StartRecording();
            m_GetPitchCoroutine = StartCoroutine(GetPitchAverage((value) =>
            {
                int midiNote, cents;
                bool isMidiNote = PitchDsp.PitchToMidiNote(m_CalibratedLowPitch, out midiNote, out cents);

                if (float.IsNaN(value) || !isMidiNote || value > m_CalibratedHighPitch)
                {
                    WarningManager.Instance.ShowWarning("Please try to hum in a deeper voice.");
                    ResetCalibration(LowPitchDuration);
                    return;
                }
                m_CalibratedLowPitch = value;
                CalibratedLowNote    = midiNote;

                ResetCalibration(LowPitchDuration, LowPitchVisualization);
                CheckForCalibrationTest();
            }, m_LowPitchReference, m_HighPitchReference, LowPitchDuration));
        }