oslib audio not working

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Zettablade
Posts: 71
Joined: Fri May 05, 2006 5:59 pm

oslib audio not working

Post by Zettablade »

Ok, I posted this in the oslib thread, but i get the feeling that no one pays much attention there.
I have this problem with my sound. it doesn't work when i use

Code: Select all

oslPlaySound(music[c], 0);
but it works perfectly when i assign it to a button.

Code: Select all

if (osl_keys->pressed.cross) oslPlaySound(music[c], 0);
Well, that will never do. I need the sound to play right with out having to press a silly button.
If you think you'de need to see my source, I can pm it to you.
Zettablade
Posts: 71
Joined: Fri May 05, 2006 5:59 pm

Post by Zettablade »

no one? nothing?
Brunni
Posts: 186
Joined: Sat Oct 08, 2005 10:27 pm

Post by Brunni »

It should work, I already tested it, so except if something broken in the latest release (which is unlikely because I didn't touch that) it's your fault. Please post more code (at least when you load and play this sound), I can't help you with so few information.
Sorry for my bad english
Image Oldschool library for PSP - PC version released
Zettablade
Posts: 71
Joined: Fri May 05, 2006 5:59 pm

Post by Zettablade »

I sent you the source code.
Brunni
Posts: 186
Joined: Sat Oct 08, 2005 10:27 pm

Post by Brunni »

What you are doing:

Code: Select all

int main(int argc, char* argv[]) 
{ 
   //Initialization 
   oslInit(0);               //The lib 
   oslInitGfx(OSL_PF_8888, 1); //Gfx 
   oslInitConsole();         //Text 
   oslInitAudio();            //Audio 

   //Load the images, sound, and tilesets 
   ImageLoad(); 
   SoundLoad(); 

   //Loop for music 
   oslSetSoundLoop(music[0], 1); 

   //Main loop 
   while (!osl_quit) 
   { 
      oslStartDrawing(); 
      [...]
       
      //Play music 
      oslPlaySound(music[c], 0); 

      [...]
      //End the drawing, put the frames in sync, and sync the audio 
      oslEndDrawing(); 
      oslSyncFrame(); 
      oslAudioVSync(); 
    } 
    
   oslEndGfx(); 
   oslQuit(); 
   return 0; 
}
That obviously won't work because you play the sound in the loop, so it will be (re)played once per frame, that is 60 times per second. What you need to do is to play it once when something happen (for example take a coin), OSLib will do the rest itself (play it to the end). So in this example you should place it near the oslSetSoundLoop (this specifies that it will be looped when finished, ideal for a music).
Sorry for my bad english
Image Oldschool library for PSP - PC version released
Zettablade
Posts: 71
Joined: Fri May 05, 2006 5:59 pm

Post by Zettablade »

Brunni wrote:What you are doing:

Code: Select all

int main(int argc, char* argv[]) 
{ 
   //Initialization 
   oslInit(0);               //The lib 
   oslInitGfx(OSL_PF_8888, 1); //Gfx 
   oslInitConsole();         //Text 
   oslInitAudio();            //Audio 

   //Load the images, sound, and tilesets 
   ImageLoad(); 
   SoundLoad(); 

   //Loop for music 
   oslSetSoundLoop(music[0], 1); 

   //Main loop 
   while (!osl_quit) 
   { 
      oslStartDrawing(); 
      [...]
       
      //Play music 
      oslPlaySound(music[c], 0); 

      [...]
      //End the drawing, put the frames in sync, and sync the audio 
      oslEndDrawing(); 
      oslSyncFrame(); 
      oslAudioVSync(); 
    } 
    
   oslEndGfx(); 
   oslQuit(); 
   return 0; 
}
That obviously won't work because you play the sound in the loop, so it will be (re)played once per frame, that is 60 times per second. What you need to do is to play it once when something happen (for example take a coin), OSLib will do the rest itself (play it to the end). So in this example you should place it near the oslSetSoundLoop (this specifies that it will be looped when finished, ideal for a music).
So, do I need to put the oslSetSoundLoop after the oslPlaySound? I don't get it? Also, do I put it into an if loop?
Brunni
Posts: 186
Joined: Sat Oct 08, 2005 10:27 pm

Post by Brunni »

oslPlaySound plays a sound, like when you double-click on a .mp3 file. It will then be played without any action from you until the end, or if you enabled the loop, until you call oslStopSound (or oslPauseSound).
You wouldn't click 60 times per second on a file you want to listen to, isn't it? That's the same here ^^
Sorry for my bad english
Image Oldschool library for PSP - PC version released
johnsto
Posts: 30
Joined: Wed Jan 18, 2006 8:52 am

Post by johnsto »

Basically, move the oslPlaySound in front of the loop so it's only called once before the loop, rather than every single time the loop is called.

i.e., try something like this:

Code: Select all

	//Loop for music
	oslSetSoundLoop(music[0], 1);
		
	//Play music
	oslPlaySound(music[c], 0);

	//Main loop
	while (!osl_quit)
	{
		oslStartDrawing();

		[...] 
Zettablade
Posts: 71
Joined: Fri May 05, 2006 5:59 pm

Post by Zettablade »

Sweet, I finally got it working! Btw, brunny, when are you going to release the new oslib?
Post Reply