Welcome! Log In Create A New Profile

Advanced

Playing Sounds

Posted by g_man 
Playing Sounds
March 29, 2009 07:04AM
I'm a n00b when it comes to wii functions, and i want to know how to play music in my game.
I don't care what file type i have to use, or what librarys i just want help.
Re: Playing Sounds
March 29, 2009 06:13PM
You are going to need a mixing library, asnd is the one people are recommending, and you are going to need a decoder library unless you are planing on storing the music uncompressed, there is not much choice between the decoders, there is generally only one that has been hacked up to use asnd for each encoding.
Re: Playing Sounds
March 29, 2009 07:06PM
OK i found out that i have asnd, but i'm not sure how to load a file into the buffer, and what is the name of the decoder?
thanks
Re: Playing Sounds
March 30, 2009 06:49AM
Check out mp3player.h

void MP3Player_Init();
void MP3Player_Stop();
BOOL MP3Player_IsPlaying();
void MP3Player_Volume(u32 volume);
s32 MP3Player_PlayBuffer(const void *buffer,s32 len,void (*filterfunc)(struct mad_stream *,struct mad_frame *));
s32 MP3Player_PlayFile(void *cb_data,s32 (*reader)(void *,void *,s32),void (*filterfunc)(struct mad_stream *,struct mad_frame *));

Re: Playing Sounds
March 30, 2009 07:34AM
Doesn't mp3player.h load mp3 directly from SD? I've seen other code using asnd where the ogg files were converted to .h during compile time. Which way would be less stressing on the buffer?
Re: Playing Sounds
March 30, 2009 07:48AM
You can load an mp3 via a buffer if you don't want to use the SD.

     MP3Player_Init();
     while(1) {
       if(!MP3Player_IsPlaying())
          MP3Player_PlayBuffer(buffer,buffer_size,NULL);
     }
     if(MP3Player_IsPlaying()) MP3Player_Stop();
Re: Playing Sounds
March 31, 2009 12:21AM
Ok to figure out what all the parts are all look at some examples, but when i link it it says that it can't find some ASND files, i have included the ASND lib file and header and nothing changed, i'm also including mp3player.h and lmad
Also what is a buffer? is it just a pointer



Edited 1 time(s). Last edit at 03/31/2009 12:30AM by g_man.
Re: Playing Sounds
March 31, 2009 01:13AM
The buffer is a pointer to your mp3 data. Which you could have loaded from a file or included as a binary header.
Re: Playing Sounds
March 31, 2009 01:20AM
Quote
scanff
The buffer is a pointer to your mp3 data. Which you could have loaded from a file or included as a binary header.
I've seen many sources that include as binary, is this done with a raw2c type program, or by having the Makefile convert during build like you do with .jpg or .ogg? Just curious.
Re: Playing Sounds
March 31, 2009 02:20AM
I believe there's a make command bin2o that converts a binary file to be included in the output elf. I've only used the make command to include an image so I don't know if you can do it for any other binary files.

If you can't use a make file command then it's no big deal I have a C++ program I wrote in about 10mins that will convert a binary file into a hex array. It outputs the data as a hex array in a file called data.h. All you have to do is include data.h in your project and your buffer will be called bin_data,.Here it is if you want it.

#include 

using namespace std;

int main()
{


    FILE* in;
    in = fopen("yourfilename.whatever","rb");
    FILE* out;
    out = fopen("data.h","wb");

    unsigned char b = 0;

    fseek (in, 0, SEEK_END);
    unsigned long size = ftell(in);
    fseek (in, 0, SEEK_SET);

    //
    #define hdr ("static unsigned char bin_data[]={")
    #define data_size ("static unsigned long bin_data_size=")
    fwrite(hdr,strlen(hdr),1,out);
    char outchar[15] = {0};

    for(int p=0;p<size;p++) {
        fread(&b,1,1,in);

        sprintf(outchar,"0x%0X",b);

        fwrite(outchar,strlen(outchar),1,out);
        if (p!=size-1) fwrite(",",1,1,out);
        if(!(p % 10)) fwrite("\n",1,1,out); // formatting

    }

    fwrite("\n};\n\n",5,1,out);
    fwrite(data_size,strlen(data_size),1,out);
    sprintf(outchar,"%d",size);
    fwrite(outchar,strlen(outchar),1,out);
    fwrite(";\n",2,1,out);

    fclose(in);
    fclose(out);


    return 0;
}

