1
/* XMMS - Cross-platform multimedia player
2
* Copyright (C) 1998-2000 Peter Alm, Mikael Alm, Olle Hallnas, Thomas Nilsson and 4Front Technologies
3
* Copyright (C) 1999,2000 H�vard Kv�len
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
* Note : removed code not used in EasyTAG
27
double mpg123_compute_tpf(struct frame *fr)
29
const int bs[4] = {0, 384, 1152, 1152};
33
tpf /= mpg123_freqs[fr->sampling_frequency] << (fr->lsf);
38
static guint32 convert_to_header(guint8 * buf)
41
return (buf[0] << 24) + (buf[1] << 16) + (buf[2] << 8) + buf[3];
45
#define DET_BUF_SIZE 1024
47
#if 0 /* Not used at the present time */
48
static gboolean mpg123_detect_by_content(gchar *filename)
54
guchar buf[DET_BUF_SIZE];
57
if((file = fopen(filename, "rb")) == NULL)
59
if (fread(tmp, 1, 4, file) != 4)
61
head = convert_to_header(tmp);
62
while(!mpg123_head_check(head))
65
* The mpeg-stream can start anywhere in the file,
66
* so we check the entire file
69
in_buf = fread(buf, 1, DET_BUF_SIZE, file);
73
for (i = 0; i < in_buf; i++)
77
if(mpg123_head_check(head))
79
fseek(file, i+1-in_buf, SEEK_CUR);
84
if (mpg123_decode_header(&fr, head))
87
* We found something which looks like a MPEG-header.
88
* We check the next frame too, to be sure
91
if (fseek(file, fr.framesize, SEEK_CUR) != 0)
93
if (fread(tmp, 1, 4, file) != 4)
95
head = convert_to_header(tmp);
96
if (mpg123_head_check(head) && mpg123_decode_header(&fr, head))
109
//static guint get_song_time(FILE * file)
110
guint mpg123_get_song_time(FILE * file)
115
XHEADDATA xing_header;
123
fseek(file, 0, SEEK_SET);
124
if (fread(tmp, 1, 4, file) != 4)
127
// Skip data of the ID3v2.x tag (patch from Artur Polaczynski)
128
if (tmp[0] == 'I' && tmp[1] == 'D' && tmp[2] == '3' && tmp[3] < 0xFF)
130
// id3v2 tag skipeer $49 44 33 yy yy xx zz zz zz zz [zz size]
131
fseek(file, 2, SEEK_CUR); // Size is 6-9 position
132
if (fread(tmp, 1, 4, file) != 4)
134
id3v2size = 10 + ( (long)(tmp[3]) | ((long)(tmp[2]) << 7) | ((long)(tmp[1]) << 14) | ((long)(tmp[0]) << 21) );
135
fseek(file, id3v2size, SEEK_SET);
136
if (fread(tmp, 1, 4, file) != 4) // Read mpeg header
140
head = convert_to_header(tmp);
141
while (!mpg123_head_check(head))
144
if (fread(tmp, 1, 1, file) != 1)
148
if (mpg123_decode_header(&frm, head))
150
buf = g_malloc(frm.framesize + 4);
151
fseek(file, -4, SEEK_CUR);
152
fread(buf, 1, frm.framesize + 4, file);
153
xing_header.toc = NULL;
154
tpf = mpg123_compute_tpf(&frm);
155
if (mpg123_get_xing_header(&xing_header, buf))
158
return ((guint) (tpf * xing_header.frames * 1000));
161
bpf = mpg123_compute_bpf(&frm);
162
fseek(file, 0, SEEK_END);
163
len = ftell(file) - id3v2size;
164
fseek(file, -128, SEEK_END);
165
fread(tmp, 1, 3, file);
166
if (!strncmp((gchar *)tmp, "TAG", 3))
168
return ((guint) ((guint)(len / bpf) * tpf * 1000));