Search code examples
c#midinaudio

Cannot play a note with NAudio.Midi


I read this answer and tried playing a single note with NAudio.Midi:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NAudio.Midi;
using System.Threading;

namespace SoundVision10
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            //Thread.Sleep inside GUI is just for example
            using (MidiOut midiOut = new MidiOut(0))
            {
                midiOut.Volume = 65535;
                midiOut.Send(MidiMessage.StartNote(60, 127, 0).RawData);
                MessageBox.Show("Sent");
                Thread.Sleep(1000);
                midiOut.Send(MidiMessage.StopNote(60, 0, 0).RawData);
                Thread.Sleep(1000);
            }
        }
    }
}

It displays "Sent" and nothing else happens.

Sound is turned on.

The name of the first Midi output device is "Microsoft Gs Wavetable Synth"

Did I forget something?


Solution

  • I replaced NAudio.dll 1.7.3.0 with NAudio.dll 1.3.8.0 and it fixed the issue.