psp mp3 implementation

git-svn-id: file:///home/notaz/opt/svn/PicoDrive@293 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2007-11-10 22:43:26 +00:00
parent b5e5172d04
commit 4b167c12c7
14 changed files with 557 additions and 40 deletions

View file

@ -16,6 +16,7 @@
static char *rom_exts[] = { "bin", "gen", "smd", "iso" };
void (*PicoCartLoadProgressCB)(int percent) = NULL;
void (*PicoCDLoadProgressCB)(int percent) = NULL; // handled in Pico/cd/cd_file.c
pm_file *pm_open(const char *path)

View file

@ -99,9 +99,9 @@ int pm_close(pm_file *fp);
int PicoCartLoad(pm_file *f,unsigned char **prom,unsigned int *psize);
int PicoCartInsert(unsigned char *rom,unsigned int romsize);
void Byteswap(unsigned char *data,int len);
// anotherguest
int PicoUnloadCart(unsigned char* romdata);
extern void (*PicoCartLoadProgressCB)(int percent);
extern void (*PicoCDLoadProgressCB)(int percent);
// Draw.c
void PicoDrawSetColorFormat(int which); // 0=BGR444, 1=RGB555, 2=8bit(HighPal pal)

View file

@ -7,16 +7,14 @@
* *
***********************************************************/
#include <sys/stat.h>
#include "../PicoInt.h"
#include "cd_file.h"
#define cdprintf dprintf
//#define cdprintf(x...)
//#define cdprintf(f,...) printf(f "\n",##__VA_ARGS__) // tmp
#define DEBUG_CD
PICO_INTERNAL int Load_ISO(const char *iso_name, int is_bin)
{
int i, j, num_track, Cur_LBA, index, ret, iso_name_len;
@ -26,11 +24,13 @@ PICO_INTERNAL int Load_ISO(const char *iso_name, int is_bin)
static char *exts[] = {
"%02d.mp3", " %02d.mp3", "-%02d.mp3", "_%02d.mp3", " - %02d.mp3",
"%d.mp3", " %d.mp3", "-%d.mp3", "_%d.mp3", " - %d.mp3",
#if CASE_SENSITIVE_FS
"%02d.MP3", " %02d.MP3", "-%02d.MP3", "_%02d.MP3", " - %02d.MP3",
/* "%02d.wav", " %02d.wav", "-%02d.wav", "_%02d.wav", " - %02d.wav",
"%d.wav", " %d.wav", "-%d.wav", "_%d.wav", " - %2d.wav" */
#endif
};
if (PicoCDLoadProgressCB != NULL) PicoCDLoadProgressCB(1);
Unload_ISO();
Tracks[0].ftype = is_bin ? TYPE_BIN : TYPE_ISO;
@ -56,10 +56,14 @@ PICO_INTERNAL int Load_ISO(const char *iso_name, int is_bin)
Cur_LBA = Tracks[0].Length; // Size in sectors
iso_name_len = strlen(iso_name);
if (iso_name_len >= sizeof(tmp_name))
iso_name_len = sizeof(tmp_name) - 1;
for (num_track = 2, i = 0; i < 100; i++)
{
for(j = 0; j < sizeof(exts)/sizeof(char *); j++)
if (PicoCDLoadProgressCB != NULL && i > 1) PicoCDLoadProgressCB(i);
for (j = 0; j < sizeof(exts)/sizeof(char *); j++)
{
int ext_len;
FILE *tmp_file;
@ -80,18 +84,28 @@ PICO_INTERNAL int Load_ISO(const char *iso_name, int is_bin)
if (tmp_file)
{
int fs;
struct stat file_stat;
index = num_track - 1;
ret = stat(tmp_name, &file_stat);
fs = file_stat.st_size; // used to calculate lenght
ret = fseek(tmp_file, 0, SEEK_END);
fs = ftell(tmp_file); // used to calculate lenght
fseek(tmp_file, 0, SEEK_SET);
#if DONT_OPEN_MANY_FILES
// some systems (like PSP) can't have many open files at a time,
// so we work with their names instead.
fclose(tmp_file);
tmp_file = (void *) strdup(tmp_name);
#endif
Tracks[index].KBtps = (short) mp3_get_bitrate(tmp_file, fs);
Tracks[index].KBtps >>= 3;
if (ret != 0 || Tracks[index].KBtps <= 0)
{
cdprintf("Error track %i: stat %i, rate %i", index, ret, Tracks[index].KBtps);
cdprintf("Error track %i: rate %i", index, Tracks[index].KBtps);
#if !DONT_OPEN_MANY_FILES
fclose(tmp_file);
#else
free(tmp_file);
#endif
continue;
}
@ -124,6 +138,8 @@ PICO_INTERNAL int Load_ISO(const char *iso_name, int is_bin)
cdprintf("End CD - %02d:%02d:%02d\n\n", Tracks[index].MSF.M,
Tracks[index].MSF.S, Tracks[index].MSF.F);
if (PicoCDLoadProgressCB != NULL) PicoCDLoadProgressCB(100);
return 0;
}
@ -138,7 +154,12 @@ PICO_INTERNAL void Unload_ISO(void)
for(i = 1; i < 100; i++)
{
if (Pico_mcd->TOC.Tracks[i].F) fclose(Pico_mcd->TOC.Tracks[i].F);
if (Pico_mcd->TOC.Tracks[i].F != NULL)
#if !DONT_OPEN_MANY_FILES
fclose(Pico_mcd->TOC.Tracks[i].F);
#else
free(Pico_mcd->TOC.Tracks[i].F);
#endif
}
memset(Pico_mcd->TOC.Tracks, 0, sizeof(Pico_mcd->TOC.Tracks));
}

View file

@ -39,16 +39,33 @@ void mix_32_to_16_mono(short *dest, int *src, int count)
}
/* unimplemented... */
void mix_16h_to_32(int *dest_buf, short *mp3_buf, int count)
{
while (count--)
{
*dest_buf++ += *mp3_buf++ >> 1;
}
}
void mix_16h_to_32_s1(int *dest_buf, short *mp3_buf, int count)
{
count >>= 1;
while (count--)
{
*dest_buf++ += *mp3_buf++ >> 1;
*dest_buf++ += *mp3_buf++ >> 1;
mp3_buf += 1*2;
}
}
void mix_16h_to_32_s2(int *dest_buf, short *mp3_buf, int count)
{
count >>= 1;
while (count--)
{
*dest_buf++ += *mp3_buf++ >> 1;
*dest_buf++ += *mp3_buf++ >> 1;
mp3_buf += 3*2;
}
}