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
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.
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.
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).
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?
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 ^^
//Loop for music
oslSetSoundLoop(music[0], 1);
//Play music
oslPlaySound(music[c], 0);
//Main loop
while (!osl_quit)
{
oslStartDrawing();
[...]