Player
[Audio]


Defines

#define oslSetSoundEndCallback(s, fct)   (s->endCallback = (fct))
#define oslSetSoundLoop(s, loop)   oslSetSoundEndCallback(s, (loop)?oslSoundLoopFunc:NULL)

Enumerations

enum  oslInitAudioME_formats { OSL_FMT_AT3 = 1, OSL_FMT_MP3 = 2, OSL_FMT_ALL = 3 }

Functions

void oslPlaySound (OSL_SOUND *s, int voice)
void oslStopSound (OSL_SOUND *s)
void oslPauseSound (OSL_SOUND *s, int pause)
void oslDeleteSound (OSL_SOUND *s)
void oslAudioVSync ()

Detailed Description

Audio player.

Define Documentation

#define oslSetSoundEndCallback ( s,
fct   )     (s->endCallback = (fct))

Sets the function to be called after a sound has finished to play.

The function has the following parameters: OSL_SOUND* (pointer to the sound), int (number of the voice). It must return the following value: 0 to destroy the channel, 1 to continue playback (imagine you play something else or replay the same song).

OSL_SOUND *s;

int myFunction(OSL_SOUND *s, int voice)         {
        //We replay the same sound on the same voice
        oslPlaySound(s, voice);
        //Return 1 because we continue sound playback
        return 1;
}

oslSetSoundEndCallback(sound, myFunction);
oslPlaySound(sound, 0);
[...] 

#define oslSetSoundLoop ( s,
loop   )     oslSetSoundEndCallback(s, (loop)?oslSoundLoopFunc:NULL)

Sets whether sound is looped or not. This is done by defining the same callback as in the example above.


Enumeration Type Documentation

Formats de fichier à initialiser pour oslInitAudioME.

Enumerator:
OSL_FMT_AT3  Atrac3 and Atrac3+.
OSL_FMT_MP3  Mpeg Audio-Layer 3.
OSL_FMT_ALL  All formats.


Function Documentation

void oslPlaySound ( OSL_SOUND s,
int  voice 
)

Plays a sound on the specified channel. The channel is the channel number from 0 to 7. Playing a sound on an active channel stops the currently playing sound. The advantage of having 8 channels is that you can play up to 8 sounds at the same time.

//These must of course be loaded, but I skipped this step as it's not the goal of this sample.
OSL_SOUND *coin, *jump, *stomp, *music;
//Play the music on an own voice reserved for it (0)
oslPlaySound(music, 0);
[...]
//Play the "coin" sound on another channel than the music else it will replace it
oslPlaySound(coin, 1);
[...]
//Play a second time the "coin" sound. Putting it on the same channel will replace the currently playing coin sound.
//This is useful as sometimes you don't want or need two specific sounds to be played together.
//Especially, imagine your character is in a field of coins, and you take 10 coins in a short period.
//Having 10 times the coin sound played in a different channel would be very noisy.
//So it's good to stop the old sound to play the new one.
oslPlaySound(coin, 1);
[...]
//The jump sound have its own channel, the coin sound will be playing together with the jump and the music.
oslPlaySound(jump, 2);
[...]
//The stomp sound will replace the coin sound as it's played on the same channel.
//But the jump sound and the music are left unaffected.
oslPlaySound(stomp, 1);

void oslStopSound ( OSL_SOUND s  ) 

Stops a sound currently playing.

void oslPauseSound ( OSL_SOUND s,
int  pause 
)

Pauses a sound.

Parameters:
s Sound to pause or resume.
pause 
  • 1: Pause the sound
  • 0: Resume the sound (where it was paused)
  • -1: Toggle pause / play

void oslDeleteSound ( OSL_SOUND s  ) 

Deletes a sound, freeing associated memory. If the sound is currently being played, it will be stopped.

void oslAudioVSync (  ) 

Call this in your loop if a file is streamed and the PSP can go in stand-by mode. If you forget to call this often enough, the sound will not resume after a return from stand-by.

Important: This function is called by oslEndFrame, so you don't need to do it twice if you've added a oslEndFrame call to your code. Consider using oslEndFrame instead of oslAudioVSync for your new projects, as it's cleaner.


Generated on Wed Feb 24 10:25:35 2010 by  doxygen 1.5.9