setpaused doesn't work updating from ex to studio

Hi,

After I updated from Fmod ex to Fmod studio I can’t make the setpaused funtion work. I am working in C with Visual Express 2010. I have made the following program to illustrate:

switch(msg)  
{
	case WM_CREATE:
	
		result = FMOD_System_Create(&systemx);	
		FMOD_System_Init(systemx, 512, FMOD_INIT_NORMAL, NULL);
		result = FMOD_System_CreateSound(systemx, "harmonium0.wav", FMOD_CREATESAMPLE | FMOD_LOOP_NORMAL | FMOD_2D, 0, &sound[0]);
		
		Control[0] = CreateWindow(TEXT("button"), TEXT("Play"),    
         	      WS_VISIBLE | WS_CHILD,
		      200, 200, 50, 50,        
		      hwnd, (HMENU) 1, NULL, NULL);  

 		Control[1] = CreateWindow(TEXT("button"), TEXT("Stop"),    
		     WS_VISIBLE | WS_CHILD,
    		     250, 200, 50, 50,        
		     hwnd, (HMENU) 2, NULL, NULL);  
	
	case WM_COMMAND:
	  				 
		  if (LOWORD(wParam) == 1) {
			 			
				  result = FMOD_System_PlaySound(systemx, sound[0], NULL, 1, &channel[0]);

				  result = FMOD_Channel_SetPaused(channel[0], 0);

				  FMOD_Channel_GetPaused(channel[0], paused);
		  }
				 
 		  if (LOWORD(wParam) == 2) {

          		        result = FMOD_Channel_SetPaused(channel[0], 1);
			
			        result = FMOD_Channel_GetPaused(channel[0], paused);
		   
         			 return 0;
  		}
 
		return 0;		  
			  
	case WM_DESTROY:
	
	       PostQuitMessage(0);
               FMOD_System_Release(systemx);
	}

	return DefWindowProc(hwnd, msg, wParam, lParam);
}	  

When clicking the first button, there is no sound. The return values are OK and the paused variable is 0. If I remove the first instance of setpaused and start playing directly from the playsound function, there is sound, but when clicking the second button the sound doesn’t stop. Also then the return values are ok and the paused value is 0.

Hope someone can help me with this.

Thanks in advance.

Sincerely

Keitel

This is probably due to the setPaused(false) being deferred to our async command queue. Are you calling System::update regularly? Calling update is needed to process the command queue among other things.

1 Like

or you can use FMOD_INIT_THREAD_UNSAFE to remove the queue

Thank you very much. That solved the problems. I placed an update function after each setpaused funtion and then it worked. I am, however, uncertain where it’s most appropriate to place the update function, in case it for instance should slow the program down. I don’t know the diference in functionality between the update command and the other you mentioned neither. But as long as it works, it’s maybe not much to bother about.

-Keitel

Usually you would call System::update as part of your game loop, once per frame. Depending on your application structure you might do this in different ways, as long as you call it regularly though you should be fine.

If you use the init flag Brett mentioned it will cause certain operations to happen synchronously without the need for System::update, but in general you should still call update regularly regardless.

1 Like

If you’re only using the windows message loop, try using a timer.

Call

SetTimer(hwnd, IDT_TIMER1, 50, (TIMERPROC) NULL);

and then add

case WM_TIMER: FMOD_System_Update(&systemx)

to your switch statement.

See more about windows timers: http://msdn.microsoft.com/en-us/library/windows/desktop/ms644901(v=vs.85).aspx

2 Likes