PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Multi-threaded GDIDemo with FMOD

I'm working on an app that will require very tight timing requirements for processing audio (using the FMOD library). In this, I need to check audio status (via FFT) every ~20 ms.

From what I've seen I'd like to use GAPIDraw to do the graphics. In tinkering with the GDIDemo, I've been able to add my audio routines which seem to function ok EXCEPT they are been called unpredictably. I am assuming that's because I really need two threads - one for the GAPIDraw graphics, and one to process audio.

I'm looking for advice (or a very clear example with code) of what I should do to make a multi-threaded version of the GDIDemo app.

Anyone want to point me in the right direction?
I've done something with threads a while back.

It goes something like this:
Code:


DWORD WINAPI AProcess( void *thisptr)
{
while(runthread)
{
DoSomething();

ttsleep = 40 - TC.DeltaTick;
if(ttsleep < 1) ttsleep = 1;
Sleep(ttsleep);
}
return 1;
}



StartProcess()
{
m_hThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) AProcess, (void*)this, CREATE_SUSPENDED, &dwThreadID);

if(m_hThread == NULL)
threadstat = -2;
else
{
SetThreadPriority( m_hThread, THREAD_PRIORITY_NORMAL );

threadstat = ResumeThread(m_hThread);
}

}



The jitter may be a problem though. You may need to do some tricks with the sleep so that you enter too soon and stall till the exact time to do the processing.