I don’t know if this issue is directly related to Fmod, but as I have not gotten any useful answer on a MSDN forum for almost the same question, I try to post it here. If someone at least could give me a hint or an idea what to look for, it could be very helpful.
I have made a Windows desktop program in C with Fmod and also Dirac. As a part of the program I have included a midi controller, which I use by connecting a midi keyboard. I use my own sound files that are played by Fmod commands.
When I turn on the midi function, it works fine for a few minutes, but then stops sounding, and without any error messages.
The code of the midi controller is in a callback function that is called from the main thread by a button that is supposed to turn the midi functionality on and off, and which has the following code:
if (LOWORD(wParam) == 10) {
cursorused = LoadCursor(NULL, IDC_WAIT);
SetCursor(cursorused);
FMOD_System_Update(systemx);
if(tampuraflag == 0){
SetWindowText(Control[10], TEXT("Off"));
tampurafrequency = kfreq/44100;
timestretch(1, tampuratime, tampurafrequency, infileName2);
tampuraflag = 1;
FMOD_Channel_SetVolume(channel[1], tampuravolume);
nMidiDeviceNum = midiInGetNumDevs();
rv = midiInOpen(&hMidiDevice, nMidiPort, (DWORD)(void*)MidiInProc, 0, CALLBACK_FUNCTION);
midiInStart(hMidiDevice);
} else if(tampuraflag == 1){
tampuraflag = 0;
SetWindowText(Control[10], TEXT("On"));
FMOD_Channel_SetPaused(channel[1], 1);
FMOD_Channel_SetPaused(channel[0], 1);
FMOD_System_Update(systemx);
rv = midiInStop(hMidiDevice);
rv = midiInClose(hMidiDevice);
hMidiDevice = NULL;
}
if (Focus) { Focus = 0; SetFocus(hwnd); }
return 0;
}
When the button is pressed a sound file of about 15 seconds in length starts and goes in a loop. This is then running in the background when using the midi keyboard. I have also found that I can’t turn off the midi functionality by clicking the button once more. The “rv” variable for midiInStop(hMidiDevice) and midiInClose(hMidiDevice) gives MMSYSERR_INVALHANDLE. After playing for a few minutes, the sound of the background file stops first, and then a few seconds later,the sound of the midi keyboard.
It would be grateful if somebody could give me an idea what could be wrong.
Thanks in advance.
Sincerely