Loading
[Audio]


Functions

OSL_SOUNDoslLoadSoundFile (const char *filename, int stream)
OSL_SOUNDoslLoadSoundFileWAV (const char *filename, int stream)
OSL_SOUNDoslLoadSoundFileBGM (const char *filename, int stream)
OSL_SOUNDoslLoadSoundFileMOD (const char *filename, int stream)
OSL_SOUNDoslLoadSoundFileMP3 (const char *filename, int stream)
OSL_SOUNDoslLoadSoundFileAT3 (const char *filename, int stream)
void oslSetModSampleRate (int freq, int stereo, int shift)

Detailed Description

Loading sounds.

Function Documentation

OSL_SOUND* oslLoadSoundFile ( const char *  filename,
int  stream 
)

Loads a sound type and determines its format with its extension.

Parameters:
filename Name of the file to be loaded. If the song must be streamed, always use files that are stored on the Memory Stick, alternate file sources have not been tested and may not always work properly.
stream Either OSL_FMT_STREAM (sound is streamed) or OSL_FMT_NONE (sound is entierly loaded in memory). Streamed sounds use less memory but require more CPU power.
This remark applies for every format: the biggest the sample rate, the more CPU time it will need to be played back.

OSL_SOUND* oslLoadSoundFileWAV ( const char *  filename,
int  stream 
)

Loads a WAV sound file. See oslLoadSoundFile for more information.

OSL_SOUND* oslLoadSoundFileBGM ( const char *  filename,
int  stream 
)

Loads a BGM sound file. See oslLoadSoundFile for more information. BGM is an audio format specific to OSLib. It stores "true" sound, taking less room than WAV, but is only mono.

You can find an encoder in the distribution.

Some other formats are available in the OSTools extension library, take a look to it.

OSL_SOUND* oslLoadSoundFileMOD ( const char *  filename,
int  stream 
)

Loads a MOD sound file. Requires to link with the mod library (-lmikmod in the library list). Currently supports the following formats: .mod, .it, .s3m and .xm.

You can only play one MOD song at a time! I didn't try to do it on 2 voices but I imagine it would play at a double speed and louder. Do NOT think this is normal and most important do not use it in your game! This behavior is very likely to change in a future version of OSLib.

Note: Streaming is not supported for MOD playback. Files will always be loaded from RAM, so don't give OSL_FMT_STREAM as an argument for stream, else you may experience problems in a future OSLib version! Set it to OSL_FMT_NONE for the moment.

Warning: Note that MOD playback is excessively heavy as much in terms of required memory (increases the size of your EBOOT) as speed (watch out the CPU usage when or without MOD playback: with some songs it may increase up to 50%!). To reduce this problem, you can define the sample rate (oslSetModSampleRate) which can help a bit. But it's still not recommended if you need a lot of CPU power for your game. However if your game does not require a high CPU load but only a high GPU (graphic) load, this is not a problem, as sound decoding will mostly be done during periods where the CPU is waiting on the GPU to finish its drawing, and thus not affecting performance very much.

OSL_SOUND* oslLoadSoundFileMP3 ( const char *  filename,
int  stream 
)

Loads an MP3 file. It is necessary to call oslInitAudioME in kernel mode before, else your program will crash!

OSL_SOUND* oslLoadSoundFileAT3 ( const char *  filename,
int  stream 
)

Loads an AT3 file. It is necessary to call oslInitAudioME in kernel mode before, else your program will crash!

void oslSetModSampleRate ( int  freq,
int  stereo,
int  shift 
)

Sets the sample rate for the MOD player (it does not affect other formats!). Decreasing it reduces the audio quality but can reduce the CPU load required to decode MOD audio.

Parameters:
freq Sample rate (in samples per second). The higher it is, the more CPU load is needed. Allowed values are 44100 (good quality), 22050 (medium quality), 11025 (low quality). The default is 44100, but if you need to use less CPU power, 22050 is a good choice. 11025 uses less CPU but it's not worth the big loss of quality IMHO, but it depends from the track in question.
stereo The only allowed value is 1 currently. Do NOT put any other value!
shift The shift sets the ratio for playback. Values are a power of two. 0 means 1x, 1 means 2x, 2 means 4x, etc. This parameter is necessary if you use another frequency than 44100, because the audio stream will always be played at 44100, due to the internal PSP audio capabilities. If you play a 22050 stream at 44100 Hz it will play twice as fast! To reduce this problem, set a shift of 1 (meaning 2x). This parameter is here so that you can make an accelerated music effect. For example if you set shift to 0 (44100 Hz) and freq to 22050, the sound will play twice as fast. Note that in this case (and only in this case!) the freq parameter can have another value than 11025, 22050 or 44100.
Note: it is unrecommended to set any other sample rate than 44100 (with a shift of 0), 22050 (with a shift of 1), 11025 (with a shift of 2) as it's tricky and not heavily tested. Also, it is currently not sure that this behavior will be kept in the future.
//The 3 "normal" possibilities, you can copy them as is if you need them.
oslSetModSampleRate(11025, 1, 2);                       //Very low CPU, bad sound
oslSetModSampleRate(22050, 1, 1);                       //Low CPU, medium sound
oslSetModSampleRate(44100, 1, 0);                       //Normal CPU usage, good sound

//Extended possibilities, not recommended as said above.
oslSetModSampleRate(22050, 1, 0);                       //Twice the normal speed
oslSetModSampleRate(33075, 1, 0);                       //3/2 speed
oslSetModSampleRate(11025, 1, 1);                       //2x speed, lower quality


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