Re: Playing Sounds
March 31, 2009 02:34AM
i just need to find a compiler, i think i have G++ on ubuntu
Re: Playing Sounds
March 31, 2009 02:51AM
What kind of mp3 does mp3player plays (Bit Size/stereo or mono/sampling rate)?
Re: Playing Sounds
March 31, 2009 03:28AM
Quote
scanff
I believe there's a make command bin2o that converts a binary file to be included in the output elf. I've only used the make command to include an image so I don't know if you can do it for any other binary files.

If you can't use a make file command then it's no big deal I have a C++ program I wrote in about 10mins that will convert a binary file into a hex array. It outputs the data as a hex array in a file called data.h. All you have to do is include data.h in your project and your buffer will be called bin_data,.Here it is if you want it.
Nice, I'll try your program and see how it works out...thanks! Also, I haven't tried the bin2o command in the Makefile, but that was what I was originally referring to. I know it does images, and I've seen tutorials that used .OGG music files in Wii projects, that use the same bin2o command for .ogg files, so I would assume it would work for .mp3, but I could be wrong. I'll do some testing with it, and if it works, I'll post the info on it.



Edited 1 time(s). Last edit at 03/31/2009 03:29AM by RazorChrist.
Re: Playing Sounds
March 31, 2009 03:33AM
Quote
Crayon
What kind of mp3 does mp3player plays (Bit Size/stereo or mono/sampling rate)?

I think all. It's a wrapper for libmad.
Re: Playing Sounds
April 01, 2009 12:48AM
I finally got the program compiled and it just gives me zeros, And yes i did replace this line
in = fopen("yourfilename.whatever","rb");
to
in = fopen("echoes.mp3","rb");
Re: Playing Sounds
April 01, 2009 01:39AM
Zero's, like how?
Re: Playing Sounds
April 01, 2009 02:09AM
0xff Sorry, i meant 0x00
I compiled with raw2c, but i'd like to get the buffer stuff loaded. I don't really know how



Edited 1 time(s). Last edit at 04/01/2009 02:28AM by g_man.
Re: Playing Sounds
April 01, 2009 02:57AM
Quote
g_man
I finally got the program compiled and it just gives me zeros.
Hey, what did you use to compile this? DevKitPro or gcc? Also, did you have to write a Makefile for it?
Re: Playing Sounds
April 01, 2009 02:59AM
Hi,

You can use the bin2o program to convert any binary file to a output elf (".o" file and a header file with the variable declaration too), so you'll be able to load it in the code, I think it'll work with any type of data/file.

For using it you only need to put this:

Quote

#---------------------------------------------------------------------------------
%.mp3.o : %.mp3
#---------------------------------------------------------------------------------
@echo $(notdir $<)
$(bin2o)

-include $(DEPENDS)

At the end of your code (before the "#endif" line of course). You can change the extension to other one you want to convert (and you can add them one after the other).

Then you only need to add the generated header file to your code:

Quote

#include "nameofthefile_mp3.h"

(Note that the "_mp3" is the extension of the original file.)

And you will have the data of the file in one variable called equals to the include I putted before but without the ".h" (obviously xD).

So I think you will be able to do this:

Quote

MP3Player_Init();
MP3Player_PlayBuffer(songname_mp3,songname_mp3_size,NULL);

Ah! you need to put all your mp3 or files you want to convert in the "data" directory, and be sure you have this line in the makefile:

Quote

DATA := data

So that's all, I hope that helped you ^.^

TiRaNog.
Re: Playing Sounds
April 01, 2009 03:37AM
The above works great for converting the files, except I'm getting some compile/linking errors:

c:/projects/wii/game/source/game.cpp: In function 'void menu_loop()':
c:/projects/wii/game/source/game.cpp:146: warning: statement is a reference, not call, to function 'MP3Player_Stop'
c:/projects/wii/game/source/game.cpp:146: warning: statement has no effect
GRRLIB.c
pngu.c
linking ... game.elf
game.o: In function `menu_loop()':
c:/projects/wii/game/source/game.cpp:136: undefined reference to `MP3Player_Init'
c:/projects/wii/game/source/game.cpp:137: undefined reference to `MP3Player_PlayBuffer'
collect2: ld returned 1 exit status (fixed)

I must be missing something somewhere. I included to game.cpp. And I put -lmad in my makefile, is there anything else that I missed?



Edited 5 time(s). Last edit at 04/01/2009 04:12AM by RazorChrist.
Sorry, only registered users may post in this forum.

Click here to login