コード例 #1
0
        private void btnRecord_Click(object sender, EventArgs e)
        {
            var waveIn = new WaveIn();

            waveIn.WaveFormat        = new WaveFormat();
            waveIn.DataAvailable    += OnDataAvailable;
            waveIn.RecordingStopped += OnRecordingStopped;

            Decoder = new WaveMp3FileDecoder();
            Decoder.DetectLevelThreshold = 0;
            Decoder.InitRealtimeMode(waveIn.WaveFormat.Channels, waveIn.WaveFormat.BitsPerSample, waveIn.WaveFormat.SampleRate, 200,
                                     (PitchTracker tracker, PitchRecord record) =>
            {
                tbFrequency.Text = record.Pitch.ToString();
                tbMidiId.Text    = record.MidiNote.ToString();
                tbNote.Text      = MusicalTemperament.MidiNoteToNoteName(record.MidiNote);
                //tbId13.Text = MusicalHmmData.MidiNoteToHmmMidiNote(record.MidiNote).ToString();
            });

            waveIn.StartRecording();
        }
コード例 #2
0
        private void btnMicFollowing_Click(object sender, EventArgs e)
        {
            _musicFollower = new MusicalFollower(_musicHmmModelOnline, (int)nudTempo.Value, _musicXmlDecoder.BeatType, _musicXmlDecoder.Beats);

            _audioDecoder = new WaveMp3FileDecoder();
            _audioDecoder.DetectLevelThreshold = AudioUtils.DecibelToPower(tbSoundAmplitude.Value);

            _waveIn                   = new WaveIn();
            _waveIn.WaveFormat        = new WaveFormat(44100, 1);
            _waveIn.DataAvailable    += OnDataAvailable;
            _waveIn.RecordingStopped += OnRecordingStopped;

            var      stopwatch = new Stopwatch();
            TimeSpan oldTime   = new TimeSpan();

            lblPitchsCount.Text = "0";
            _audioDecoder.InitRealtimeMode(_waveIn.WaveFormat.Channels, _waveIn.WaveFormat.BitsPerSample, _waveIn.WaveFormat.SampleRate,
                                           _musicFollower.GetTimerInterval((int)nudTempo.Value),
                                           (PitchTracker tracker, PitchRecord record) =>
            {
                lblPitchsCount.Text = (int.Parse(lblPitchsCount.Text) + 1).ToString();
                lblTime.Text        = (stopwatch.Elapsed - oldTime).ToString();
                oldTime             = stopwatch.Elapsed;

                tbCurNoteName.Text    = MusicalTemperament.MidiNoteToNoteName(record.MidiNote);
                tbCurMidiNote.Text    = record.MidiNote <= -1 ? "-" : record.MidiNote.ToString();
                tbCurHmmMidiNote.Text = _musicHmmData.MidiNoteToHmmMidiNote(record.MidiNote).ToString();
                FollowObservation(record.MidiNote);
            });
            _waveIn.StartRecording();
            stopwatch.Start();
            oldTime = stopwatch.Elapsed;

            timerMetronome.Interval = _musicFollower.GetMetronomeInterval((int)nudTempo.Value);
            timerMetronome.Start();

            btnMicFollowing.Text = "Stop";
        }