PSP Pro GamerZ
Would you like to react to this message? Create an account in a few clicks or log in to continue.

PSP Pro GamerZ

For all your PSP Needs
AKA Team Unknown Forum
 
HomeLatest imagesRegisterLog 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 ----

 

 [Tutorial] Using sound effects in homebrew (OSlib)

Go down 
2 posters
AuthorMessage
NightStar3




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

[Tutorial] Using sound effects in homebrew (OSlib)   Empty
PostSubject: [Tutorial] Using sound effects in homebrew (OSlib)    [Tutorial] Using sound effects in homebrew (OSlib)   EmptySun 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
KaZ


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

[Tutorial] Using sound effects in homebrew (OSlib)   Empty
PostSubject: Re: [Tutorial] Using sound effects in homebrew (OSlib)    [Tutorial] Using sound effects in homebrew (OSlib)   EmptyMon 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
-
» [Homebrew]Blue Screen of Death by KaZ[Homebrew]
» [Tutorial] C/C++ Tutorials Part 3 - CTRL Pad by KaZ[Tutorial]
» [Tutorial]C/C++ Tutorials Part 4 - I/O Functions [Tutorial]
» [Quick Tutorial]Part 1 - How to setup PSPDev/PSPSDK [Tutorial]
» [Tutorial] C/C++ Tutorials Part 2 - Making a Hello world by KaZ [Tutorial]

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