PSP Pro GamerZ

For all your PSP Needs
AKA Team Unknown Forum
 
HomeFAQRegisterLog in
---- Welcome to Team Unknown's official Forum, Don't forget to Register on the forum. Be sure to check out all of our projects such as uo DSONPSP and DigiPSP Also Check out our PSP Programming Tutorials Very Happy ----

Share | 
 

 [Tutorial] Using sound effects in homebrew (OSlib)

Go down 
AuthorMessage
NightStar3



Posts : 4
Points : 6
Join date : 2010-10-03

PostSubject: [Tutorial] Using sound effects in homebrew (OSlib)    Sun Oct 03, 2010 2:41 pm

Welcome to my tutorial on using sound effects in your
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:

[You must be registered and logged in to see this link.]


(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 Smile . )


Firstly your code should look like this:

Code:
//The main library OSLib
#include <oslib/oslib.h>
In order to use oslib in your programs,
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:
PSP_MODULE_INFO("SFX_tutorial", 0, 1, 1);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);
 

Those lines tell us that we are running
the files in usermode. Those lines are necessary to
create an EBOOT.PBP file.


Follow that code with:

Code:
//definition of the pointers towards our sounds
OSL_SOUND *click;


Those lines tell us that we are using the variables
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:

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();

Those lines initialize the graphics mode
and the audio mode used in oslib.


Now for our variables:

Code:

click = oslLoadSoundFile("file.wav", OSL_FMT_NONE);

In order to load the sound defined in the click
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:

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();
   }

With that we end our main control loop but the
code isn't finished yet.

Our last lines are:



Code:


//Leave the program
   oslEndGfx();
   oslQuit();
   return 0;
}

This allows us to shut down our program.
If the command was successful,
the program would return a Zero.

The full code should look like:


Code:
//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:
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.mak

That will generate our EBOOT file.

Be sure to place the sound effect file with the eboot.
Wink


You can find sound effects here:

[You must be registered and logged in to see this link.]
(be sure to download the .wav file, not the .mp3 Razz )

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. Wink




Hope it all helped,



NightStar3






Back to top Go down
KaZ
Admin
avatar

Posts : 131
Points : 204
Join date : 2010-09-20
Location : In The Sky

PostSubject: Re: [Tutorial] Using sound effects in homebrew (OSlib)    Mon Oct 04, 2010 9:58 am

Razz Great Tutorial Nighstar3
btw in return for teaching me oslib i'll make you Mod on the forum
Back to top Go down
 
[Tutorial] Using sound effects in homebrew (OSlib)
Back to top 
Page 1 of 1
 Similar topics
-
» Curl Tutorial!
» Odd Huffing Sound
» AOE_Fan's RMS Command Tutorial
» Outcry. The shimmering game
» i need help ;/

Permissions in this forum:You cannot reply to topics in this forum
PSP Pro GamerZ :: PSP :: C++ Tutorials/OSLIB/MIPS/Programming-
Jump to: