|
Playing sound files September 29, 2009 03:16PM | Registered: 16 years ago Posts: 34 |
FILE *f = fopen("/loop.mod", "rb");
if (f == NULL) {
fclose(f);
} else {
fseek (f , 0, SEEK_END);
mod_size = ftell (f);
rewind(f);
// allocate memory to contain the whole file:
buffer = (char*) malloc (sizeof(char)*mod_size);
if (buffer == NULL) { perror ("Memory error\n"); }
// copy the file into the buffer:
result = fread (buffer,1,mod_size,f);
if (result != mod_size) { perror ("Reading error\n"); }
fclose(f);
MODPlay_SetMOD(&play, buffer);
MODPlay_Start(&play);
}|
Re: Playing sound files September 29, 2009 04:19PM | Registered: 17 years ago Posts: 175 |
|
Re: Playing sound files September 29, 2009 11:15PM | Admin Registered: 17 years ago Posts: 5,132 |
|
Re: Playing sound files October 01, 2009 05:19AM | Registered: 16 years ago Posts: 552 |
FILE *BGM = 0; long lSize; char * mbuffer; size_t mresult; bool mp3isready = false;
BGM = fopen("test.mp3", "rb");
fseek (BGM , 0 , SEEK_END);
lSize = ftell (BGM);
rewind (BGM);
mbuffer = (char*) malloc (sizeof(char)*lSize);
mresult = fread (mbuffer,1,lSize,BGM);
fclose(BGM);
MP3Player_PlayBuffer(mbuffer, lSize, NULL);|
Re: Playing sound files October 03, 2009 04:47AM | Registered: 16 years ago Posts: 552 |
|
Re: Playing sound files October 03, 2009 07:36AM | Registered: 16 years ago Posts: 703 |
|
Re: Playing sound files October 03, 2009 06:36PM | Admin Registered: 17 years ago Posts: 5,132 |
|
Re: Playing sound files October 04, 2009 04:50AM | Registered: 16 years ago Posts: 552 |
#include asndlib.h
#include mp3player.h
FILE *BGM = 0;
long lSize;
char * mbuffer;
size_t mresult;
int main() {
ASND_Init();
MP3Player_Init();
while(1){
Scanpads
WHEN A IS PRESSED {
BGM = fopen("test.mp3", "rb");
fseek (BGM , 0 , SEEK_END);
lSize = ftell (BGM);
rewind (BGM);
mbuffer = (char*) malloc (sizeof(char)*lSize);
mresult = fread (mbuffer,1,lSize,BGM);
fclose(BGM);
MP3Player_PlayBuffer(mbuffer, lSize, NULL);
}
}
}
No compile errors, just dump when i press A|
Re: Playing sound files October 04, 2009 05:45AM | Registered: 16 years ago Posts: 703 |
|
Re: Playing sound files October 04, 2009 03:06PM | Admin Registered: 17 years ago Posts: 5,132 |
if(WPAD_ButtonsDown(WPAD_CHAN_0)&WPAD_BUTTON_B){
if(MP3Player_IsPlaying())
MP3Player_Stop();
}|
Re: Playing sound files October 04, 2009 03:23PM | Registered: 16 years ago Posts: 552 |
|
Re: Playing sound files October 04, 2009 03:34PM | Admin Registered: 17 years ago Posts: 5,132 |
|
Re: Playing sound files October 04, 2009 03:44PM | Registered: 16 years ago Posts: 552 |
|
Re: Playing sound files October 04, 2009 03:51PM | Admin Registered: 17 years ago Posts: 5,132 |
|
Re: Playing sound files October 04, 2009 03:53PM | Registered: 16 years ago Posts: 552 |
|
Re: Playing sound files October 04, 2009 04:05PM | Admin Registered: 17 years ago Posts: 5,132 |
|
Re: Playing sound files October 04, 2009 04:45PM | Registered: 16 years ago Posts: 552 |
void playsfx(int freq, void *pcm, s32 pcmsize) {
ASND_SetVoice(SND_GetFirstUnusedVoice(), 3, freq, 0, pcm, pcmsize, soundvol, soundvol, NULL);
}playsfx(44100, (char *) click_pcm, click_pcm_size);
#include "click_pcm.h"
|
Re: Playing sound files October 05, 2009 10:10PM | Registered: 16 years ago Posts: 13 |
|
Re: Playing sound files October 07, 2009 04:05AM | Registered: 16 years ago Posts: 552 |
|
Re: Playing sound files October 10, 2009 04:45PM | Registered: 16 years ago Posts: 34 |
#include mp3player.h // lmad in MakeFile
#include asndlib.h // lasnd in MakeFile
int main()
{
PlayMP3("data/music/RPB-WoPiMedley.mp3");
}
void PlayMP3(const std::string filename) {
/* Sources:
1. [arikadosblog.blogspot.com]
2. [www.pastie.org]
*/
ASND_Init();
MP3Player_Init();
FILE* f = OpenFile(filename, "rb");
long size = FileSize(f);
// allocate memory to contain the whole file:
char* buffer;
buffer = (char*) malloc (sizeof(char)*size);
if (buffer == NULL) Error("cannot allocate memory for file '" + filename + "'");
// copy the file into the buffer:
long result = fread (buffer, 1, size, f);
if (result != size) Error ("cannot store file '" + filename + "' in memory");
fclose(f); // file is stored so we can close it now
// play the buffer
MP3Player_PlayBuffer(buffer, size, NULL);
}
FILE* OpenFile(const std::string filename, std::string fam)
{
FILE* file = NULL;
if(!fatInitDefault()) Error("cannot initialize FAT system");
file = fopen(filename.c_str(), fam.c_str()); // fam = file access mode
if (file == NULL) Error("cannot open file '" + filename + "'");
return file;
}
long FileSize(FILE* f) {
/* Sources:
1. [arikadosblog.blogspot.com]
2. [www.pastie.org]
*/
long size;
fseek (f, 0, SEEK_END);
size = ftell(f);
rewind(f);
return size;
}
void Error(const std::string message) {
printf("\x1b[2J"); // clear the screen
printf("\nError: "); printf("%s", message.c_str());
WaitWiiButton(); // wait for any button to be pressed on the wiimote
exit(1);
}