melanchall / drywetmidi

.NET library to read, write, process MIDI files and to work with MIDI devices
https://melanchall.github.io/drywetmidi
MIT License
540 stars 75 forks source link

Latency #48

Closed Yorgg closed 4 years ago

Yorgg commented 4 years ago

I am having noticeable latency from when a key is pressed on digital piano and when sound is produced. The latency time is constant (around ~100ms if I had to guess).

Output device is MICROSOFT GS WAVETABLE SYNTH. The application is running on Unity.

How can I reduce this latency?

  device = Melanchall.DryWetMidi.Devices.InputDevice.GetByName(deviceName);    
  device.EventReceived += OnEventReceived;
  device.StartEventsListening();

 private void OnEventReceived(object sender, MidiEventReceivedEventArgs e)
    {
        if (e.EventType == Melanchall.DryWetMidi.Smf.MidiEventType.NoteOn)
        {
            var note = e as NoteOnEvent;
            Debug.Log(note.Velocity);
            Debug.Log($"{note.GetNoteName()}{note.GetNoteOctave()}");
        }

        if (App.Settings.Midi.outputDevice != null)
        {
            App.Settings.Midi.outputDevice.SendEvent(e);
        }
    }
}

thanks!

melanchall commented 4 years ago

Hi,

It's known problem of the Microsoft GS Wavetable Synth. This software synth adds ~100 ms latency. If you google this problem, you'll find a lot of threads. Examples:

So it's not about DryWetMIDI.

Yorgg commented 4 years ago

Ah okay. I will try another output device.

Thank you.