Beispiel #1
0
        private void timerFollowSequence_Tick(object sender, EventArgs e)
        {
            if (_currentNoteInd >= 0 && _currentNoteInd < _inputSequence.Length)
            {
                FollowObservation(_inputSequence[_currentNoteInd++]);

                double r = _random.NextDouble();
                if (r < (double)nudTempoErrorPercent.Value / 100.0)
                {
                    int    interval = _musicFollower.GetTimerInterval((int)nudTempo.Value);
                    double variance = interval * (double)nudTempoVariationErrorPercent.Value / 100.0 * 2;
                    timerFollowSequence.Interval = (int)Math.Round(interval - variance / 2 + _random.NextDouble() * variance);
                }
                else
                {
                    timerFollowSequence.Interval = _musicFollower.GetTimerInterval((int)nudTempo.Value);
                }
            }
            else
            {
                timerFollowSequence.Stop();
                timerMetronome.Stop();
                btnFollowSequence.Text = "Ended";
            }
        }
Beispiel #2
0
        private void btnFollowSequence_Click(object sender, EventArgs e)
        {
            tbInputSequence.Enabled = false;

            if (!timerFollowSequence.Enabled)
            {
                if (!_musicHmmModelOnline.Started)
                {
                    _musicFollower = new MusicalFollower(_musicHmmModelOnline, (int)nudTempo.Value, _musicXmlDecoder.Beats, _musicXmlDecoder.BeatType);
                    timerFollowSequence.Interval = _musicFollower.GetTimerInterval((int)nudTempo.Value);
                    timerMetronome.Interval      = _musicFollower.GetMetronomeInterval((int)nudTempo.Value);
                    _inputSequence = tbInputSequence.Text.Split(',').Select(s => int.Parse(s)).ToArray();
                }

                timerFollowSequence.Start();
                timerMetronome.Start();
                btnFollowSequence.Text = "Stop";
            }
            else
            {
                timerFollowSequence.Stop();
                timerMetronome.Stop();
                btnFollowSequence.Text = "Follow the Sequence";
            }
        }
Beispiel #3
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";
        }