Welcome! Log In Create A New Profile

Advanced

Sound? Howto?

Posted by RatherBeerBrew 
Sound? Howto?
August 03, 2008 03:03PM
Hello folks,

nice to be in this forum :)-D

I got a realy big problem: enabling sound in my programs. I did a very simple game. GFX is not that problem.

But how can I add some sound to my game? I exported a .ogg file with Audacity. How can I put it in? I read the "soundlib" tutorial from "Hermes". But I understand nothing.

Can some one realy help me (us)? Howto put a song and sfx in homebrewed games (demos etc.)?

Thank you guys!!!
Re: Sound? Howto?
August 03, 2008 03:15PM
You can hard code it all yourself, open the file read it to the audio buffer, then write the codec's to play it, make sure to lock while reading from the audio buffers so that you don't get anything overwriting your song. I don't often use libraries, they annoy me somewhat as you can't tell whats happening %100 of the time.
Re: Sound? Howto?
August 03, 2008 03:56PM
I believe if you want to play the .ogg file, you must write the function to do so yourself. An easier method may be to convert it to an .mp3 file and use libogc to play it.



Edited 1 time(s). Last edit at 08/03/2008 03:56PM by Arikado.
Re: Sound? Howto?
August 03, 2008 08:30PM
Arikado Wrote:
-------------------------------------------------------
> I believe if you want to play the .ogg file, you
> must write the function to do so yourself. An
> easier method may be to convert it to an .mp3 file
> and use libogc to play it.

The goal should be:

1. Play a intro song.
2. Stop this intro song and start playing ingamesong (if startet).
3. Play some sfx if triggers (A button, B button etc.) are pressed.

How can I do this with .mp3? Is there any tutorial how to play .mp3 files? Uhm, the idea of WiiPhlex should be ok (put the .mp3 hardcoded in the game...). I can convert the .mp3 with which tool?

I thank you very much for help...
Re: Sound? Howto?
August 03, 2008 11:48PM
Mp3 converter tool I haven't tried it myself but I've heard good things about it. Plus its free. Check out the page first however. No guarantee, but I'm 99.9% sure it will work perfectly.

You'll need devkitPPC properly installed to do the following:

Add -lfat -lwiiuse -logc to the LIBS directory in your makefile.

Add a folder called data to your .pnproj file. Put your .mp3 files in this folder.

When you compile your program and get your files, make a new folder in your apps folder on your SanDisk. Make sure to put boot.elf and the data folder within that folder.

Heres a simple example for making sounds play when you press buttons:
#include  //Wii Remote
#include  //Load .mp3 files from Sandisk
#include //To play .mp3

//Set up video

 int main(){

   VIDEO_Init();//Initialise Video (Note: I'm not doing anything with the screen this program)

   fatInitDefault();//Initialise the front SanDisk for loading .mp3s

   MP3Player_Init();//Initialise the MP3 player

   WPAD_Init();//Initialise the Wii Remote

   while(true){

   WPAD_ScanPads();//Checks the current state of the wii remote

   if(WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_A){
     if(MP3Player_IsPlaying())
      MP3Player_Stop();

      MP3Player_PlayFile("data/soundeffect1.mp3", lengthofsoundeffect1, NULL);/*This line will not compile because I do not have the correct paremeters*/

      }

   if(WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_B){
     if(MP3Player_IsPlaying())
      MP3Player_Stop();

     MP3Player_PlayFile("data/soundeffect2.mp3", lengthofsoundeffect2, NULL);/*This line will not compile because I do not have the correct    paremeter*/

      }


   if(WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_HOME){
     if(MP3Player_IsPlaying())
      MP3Player_Stop();
     break;
    }
   }
     return 0;
 }

Heres another simple example for continuous intro music. Stop and start the music with 2:

#include  //Wii Remote
#include  //Load .mp3 files from Sandisk
#include //To play .mp3

//Set up video

 int main(){

   VIDEO_Init();//Initialise Video (Note: I'm not doing anything with the screen this program)

   fatInitDefault();//Initialise the front SanDisk for loading .mp3s

   MP3Player_Init();//Initialise the MP3 player

   WPAD_Init();//Initialise the Wii Remote

   while(true){

   WPAD_ScanPads();//Checks the current state of the wii remote

   if(WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_2){
     if(MP3Player_IsPlaying()){
      MP3Player_Stop();
      continue;
        }

     if(!MP3Player_IsPlaying())
      MP3Player_PlayFile("data/intro.mp3", introlength, NULL);//This line will not compile because I do not have the correct paremeters

      }

   
    if(WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_HOME){
     if(MP3Player_IsPlaying())
      MP3Player_Stop();
     break;
    }
   }
     return 0;
 }

Based on what is in mp3player.h, those lines that aren't compiling, i think should be compiling (however I replaced the second parameter with a number when I attempted to compile). Other than that those two lines, the programs would actually work perfectly if only the lines would compile. I'll edit this post if I get it working.

Sorry about not being able to get the MP3_PlayFile() working. Heres the prototype for it:

 s32 MP3Player_PlayFile(void *cb_data,s32 (*reader)(void *,void *,s32),void (*filterfunc)(struct mad_stream *,struct mad_frame *));

