From 5c2c991d148de6aafae4836f4e40edb453734d94 Mon Sep 17 00:00:00 2001 From: Miika Pekkarinen Date: Tue, 5 Jul 2005 19:55:40 +0000 Subject: [PATCH] Applied patch "[ 1232957 ] MP3 metadata fixes for software codec". Thanks to Magnus Holmgren. Now metadata reading is better with improved performance for mp3 files. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7030 a1c6a512-1295-4272-9138-f99709370657 --- apps/codecs.c | 1 - apps/codecs.h | 1 - apps/codecs/mpa.c | 17 +++++++---------- apps/metadata.c | 5 ----- apps/playback.c | 3 --- apps/playback.h | 3 +-- firmware/export/id3.h | 5 +++++ firmware/id3.c | 5 +++++ firmware/mp3data.c | 2 +- 9 files changed, 19 insertions(+), 23 deletions(-) diff --git a/apps/codecs.c b/apps/codecs.c index 8b4f9b5f32..d3a9d9e9c1 100644 --- a/apps/codecs.c +++ b/apps/codecs.c @@ -74,7 +74,6 @@ struct codec_api ci = { 0, /* filesize */ 0, /* curpos */ NULL, /* id3 */ - NULL, /* mp3data */ NULL, /* taginfo_ready */ false, /* stop_codec */ false, /* reload_codec */ diff --git a/apps/codecs.h b/apps/codecs.h index 5878ca9185..ea5972968f 100644 --- a/apps/codecs.h +++ b/apps/codecs.h @@ -121,7 +121,6 @@ struct codec_api { /* For gapless mp3 */ struct mp3entry *id3; /* TAG metadata pointer */ - struct mp3info *mp3data; /* MP3 metadata pointer */ bool *taginfo_ready; /* Is metadata read */ /* Codec should periodically check if stop_codec is set to true. diff --git a/apps/codecs/mpa.c b/apps/codecs/mpa.c index df78b07247..5cf4eb8730 100644 --- a/apps/codecs/mpa.c +++ b/apps/codecs/mpa.c @@ -23,7 +23,6 @@ #include "playback.h" #include "dsp.h" -#include "mp3data.h" #include "lib/codeclib.h" struct mad_stream Stream IDATA_ATTR; @@ -61,7 +60,6 @@ extern char iramend[]; enum codec_status codec_start(struct codec_api* api) { struct codec_api *ci = api; - struct mp3info *info; int Status = 0; size_t size; int file_end; @@ -115,7 +113,6 @@ enum codec_status codec_start(struct codec_api* api) for gapless playback */ next_track: - info = ci->mp3data; first_frame = false; file_end = 0; OutputPtr = OutputBuffer; @@ -128,24 +125,24 @@ enum codec_status codec_start(struct codec_api* api) ci->request_buffer(&size, ci->id3->first_frame_offset); ci->advance_buffer(size); - - if (info->enc_delay >= 0 && info->enc_padding >= 0) { - stop_skip = info->enc_padding - mpeg_latency[info->layer]; + + if (ci->id3->lead_trim >= 0 && ci->id3->tail_trim >= 0) { + stop_skip = ci->id3->tail_trim - mpeg_latency[ci->id3->layer]; if (stop_skip < 0) stop_skip = 0; - start_skip = info->enc_delay + mpeg_latency[info->layer]; + start_skip = ci->id3->lead_trim + mpeg_latency[ci->id3->layer]; } else { stop_skip = 0; /* We want to skip this amount anyway */ - start_skip = mpeg_latency[info->layer]; + start_skip = mpeg_latency[ci->id3->layer]; } /* NOTE: currently this doesn't work, the below calculated samples_count seems to be right, but sometimes libmad just can't supply us with all the data we need... */ - if (info->frame_count) { + if (ci->id3->frame_count) { /* TODO: 1152 is the frame size in samples for MPEG1 layer 2 and layer 3, it's probably not correct at all for MPEG2 and layer 1 */ - samplecount = info->frame_count*1152 - (start_skip + stop_skip); + samplecount = ci->id3->frame_count*1152 - (start_skip + stop_skip); samplesdone = ci->id3->elapsed * frequency_divider / 10; } else { samplecount = ci->id3->length * frequency_divider / 10; diff --git a/apps/metadata.c b/apps/metadata.c index 6ba2331d26..0e770dde7a 100644 --- a/apps/metadata.c +++ b/apps/metadata.c @@ -23,7 +23,6 @@ #include "metadata.h" #include "mp3_playback.h" -#include "mp3data.h" #include "logf.h" #include "atoi.h" @@ -113,10 +112,6 @@ bool get_metadata(struct track_info* track, int fd, const char* trackname, mp3info(&track->id3, trackname, v1first); lseek(fd, 0, SEEK_SET); - /* This is too slow to execute on some files. */ - get_mp3file_info(fd, &track->mp3data); - lseek(fd, 0, SEEK_SET); - /* logf("T:%s", track->id3.title); logf("L:%d", track->id3.length); diff --git a/apps/playback.c b/apps/playback.c index 8186cf3191..11ef7d7a04 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -39,7 +39,6 @@ #include "audio.h" #include "logf.h" #include "mp3_playback.h" -#include "mp3data.h" #include "usb.h" #include "status.h" #include "main_menu.h" @@ -738,7 +737,6 @@ bool loadcodec(const char *trackname, bool start_play) cur_ti = &tracks[track_widx]; ci.filesize = cur_ti->filesize; ci.id3 = (struct mp3entry *)&cur_ti->id3; - ci.mp3data = (struct mp3info *)&cur_ti->mp3data; ci.taginfo_ready = (bool *)&cur_ti->taginfo_ready; ci.curpos = 0; playing = true; @@ -1179,7 +1177,6 @@ void audio_update_trackinfo(void) cur_ti->id3.elapsed = 0; cur_ti->id3.offset = 0; ci.id3 = (struct mp3entry *)&cur_ti->id3; - ci.mp3data = (struct mp3info *)&cur_ti->mp3data; ci.curpos = 0; cur_ti->start_pos = 0; ci.taginfo_ready = (bool *)&cur_ti->taginfo_ready; diff --git a/apps/playback.h b/apps/playback.h index 48d533f138..cb006f9e52 100644 --- a/apps/playback.h +++ b/apps/playback.h @@ -44,10 +44,9 @@ enum { /* Not yet implemented. */ #define CODEC_SET_AUDIOBUF_WATERMARK 4 -#define MAX_TRACK 10 +#define MAX_TRACK 32 struct track_info { struct mp3entry id3; /* TAG metadata */ - struct mp3info mp3data; /* MP3 metadata */ char *codecbuf; /* Pointer to codec buffer */ long codecsize; /* Codec length in bytes */ diff --git a/firmware/export/id3.h b/firmware/export/id3.h index 8f904e49e6..7970f529f1 100644 --- a/firmware/export/id3.h +++ b/firmware/export/id3.h @@ -19,6 +19,7 @@ #ifndef ID3_H #define ID3_H +#include #include "config.h" #include "file.h" @@ -78,12 +79,16 @@ struct mp3entry { unsigned int length; /* song length */ unsigned int elapsed; /* ms played */ + int lead_trim; /* Number of samples to skip at the beginning */ + int tail_trim; /* Number of samples to remove from the end */ + /* Added for Vorbis */ unsigned long samples; /* number of samples in track */ /* MP3 stream specific info */ long bpf; /* bytes per frame */ long tpf; /* time per frame */ + long frame_count; /* number of frames in the file (if VBR) */ /* Xing VBR fields */ bool vbr; diff --git a/firmware/id3.c b/firmware/id3.c index 6a13de4e29..4fe9fa0a40 100644 --- a/firmware/id3.c +++ b/firmware/id3.c @@ -832,9 +832,14 @@ static int getsonglength(int fd, struct mp3entry *entry) entry->tpf = info.frame_time; entry->bpf = info.frame_size; + entry->frame_count = info.frame_count; entry->vbr = info.is_vbr; entry->has_toc = info.has_toc; + + entry->lead_trim = info.enc_delay; + entry->tail_trim = info.enc_padding; + memcpy(entry->toc, info.toc, sizeof(info.toc)); entry->vbr_header_pos = info.vbr_header_pos; diff --git a/firmware/mp3data.c b/firmware/mp3data.c index e899125013..087bcf5030 100644 --- a/firmware/mp3data.c +++ b/firmware/mp3data.c @@ -266,7 +266,7 @@ static int fileread(int fd, unsigned char *c) #if defined(IRIVER_H100) && !defined(SIMULATOR) /* We don't want to eat all cpu power. Maybe better way to do this should be implemented. */ - while (pcm_is_lowdata()) + if (pcm_is_lowdata()) yield(); #endif