forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Feeding .mp3s into a buffer for playing in the MUSIC folder?

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
sg57



Joined: 14 Oct 2005
Posts: 154

PostPosted: Sat Feb 18, 2006 3:25 pm    Post subject: Feeding .mp3s into a buffer for playing in the MUSIC folder? Reply with quote

I need some help. I (we if you count ShatterDome and Smerity) am/are trying to read all the .mp3's in the Music folder, and feed them into a buffer so I/we can call 'MP3_Load(mp3bufferhere);' when using libmad lib. So far this is what we have got:
Code:

#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <pspaudio.h>
#include <pspaudiolib.h>
#include "mp3player.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

PSP_MODULE_INFO("Mp3 Player Directory Example", 0, 1, 1);

#define printf pspDebugScreenPrintf

int exit_callback(int arg1, int arg2, void *common) {
          sceKernelExitGame();
          return 0;
}
int CallbackThread(SceSize args, void *argp) {
          int cbid;

          cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
          sceKernelRegisterExitCall  back(cbid);

          sceKernelSleepThreadCB(); 

          return 0;
}
int SetupCallbacks(void) {
          int thid = 0;

          thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
          if(thid >= 0) {
                    sceKernelStartThread(thid  , 0, 0);
          }

          return thid;
}

struct songinfo
{ char songname[255];} ;

struct songinfo playlist[100];

int getsonglist(void)
{
int dfd;
SceIoDirent songdir;
memset(&songdir, 0, sizeof songdir);
char buffer[255];

int songcount = 0, maxsongs = 0;

dfd = sceIoDopen("ms0:/PSP/MUSIC/TEST/");

while(sceIoDread(dfd, &songdir) > 0)
{
//sceIoDread(dfd,&songdir);

sprintf(playlist[songcount].songname,"%s",songdir.d_name);
maxsongs = songcount;
songcount++;

} // while sceIODread
sceIoClose(dfd);

return maxsongs;
} // int

int main()
{
pspDebugScreenInit();
SetupCallbacks();
pspAudioInit();
SceCtrlData pad;

char songpathbuf[255];
int songcounter = 1, change = 0, numsong = getsonglist();


MP3_Init(1);

songcounter++;
sprintf(songpathbuf,"ms0:/PSP/MUSIC/TEST/%s",playlist[songcounter].songname);

printf("songpathbuf == %s\n", songpathbuf);
MP3_Load(songpathbuf);
MP3_Play();
while(1) { //wait for X to be pressed
    sceCtrlReadBufferPositive  (&pad, 1);
    if(pad.Buttons & PSP_CTRL_CROSS) break;

    if(pad.Buttons & PSP_CTRL_CIRCLE) MP3_Pause();

    if(pad.Buttons & PSP_CTRL_RTRIGGER) { change = 1; songcounter++; }

    if(pad.Buttons & PSP_CTRL_LTRIGGER) { change = 1; songcounter--; }

    if(MP3_EndOfStream() == 1) { change = 1; songcounter++; }

if (change == 1)
{
MP3_Stop();
MP3_FreeTune();
if (songcounter > numsong) songcounter = numsong;
if (songcounter < 1) songcounter = 1;

sprintf(songpathbuf,"ms0:/PSP/MUSIC/TEST/%s",playlist[songcounter].songname);

printf("songpathbuf == %s\n", songpathbuf);

MP3_Load(songpathbuf);
MP3_Play();
change = 0;
} // if change == 1

} // while
MP3_Stop();
//MP3_FreeTune();

sceKernelSleepThread();

return 0;
}

Now, others have done this and it works, but I have edited ita little so it works with my code, and it complies alright, but i get this when running (using printf I believe):
http://forums.qj.net/attachment.php?attachmentid=2679&stc=1

Anyone know how I could read all the .mp3s from the MUSIC folder and load them using hte library libmad?[/code]
Back to top
View user's profile Send private message
.: Smerity :.



Joined: 04 Feb 2006
Posts: 9

