Esempio n. 1
0
 private void tbSoundAmplitude_Scroll(object sender, EventArgs e)
 {
     if (_audioDecoder != null)
     {
         _audioDecoder.DetectLevelThreshold = AudioUtils.DecibelToPower(tbSoundAmplitude.Value);
     }
     lblCurAmpl.Text = tbSoundAmplitude.Value + " db";
 }
Esempio n. 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";
        }