asap: fix stereo mode and hopefully fix metadata handling.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18140 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Dominik Wenger 2008-07-28 19:20:40 +00:00
parent 8df332c062
commit 9b7566e3ec
2 changed files with 62 additions and 49 deletions

View file

@ -36,6 +36,7 @@ enum codec_status codec_main(void)
int song;
int duration;
char* module;
int bytesPerSample =2;
/* Generic codec initialisation */
ci->configure(CODEC_SET_FILEBUF_WATERMARK, 1024*512);
@ -74,10 +75,15 @@ next_track:
ci->configure(DSP_SET_SAMPLE_DEPTH, 16);
/* Stereo or Mono output ? */
if(asap.module_info.channels ==1)
{
ci->configure(DSP_SET_STEREO_MODE, STEREO_MONO);
bytesPerSample = 2;
}
else
{
ci->configure(DSP_SET_STEREO_MODE, STEREO_INTERLEAVED);
bytesPerSample = 4;
}
/* reset eleapsed */
ci->set_elapsed(0);
@ -115,7 +121,7 @@ next_track:
n_bytes = ASAP_Generate(&asap, samples, sizeof(samples), ASAP_FORMAT_S16_BE);
#endif
ci->pcmbuf_insert(samples, NULL, n_bytes /2);
ci->pcmbuf_insert(samples, NULL, n_bytes /bytesPerSample);
bytes_done += n_bytes;
ci->set_elapsed((bytes_done / 2) / 44.1);

View file

@ -33,18 +33,6 @@
#define MAX_SONGS 32
struct module_info
{
char name[255];
char author[255];
char date[255];
int numSongs;
int defSong;
int numChannels;
int durations[32];
int loops[32];
};
static bool parse_dec(int *retval, const char *p, int minval, int maxval)
{
int r = 0;
@ -116,7 +104,26 @@ static int ASAP_ParseDuration(const char *s)
return r;
}
static bool parse_sap_header(int fd,struct module_info* info,int file_len)
static bool read_asap_string(char* source,char** buf,char** buffer_end,char** dest)
{
if(parse_text(*buf,source) == false) return false;
/* set dest pointer */
*dest = *buf;
/* move buf ptr */
*buf += strlen(*buf)+1;
/* check size */
if(*buf >= *buffer_end)
{
DEBUGF("Buffer full\n");
return false;
}
return true;
}
static bool parse_sap_header(int fd,struct mp3entry* id3,int file_len)
{
int module_index = 0;
int sap_signature = -1;
@ -125,15 +132,20 @@ static bool parse_sap_header(int fd,struct module_info* info,int file_len)
int i;
/* set defaults */
info->numSongs=1;
info->defSong=0;
info->numChannels=1;
int numSongs=1;
int defSong=0;
int numChannels=1;
int durations[MAX_SONGS];
int loops[MAX_SONGS];
for (i = 0; i < MAX_SONGS; i++) {
info->durations[i] = -1;
info->loops[i] = 0;
durations[i] = -1;
loops[i] = 0;
}
/* use id3v2 buffer for our strings */
char* buffer = id3->id3v2buf;
char* buffer_end = id3->id3v2buf + ID3V2_BUF_SIZE;
/* parse file */
while (1)
{
@ -180,45 +192,51 @@ static bool parse_sap_header(int fd,struct module_info* info,int file_len)
return false;
if (strcmp(line,"AUTHOR") == 0)
{
if (parse_text(info->author, p) == false )
if(read_asap_string(p,&buffer,&buffer_end,&id3->artist) == false)
return false;
}
else if(strcmp(line,"NAME")==0)
{
if (parse_text(info->name, p) == false)
if(read_asap_string(p,&buffer,&buffer_end,&id3->title) == false)
return false;
}
else if(strcmp(line,"DATE")==0)
{
if (parse_text(info->date, p) == false)
if(read_asap_string(p,&buffer,&buffer_end,&id3->year_string) == false)
return false;
}
else if (strcmp(line,"SONGS")==0)
{
if (parse_dec(&info->numSongs, p,1,MAX_SONGS) == false )
if (parse_dec(&numSongs, p,1,MAX_SONGS) == false )
return false;
}
else if (strcmp(line,"DEFSONG")==0)
{
if (parse_dec(&info->defSong, p,0,MAX_SONGS) == false)
if (parse_dec(&defSong, p,0,MAX_SONGS) == false)
return false;
}
else if (strcmp(line,"STEREO")==0)
{
info->numChannels = 2;
numChannels = 2;
}
else if (strcmp(line,"TIME") == 0)
{
int duration = ASAP_ParseDuration(p);
if (duration < 0 || duration_index >= MAX_SONGS)
int durationTemp = ASAP_ParseDuration(p);
if (durationTemp < 0 || duration_index >= MAX_SONGS)
return false;
info->durations[duration_index] = duration;
durations[duration_index] = durationTemp;
if (strstr(p, "LOOP") != NULL)
info->loops[duration_index] = 1;
loops[duration_index] = 1;
duration_index++;
}
}
/* set length: */
int length = durations[defSong];
if (length < 0)
length = 180 * 1000;
id3->length = length;
lseek(fd,0,SEEK_SET);
return true;
}
@ -226,26 +244,15 @@ static bool parse_sap_header(int fd,struct module_info* info,int file_len)
bool get_asap_metadata(int fd, struct mp3entry* id3)
{
char *buf = id3->id3v2buf;
int filelength = filesize(fd);
struct module_info *info;
info = (struct module_info *) (((intptr_t)buf + 3) & ~3); /* Align to 4 bytes */
if(parse_sap_header(fd,info,filelength) == false)
if(parse_sap_header(fd,id3,filelength) == false)
{
DEBUGF("parse sap header failed.\n");
return false;
}
id3->title = info->name;
id3->artist = info->author;
id3->year_string = info->date;
int length = info->durations[info->defSong];
if (length < 0)
length = 180 * 1000;
id3->length = length;
id3->bitrate = 706;
id3->frequency = 44100;