Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Use Wpf.
I parse a midi file and use midioutshortmsg to send message in a For Loop,
and sleep for delay Delta Time;
My playback is lagging ,But, when i open other midi software at the same time
(include WindowMediaPlayer) ,All the Problem is sloved,My Program work fine.
When I close the other opened software.Problem is come back.

My program stuck in here.
I have already try send in midistreamout,MidiOutProc,or midioutlongmsg,etc.but my problem still can't solve.

What I have tried:

Some Code Here:

[DllImport("winmm.dll")]
private extern static int midiOutOpen(out int lphMidiOut, int uDeviceID, int dwCallback, int dwInstance, int dwFlags);
[DllImport("winmm.dll")]
public extern static int midiOutShortMsg(int lphMidiOut, int dwMsg);

public int midiOut;

private void Play_Click(object sender, RoutedEventArgs e)
{
midiOutOpen(out midiOut, 0, 0, 0, 0);

InstanceCaller = new Thread(new ThreadStart(SendMessage));
InstanceCaller.Start();
}

private void SendMessage()
{
for (int i = 0; i < melodyList.Count; i++)
{
var messgae = Convert.ToInt32(melodyList[i], 16);
midiOutShortMsg(midiOut, messgae);
Thread.Sleep(Convert.ToInt32(durationList[i]));
}
}
Posted
Updated 25-Apr-20 11:39am
v3

1 solution

"Playback" requires a balance between the "engine" and the player. Most likely you need to buffer better and your "sleep" isn't helping. The fact it works "better" under contention says you need to think more about "why" you have a "for and sleep" loop at all. Read the docs about "playback".
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900