Mercurial > audlegacy
changeset 993:a9ac4beb4e15 trunk
[svn] Use taglib for length determination. Simpler code, might also deal better with some VBR MP3s if they have length info in their tags.
author | chainsaw |
---|---|
date | Sun, 30 Apr 2006 17:59:55 -0700 |
parents | 90c87c7aee9c |
children | 3d2984564cb8 |
files | Plugins/Input/mpg123/fileinfo.c Plugins/Input/mpg123/mpg123.c |
diffstat | 2 files changed, 26 insertions(+), 151 deletions(-) [+] |
line wrap: on
line diff
--- a/Plugins/Input/mpg123/fileinfo.c Sun Apr 30 17:00:48 2006 -0700 +++ b/Plugins/Input/mpg123/fileinfo.c Sun Apr 30 17:59:55 2006 -0700 @@ -50,11 +50,10 @@ *tracknum_entry, *comment_entry; static GtkWidget *genre_combo; static GtkWidget *mpeg_level, *mpeg_bitrate, *mpeg_samplerate, *mpeg_flags, - *mpeg_error, *mpeg_copy, *mpeg_orig, *mpeg_emph, *mpeg_frames, - *mpeg_filesize; + *mpeg_error, *mpeg_copy, *mpeg_orig, *mpeg_emph, *mpeg_filesize; static GtkWidget *mpeg_level_val, *mpeg_bitrate_val, *mpeg_samplerate_val, *mpeg_error_val, *mpeg_copy_val, *mpeg_orig_val, *mpeg_emph_val, - *mpeg_frames_val, *mpeg_filesize_val, *mpeg_flags_val; + *mpeg_filesize_val, *mpeg_flags_val; GtkWidget *vbox, *hbox, *left_vbox, *table; GtkWidget *mpeg_frame, *mpeg_box; @@ -357,19 +356,6 @@ gtk_table_attach(GTK_TABLE(test_table), mpeg_samplerate_val, 1, 2, 2, 3, GTK_FILL, GTK_FILL, 10, 2); - mpeg_frames = gtk_label_new(_("Frames:")); - gtk_misc_set_alignment(GTK_MISC(mpeg_frames), 1, 0.5); - gtk_label_set_justify(GTK_LABEL(mpeg_frames), GTK_JUSTIFY_RIGHT); - gtk_label_set_attributes(GTK_LABEL(mpeg_frames), attrs); - gtk_table_attach(GTK_TABLE(test_table), mpeg_frames, 0, 1, 3, 4, - GTK_FILL, GTK_FILL, 5, 2); - - mpeg_frames_val = gtk_label_new(""); - gtk_misc_set_alignment(GTK_MISC(mpeg_frames_val), 0, 0); - gtk_label_set_justify(GTK_LABEL(mpeg_frames_val), GTK_JUSTIFY_LEFT); - gtk_table_attach(GTK_TABLE(test_table), mpeg_frames_val, 1, 2, 3, - 4, GTK_FILL, GTK_FILL, 10, 2); - mpeg_filesize = gtk_label_new(_("File size:")); gtk_misc_set_alignment(GTK_MISC(mpeg_filesize), 1, 0.5); gtk_label_set_justify(GTK_LABEL(mpeg_filesize), GTK_JUSTIFY_RIGHT); @@ -673,9 +659,6 @@ gtk_label_set_text(GTK_LABEL(mpeg_emph), _("Emphasis:")); gtk_label_set_text(GTK_LABEL(mpeg_emph_val), _("N/A")); - gtk_label_set_text(GTK_LABEL(mpeg_frames), _("Frames:")); - gtk_label_set_text(GTK_LABEL(mpeg_frames_val), _("N/A")); - gtk_label_set_text(GTK_LABEL(mpeg_filesize), _("File size:")); gtk_label_set_text(GTK_LABEL(mpeg_filesize_val), _("N/A")); @@ -751,6 +734,16 @@ g_free(ptr); } + i = taglib_audioproperties_samplerate(taglib_ap); + + if (i != 0) + label_set_text(mpeg_samplerate_val, _("%ld Hz"), i); + + i = taglib_audioproperties_bitrate(taglib_ap); + + if (i != 0) + label_set_text(mpeg_bitrate_val, _("%d KBit/s"), i); + ptr = taglib_tag_genre(taglib_tag); if (ptr != NULL) @@ -768,7 +761,6 @@ guint32 head; guchar tmp[4]; struct frame frm; - gboolean id3_found = FALSE; if (vfs_fread(tmp, 1, 4, fh) != 4) { vfs_fclose(fh); @@ -787,41 +779,19 @@ } if (mpg123_decode_header(&frm, head)) { guchar *buf; - gdouble tpf; gint pos; - xing_header_t xing_header; - guint32 num_frames; buf = g_malloc(frm.framesize + 4); vfs_fseek(fh, -4, SEEK_CUR); vfs_fread(buf, 1, frm.framesize + 4, fh); - tpf = mpg123_compute_tpf(&frm); set_mpeg_level_label(frm.mpeg25, frm.lsf, frm.lay); pos = vfs_ftell(fh); vfs_fseek(fh, 0, SEEK_END); - if (mpg123_get_xing_header(&xing_header, buf)) { - num_frames = xing_header.frames; - label_set_text(mpeg_bitrate_val, - _("Variable,\navg. bitrate: %d KBit/s"), - (gint) ((xing_header.bytes * 8) / - (tpf * xing_header.frames * 1000))); - } - else { - num_frames = - ((vfs_ftell(fh) - pos - - (id3_found ? 128 : 0)) / mpg123_compute_bpf(&frm)) + 1; - label_set_text(mpeg_bitrate_val, _("%d KBit/s"), - tabsel_123[frm.lsf][frm.lay - - 1][frm.bitrate_index]); - } - label_set_text(mpeg_samplerate_val, _("%ld Hz"), - mpg123_freqs[frm.sampling_frequency]); label_set_text(mpeg_error_val, _("%s"), bool_label[frm.error_protection]); label_set_text(mpeg_copy_val, _("%s"), bool_label[frm.copyright]); label_set_text(mpeg_orig_val, _("%s"), bool_label[frm.original]); label_set_text(mpeg_emph_val, _("%s"), emphasis[frm.emphasis]); - label_set_text(mpeg_frames_val, _("%d"), num_frames); label_set_text(mpeg_filesize_val, _("%lu Bytes"), vfs_ftell(fh)); label_set_text(mpeg_flags_val, _("%s"), channel_mode_name(frm.mode)); g_free(buf); @@ -830,4 +800,3 @@ } } -
--- a/Plugins/Input/mpg123/mpg123.c Sun Apr 30 17:00:48 2006 -0700 +++ b/Plugins/Input/mpg123/mpg123.c Sun Apr 30 17:59:55 2006 -0700 @@ -263,13 +263,6 @@ g_strfreev(mpg123_id3_encoding_list); } -static guint32 -convert_to_header(guint8 * buf) -{ - return (buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + buf[3]; -} - - #if 0 #define DET_BUF_SIZE 1024 @@ -370,15 +363,6 @@ } } -static const char * -get_id3_genre(unsigned char genre_code) -{ - if (genre_code < GENRE_MAX) - return gettext(mpg123_id3_genres[genre_code]); - - return ""; -} - guint mpg123_strip_spaces(char *src, size_t n) { @@ -426,39 +410,6 @@ return ext; } -/* - * Function id3v1_to_id3v2 (v1, v2) - * - * Convert ID3v1 tag `v1' to ID3v2 tag `v2'. - * - */ -void -mpg123_id3v1_to_id3v2(struct id3v1tag_t *v1, struct id3tag_t *v2) -{ - memset(v2, 0, sizeof(struct id3tag_t)); - strncpy(v2->title, v1->title, 30); - strncpy(v2->artist, v1->artist, 30); - strncpy(v2->album, v1->album, 30); - strncpy(v2->comment, v1->u.v1_0.comment, 30); - strncpy(v2->genre, get_id3_genre(v1->genre), sizeof(v2->genre)); - g_strstrip(v2->title); - g_strstrip(v2->artist); - g_strstrip(v2->album); - g_strstrip(v2->comment); - g_strstrip(v2->genre); - { - char y[5]; - memcpy(y, v1->year, 4); y[4]=0; - v2->year = atoi(y); - } - - /* Check for v1.1 tags. */ - if (v1->u.v1_1.__zero == 0) - v2->track_number = v1->u.v1_1.track_number; - else - v2->track_number = 0; -} - #define REMOVE_NONEXISTANT_TAG(x) if (!*x) { x = NULL; } /* @@ -541,69 +492,27 @@ return ret; } -static long -get_song_length(VFSFile * file) +static guint +get_song_time(char *filename) { int len; - char tmp[4]; - vfs_fseek(file, 0, SEEK_END); - len = vfs_ftell(file); - vfs_fseek(file, -128, SEEK_END); - vfs_fread(tmp, 1, 3, file); - if (!strncmp(tmp, "TAG", 3)) - len -= 128; - return len; -} - - -static guint -get_song_time(VFSFile * file) -{ - guint32 head; - guchar tmp[4], *buf; - struct frame frm; - xing_header_t xing_header; - double tpf, bpf; - guint32 len; - - if (!file) - return -1; + taglib_file = taglib_file_new(filename); + if(taglib_file) { + taglib_ap = taglib_file_audioproperties(taglib_file); + } - vfs_fseek(file, 0, SEEK_SET); - if (vfs_fread(tmp, 1, 4, file) != 4) - return 0; - head = convert_to_header(tmp); - while (!mpg123_head_check(head)) { - head <<= 8; - if (vfs_fread(tmp, 1, 1, file) != 1) - return 0; - head |= tmp[0]; - } - if (mpg123_decode_header(&frm, head)) { - buf = g_malloc(frm.framesize + 4); - vfs_fseek(file, -4, SEEK_CUR); - vfs_fread(buf, 1, frm.framesize + 4, file); - tpf = mpg123_compute_tpf(&frm); - if (mpg123_get_xing_header(&xing_header, buf)) { - g_free(buf); - if (xing_header.bytes == 0) - xing_header.bytes = get_song_length(file); - return (tpf * xing_header.frames * 1000); - } - g_free(buf); - bpf = mpg123_compute_bpf(&frm); - len = get_song_length(file); - return ((guint) (len / bpf) * tpf * 1000); - } - return 0; + len = taglib_audioproperties_length(taglib_ap); + + taglib_file_free(taglib_file); + taglib_tag_free_strings(); + + return len; } static void get_song_info(char *filename, char **title_real, int *len_real) { - VFSFile *file; - (*len_real) = -1; (*title_real) = NULL; @@ -613,11 +522,8 @@ if (!strncasecmp(filename, "http://", 7)) return; - if ((file = vfs_fopen(filename, "rb")) != NULL) { - (*len_real) = get_song_time(file); - (*title_real) = get_song_title(filename); - vfs_fclose(file); - } + (*len_real) = get_song_time(filename); + (*title_real) = get_song_title(filename); } static int