 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Zettablade
Joined: 05 May 2006 Posts: 71
|
Posted: Fri Jun 23, 2006 12:24 am Post subject: oslib audio not working |
|
|
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 |
|
 |
Zettablade
Joined: 05 May 2006 Posts: 71
|
Posted: Fri Jun 23, 2006 3:24 pm Post subject: |
|
|
| no one? nothing? |
|
| Back to top |
|
 |
Brunni
Joined: 08 Oct 2005 Posts: 186
|
Posted: Fri Jun 23, 2006 5:48 pm Post subject: |
|
|
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 |
|
 |
Zettablade
Joined: 05 May 2006 Posts: 71
|
Posted: Fri Jun 23, 2006 6:12 pm Post subject: |
|
|
| I sent you the source code. |
|
| Back to top |
|
 |
Brunni
Joined: 08 Oct 2005 Posts: 186
|
Posted: Fri Jun 23, 2006 8:44 pm Post subject: |
|
|
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 |
|
 |
Zettablade
Joined: 05 May 2006 Posts: 71
|
Posted: Fri Jun 23, 2006 8:49 pm Post subject: |
|
|
| 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 |
|
 |
Brunni
Joined: 08 Oct 2005 Posts: 186
|
Posted: Fri Jun 23, 2006 10:09 pm Post subject: |
|
|
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 |
|
 |
johnsto
Joined: 18 Jan 2006 Posts: 30
|
Posted: Sat Jun 24, 2006 4:57 am Post subject: |
|
|
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 |
|
 |
Zettablade
Joined: 05 May 2006 Posts: 71
|
Posted: Sat Jun 24, 2006 7:27 am Post subject: |
|
|
| Sweet, I finally got it working! Btw, brunny, when are you going to release the new oslib? |
|
| Back to top |
|
 |
|
|
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
|