PSP homebrew applications.
First, In order to use this tutorial, you need to download
the unofficial PSP graphics library name OSlib which
can be found here:
http://www.qj.net/qjnet/psp/psp-homebre ... -v111.html
(If you have windows and don't have Cygwin,
there's a way for you guys to install it as well. Just PM and I'll
take you through the steps
Firstly your code should look like this:
Code: Select all
//The main library OSLib
#include <oslib/oslib.h>
you need to include this line. Those are your
basic header files, which allow you to use
oslib's functions.
NOTE: Those who try to include "oslib/audio.h"
will just get an error when compiling (functions aren't
fully linked).
Next add the lines:
Code: Select all
PSP_MODULE_INFO("SFX_tutorial", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
the files in usermode. Those lines are necessary to
create an EBOOT.PBP file.
Follow that code with:
Code: Select all
//definition of the pointers towards our sounds
OSL_SOUND *click;
music and click in our program.
You can change those if you'd like but you
would have to change them in the preceding lines as well.
So now, we are entering our main thread:
Code: Select all
int main()
{
//Initialization of the library
oslInit(0);
//Initialization of the graphic mode
oslInitGfx(OSL_PF_8888, 1);
//Initialization of the text console
oslInitConsole();
//Initialize audio
oslInitAudio();
and the audio mode used in oslib.
Now for our variables:
Code: Select all
click = oslLoadSoundFile("file.wav", OSL_FMT_NONE);
variable, we must first configure the path to the wav file.
Just change the filename to the one that you are using.
Now we enter our main loop:
Code: Select all
while (!osl_quit)
{
//Allow to draw
oslStartDrawing();
//Read the keys
oslReadKeys();
//Sounds commands
if (osl_keys->pressed.cross) oslPlaySound(click, 1);
// It loads the sound file defined in the click variable when the
// X button is pressed
/* The "click" line in oslPlaySound calls the variable, in your case
the sound effect defined in the "click" variable.
The next pointer "1" means that it is streamed through the audio
channel 1. The psp has 8 audio channels that we can use
(0, 1, 2, 3, 4, 5, 6, 7). Each sound effect should use it's own channel.
*/
//Display the instructions
oslPrintf_xy(0,30,"Press Cross to play the sound effect.");
//End of the draw
oslEndDrawing();
//Synchronize the screen
oslSyncFrame();
//For the sleep
oslAudioVSync();
}
code isn't finished yet.
Our last lines are:
Code: Select all
//Leave the program
oslEndGfx();
oslQuit();
return 0;
}
If the command was successful,
the program would return a Zero.
The full code should look like:
Code: Select all
//The main library OSLib
#include <oslib/oslib.h>
PSP_MODULE_INFO("OSLib Sample", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
//definition of the pointers towards our sounds
OSL_SOUND *click;
int main()
{
//Initialization of the library
oslInit(0);
//Initialization of the graphic mode
oslInitGfx(OSL_PF_8888, 1);
//Initialization of the text console
oslInitConsole();
//Initialize audio
oslInitAudio();
//loading the sounds
click = oslLoadSoundFile("file.wav", OSL_FMT_NONE);
//main loop
while (!osl_quit)
{
//Allow to draw
oslStartDrawing();
//Read the keys
oslReadKeys();
//Sounds commands
if (osl_keys->pressed.cross)
{
oslPlaySound(click, 1);
}
// It loads the sound file defined in the click variable when the
// X button is pressed
/* The "click" line in oslPlaySound calls the variable, in your case
the sound effect defined in the "click" variable.
The next pointer "1" means that it is streamed through the audio
channel 1. The psp has 8 audio channels that we can use
(0, 1, 2, 3, 4, 5, 6, 7). Each sound effect should use it's own channel.
*/
//Display the instructions
oslPrintf_xy(0,30,"Press Cross to play the sound effect.");
//End of the draw
oslEndDrawing();
//Synchronize the screen
oslSyncFrame();
//For the sleep
oslAudioVSync();
}
//Leave the program
oslEndGfx();
oslQuit();
return 0;
}
In order to compile the whole code so that the psp can
read it and execute it, we must create a makefile.
Your makefile should look like this:
Code: Select all
TARGET = SFX_lesson
OBJS = main.o
INCDIR =
CFLAGS = -G4 -Wall -O2
CXXFLAGS = $(CFLAGS) -fno-exceptions -fno-rtti
ASFLAGS = $(CFLAGS)
LIBDIR =
LDFLAGS =
STDLIBS= -losl -lpng -lz \
-lpspsdk -lpspctrl -lpspumd -lpsprtc -lpsppower -lpspgu -lpspaudiolib -lpspaudio -lm
LIBS=$(STDLIBS)$(YOURLIBS)
EXTRA_TARGETS = EBOOT.PBP
PSP_EBOOT_TITLE = SFX_test
PSPSDK=$(shell psp-config --pspsdk-path)
include $(PSPSDK)/lib/build.makBe sure to place the sound effect file with the eboot.
You can find sound effects here:
http://www.soundjay.com/button-sounds-1.html
(be sure to download the .wav file, not the .mp3
Once downloaded, if you didn't modify the code I posted
then rename the wav file to file.wav.
If you used your own name (in the variable) change it to that.
If you have any problems with this tutorial on how to use
sound effects in your PSP homebrew (It's useful for menu's)
Feel free to discuss it here.
If you find any bugs in the code that I have posted,
feel free to correct me.
Hope it all helped,
NightStar3
Advertising
