forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

oslib audio not working

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Zettablade



Joined: 05 May 2006
Posts: 71

PostPosted: Fri Jun 23, 2006 12:24 am    Post subject: oslib audio not working Reply with quote

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:
oslPlaySound(music[c], 0);

but it works perfectly when i assign it to a button.
Code:
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.
Back to top
View user's profile Send private message
Zettablade



Joined: 05 May 2006
Posts: 71

PostPosted: Fri Jun 23, 2006 3:24 pm    Post subject: Reply with quote

no one? nothing?
Back to top
View user's profile Send private message
Brunni



Joined: 08 Oct 2005
Posts: 186

PostPosted: Fri Jun 23, 2006 5:48 pm    Post subject: Reply with quote

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
Oldschool library for PSP - PC version released
Back to top
View user's profile Send private message
Zettablade



Joined: 05 May 2006
Posts: 71

PostPosted: Fri Jun 23, 2006 6:12 pm    Post subject: Reply with quote

I sent you the source code.
Back to top
View user's profile Send private message
Brunni



Joined: 08 Oct 2005
Posts: 186

PostPosted: Fri Jun 23, 2006 8:44 pm    Post subject: Reply with quote

What you are doing:
Code:
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
Oldschool library for PSP - PC version released
Back to top
View user's profile Send private message
Zettablade



Joined: 05 May 2006
Posts: 71

PostPosted: Fri Jun 23, 2006 8:49 pm    Post subject: Reply with quote

Brunni wrote:
What you are doing:
Code:
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?
Back to top
View user's profile Send private message
Brunni



Joined: 08 Oct 2005
Posts: 186

PostPosted: Fri Jun 23, 2006 10:09 pm    Post subject: Reply with quote

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
Oldschool library for PSP - PC version released
Back to top
View user's profile Send private message
johnsto



Joined: 18 Jan 2006
Posts: 30

PostPosted: Sat Jun 24, 2006 4:57 am    Post subject: Reply with quote

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:
   //Loop for music
   oslSetSoundLoop(music[0], 1);
      
   //Play music
   oslPlaySound(music[c], 0);

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

      [...]
Back to top
View user's profile Send private message
Zettablade



Joined: 05 May 2006
Posts: 71

PostPosted: Sat Jun 24, 2006 7:27 am    Post subject: Reply with quote

Sweet, I finally got it working! Btw, brunny, when are you going to release the new oslib?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group