Midi-dot-net playing notes simultaneously and to high delay

457 views Asked by At

After resolving the problem with noteOn key event (thank you Justin) i noticed another two problems: too high delay and impossible playing simultaneously.

Firstable i use IF statment:

if (nutka == "A0" && msg.Velocity != 0) {
    clock.Schedule(new NoteOnMessage(outputDevice, Channel.Channel1, Pitch.A0, 80, 2));
}

and this works excelent, no delay, but it also allows me to use only MIDI Pitch not a .wav files.

when i use other possibility to play a note (from files added to Resources):

SoundPlayer noteA0 = new SoundPlayer(Properties.Resources.A0);
noteA0.Play();

looks and works OK but SoundPlayer don't allow me to play notes simultaneously.

Another way i was trying was WMP library:

var noteA0 = new WMPLib.WindowsMediaPlayer();
noteA0.URL = @"c:\sounds\piano\A0.wav";

Ok... it plays simultaneous but kind a funny thing happens, the more notes i play the bigger delay (delay between i press a key and i hear the sound) i have and finally my programm stuck on playing anything (still got noteOn messages)...looks like the memory buffer was suddenly gone or something like that?

The last thing i was trying to check was DirectX library:

Audio noteA1 = new Audio(@"C:\sounds\piano\A1.wav");
noteA1.Play();

Build and compile - with no problems, without any errors, but when i pressed a key on my midi device, application returns message:

An unhandled exception of type 'System.BadImageFormatException' occurred in Midi.dll
Additional information: Could not load file or assembly 'Microsoft.DirectX.AudioVideoPlayback.dll' or one of its dependencies. 
It is not a valid Win32 application. (Exception from HRESULT: 0x800700C1)

My question is - is it possible to add my files (.wav) to Solution Resources and play them simultaneously with delay which will allow me to play like with normal piano? Normal piano i mean with low delay, almost unnoticeable delay.

0

There are 0 answers