Sign in to follow this  
Chett2001

Multi-threading? [Solved]

Recommended Posts

Hey, im wondering how tricky it is to do multithreading? Basically the problem im having it i have developed a 3d application with a user interface and im doing the following using microsoft text to speech:
if(playAudio==true)
		{
				
				if(bPageOnePlayed==true)
				{
				int lTts;
			    lTts =iTts;
				lTts++;
				ISpVoice * pVoice = NULL;
				char* ansistr = "error, no text found";
				ansistr = myPage.pageArray[lTts];
				int a = lstrlenA(ansistr);
				BSTR unicodestr = SysAllocStringLen(NULL, a);
				
				::MultiByteToWideChar(CP_ACP, 0, ansistr, a, unicodestr, a);
				::SysFreeString(unicodestr);
				CoInitialize(NULL);
				HRESULT hr = CoCreateInstance(CLSID_SpVoice, NULL, CLSCTX_ALL, IID_ISpVoice, (void **)&pVoice);
				
    if( SUCCEEDED( hr ) )
			{
				hr = pVoice->Speak(unicodestr, 0, NULL); 
				pVoice->Release();
				pVoice = NULL;
			}
The problem? when the text to speech is engaged nothing happens, this small function seems to hold the CPU's attention till the text has finished, the same is true of a mock up test i did for playing a wav file:
if( ::GetAsyncKeyState('Q') & 0x8000f )
				{
					if(iSound<1)
					{
		    PlaySound("drac1.wav", NULL, SND_FILENAME);
				iSound++;
					}
				}
			}
So does this sort of thing require multithreading? if so does anyone has some simple examples of how to implement it (im still very much a noobie). The over all goal is to be able to interact with the user interface whilst the sound is playing, efficiency isnt a big issue i simply need to get this prototype working as best it can :D Im using C++ with native directX if it helps. [Edited by - Chett2001 on June 2, 2007 5:17:49 PM]

Share this post


Link to post
Share on other sites
1. Use the Async flag for the Speak command. That means it will not halt the CPU while speaking.

2. Use WaitForSingleObject() to wait for the speaking to finish if you want your thread to wait.

Share this post


Link to post
Share on other sites
Wow thanks i cant believe i missed the tag for 1, anyone got a solution for the wav file issue?

edit:Cool i found a similar tag for playSound, thanks for your help HeadKaze, appreciated.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this