PostPosted: Sat Feb 18, 2006 5:58 pm    Post subject: Reply with quote

Ok, I got it to

    Ignore non-Mp3 files
    Select previous and next files using L and R


What I haven't got it to do yet is -

    Ability to select directories
    Reset the timer so it starts at the start of the next song


Any help on the latter two would be good...

Code:

// Mp3 Directory Player, original code by Shatterdome, improved on by Smerity

#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <pspaudio.h>
#include <pspaudiolib.h>
#include "mp3player.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

PSP_MODULE_INFO("Mp3 Directory Example", 0, 1, 1); // name, other, major, minor

#define printf pspDebugScreenPrintf

int exit_callback(int arg1, int arg2, void *common) {
          sceKernelExitGame();
          return 0;
}
int CallbackThread(SceSize args, void *argp) {
          int cbid;

          cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
          sceKernelRegisterExitCallback(cbid);

          sceKernelSleepThreadCB();

          return 0;
}
int SetupCallbacks(void) {
          int thid = 0;

          thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
          if(thid >= 0) {
                    sceKernelStartThread(thid, 0, 0);
          }

          return thid;
}

struct songinfo
{ char songname[255];} ;

struct songinfo playlist[100]; //an array of 100 structures of type songinfo (which only holds one variable, but can hold as many as you want...
// This function reads all the songs in the psp/music dir and feeds them into that playlist[100] array, easier to work with...

int getsonglist(void)
{
int dfd;
SceIoDirent songdir;
memset(&songdir, 0, sizeof songdir);
char buffer[255];

int songcount = 0, maxsongs = 0;

dfd = sceIoDopen("ms0:/PSP/MUSIC/");

while(sceIoDread(dfd, &songdir) > 0)
{
//sceIoDread(dfd,&songdir);

sprintf(buffer,"%s",songdir.d_name);
// debug - printf("buffer == %s\n", buffer);
char *suffix = strrchr (buffer, '.');
if (suffix != NULL)
{
if (stricmp (suffix, ".mp3") == 0)
{
sprintf(playlist[songcount].songname,"%s",buffer);
maxsongs = songcount;
songcount++;
} // != NULL
} // == 0

} // while sceIODread
sceIoClose(dfd);

return maxsongs;
} // int

int main()
{
pspDebugScreenInit();
SetupCallbacks();
pspAudioInit();
SceCtrlData pad;

char songpathbuf[255];
int songcounter = 0, change = 0, numsong = getsonglist();


MP3_Init(1);

pspDebugScreenSetXY(2, 4);
if (numsong < 1) printf("No songs in folder...\n\n");

sprintf(songpathbuf,"ms0:/PSP/MUSIC/%s",playlist[songcounter].songname);

printf("songpathbuf == %s\n", songpathbuf);
MP3_Load(songpathbuf);
MP3_Play();
while(1) {
    sceCtrlReadBufferPositive(&pad, 1);
    if(pad.Buttons & PSP_CTRL_CROSS) break;

    if(pad.Buttons & PSP_CTRL_CIRCLE) MP3_Pause();

    if(pad.Buttons & PSP_CTRL_RTRIGGER) { change = 1; songcounter++; }

    if(pad.Buttons & PSP_CTRL_LTRIGGER) { change = 1; songcounter--; }

    if(MP3_EndOfStream() == 1) { change = 1; songcounter++; }

if (change == 1)
{
MP3_FreeTune();
MP3_Stop();
if (songcounter > numsong) songcounter = 0; // repeat from start
if (songcounter < 0) songcounter = 0; // compensate for . and .. but will be fixed when we can ignore non Mp3s

sprintf(songpathbuf,"ms0:/PSP/MUSIC/%s",playlist[songcounter].songname);

// debug - printf("songpathbuf == %s\n", songpathbuf);
// debug - printf("songcounter == %i\n", songcounter);

MP3_Load(songpathbuf);
MP3_Play();
change = 0;
} // if change == 1

} // while
MP3_Stop();

sceKernelSleepThread();

return 0;
}
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group