Hope that all helps.



Edited 3 time(s). Last edit at 08/04/2008 11:39PM by Arikado.
Re: Sound? Howto?
August 04, 2008 12:12AM
Look at the source code of an existing homebrew app.
Re: Sound? Howto?
August 04, 2008 01:49AM
Actually, I did. I looked at DragonMedia Player, MiniMp3 Player, and MPlayerWii. MiniMp3 Player used GRRLIB, which I know nothing about. DragonMedia Player used libwiisprite, which I know quite a bit about. Unfortunately I didn't understand its loading technique. I sort of just quickly skimmed MPlayerWii.

I've been able to figure out that the function needs 3 parameters to pass. The first is an s32 which I know nearly nothing about. Ditto the second parameter. It is also an s32 but holds the length of the file. The last parameter passes either NULL or TRUE and determines whether or not the .mp3 will keep playing after it ends.
Re: Sound? Howto?
August 04, 2008 02:52AM
This is how to play mp3s and it uses libwiisprite [http://wiibrew.org/]
Re: Sound? Howto?
August 04, 2008 04:12AM
Does no one write the code for this stuff themselves these days...
Re: Sound? Howto?
August 04, 2008 05:35AM
I know... Shameful!
Re: Sound? Howto?
August 04, 2008 03:39PM
Sorry guys,

everything I tried (what's written above) didn't work. Even if I include the "mp3player.h" lib the compiler is showing an error:

--------------snipped----------------
c:/devkitPro/libogc/lib/wii\libmad.a(mp3player.o): In function `MP3Player_Init':
mp3player.c:(.text.MP3Player_Init+0x28): undefined reference to `AUDIO_Init'
mp3player.c:(.text.MP3Player_Init+0x30): undefined reference to `AUDIO_SetDSPSampleRate'
collect2: ld returned 1 exit status
make[1]: *** [/c/projects/wii/dke/dke.elf] Error 1
"make": *** [build] Error 2

> Process Exit Code: 2
--------------snipped----------------

What's wrong?
Re: Sound? Howto?
August 04, 2008 06:04PM
What does the
LIBS:

line of your Makefile have?
Re: Sound? Howto?
August 04, 2008 06:26PM
vader347 Wrote:
-------------------------------------------------------
> What does the
> LIBS:
>
> line of your Makefile have?



That:

-lpng -lz -lfat -lwiiuse -lbte -logc -lm -lmad
Re: Sound? Howto?
August 04, 2008 06:58PM
Quote

That:-lpng -lz -lfat -lwiiuse -lbte -logc -lm -lmad
Try changing that to

-lpng -lz -lfat -lwiiuse -lbte -lmp3player -lmad -logc -lm
Re: Sound? Howto?
August 04, 2008 09:30PM
vader347 Wrote:
-------------------------------------------------------
> That:-lpng -lz -lfat -lwiiuse -lbte -logc -lm
> -lmad
> Try changing that to
>
> -lpng -lz -lfat -lwiiuse -lbte -lmp3player -lmad
> -logc -lm

Damned. So close:

> "make"
linking ... dke.elf
c:/devkitpro/devkitppc/bin/../lib/gcc/powerpc-gekko/4.2.3/../../../../powerpc-gekko/bin/ld.exe: cannot find -lmp3player
collect2: ld returned 1 exit status
make[1]: *** [/c/projects/wii/dke/dke.elf] Error 1
"make": *** [build] Error 2

> Process Exit Code: 2
> Time Taken: 00:00

What's missing? mp3player.h is in directory C:\devkitPro\libogc\include....
Re: Sound? Howto?
August 04, 2008 09:32PM
remove -lmp3player
Re: Sound? Howto?
August 04, 2008 09:50PM
vader347 Wrote:
-------------------------------------------------------
> remove -lmp3player

Then

--------------snipped----------------
c:/devkitPro/libogc/lib/wii\libmad.a(mp3player.o): In function `MP3Player_Init':
mp3player.c:(.text.MP3Player_Init+0x28): undefined reference to `AUDIO_Init'
mp3player.c:(.text.MP3Player_Init+0x30): undefined reference to `AUDIO_SetDSPSampleRate'
collect2: ld returned 1 exit status
make[1]: *** [/c/projects/wii/dke/dke.elf] Error 1
"make": *** [build] Error 2

> Process Exit Code: 2
--------------snipped----------------

appears again...
Re: Sound? Howto?
August 04, 2008 10:15PM
Sorry this time it should work
-lpng -lz -lwiiuse -lmad -lbte -lfat -logc -lm
Re: Sound? Howto?
August 04, 2008 10:27PM
I have -lmp3player -lwiiuse -lbte -lfat -logc -lm Unfortunately, I still haven't fixed the Mp3Player_Playfile() so it doesn't work yet.
Re: Sound? Howto?
August 04, 2008 10:33PM
Quote

I have -lmp3player -lwiiuse -lbte -lfat -logc -lm Unfortunately, I still haven't fixed the Mp3Player_Playfile() so it doesn't work yet.
RatherBeerBrew and I don't have libmp3player. Unless it is somewhere weird.
Sorry, only registered users may post in this forum.

Click here to login