2002-04-23 08:43:04 +00:00
|
|
|
|
/***************************************************************************
|
|
|
|
|
* __________ __ ___.
|
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2002 by Daniel Stenberg
|
|
|
|
|
*
|
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
|
*
|
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
|
* KIND, either express or implied.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Parts of this code has been stolen from the Ample project and was written
|
2002-08-19 14:15:33 +00:00
|
|
|
|
* by David H<EFBFBD>rdeman. It has since been extended and enhanced pretty much by
|
|
|
|
|
* all sorts of friendly Rockbox people.
|
|
|
|
|
*
|
|
|
|
|
* A nice reference for MPEG header info:
|
|
|
|
|
* http://rockbox.haxx.se/docs/mpeghdr.html
|
|
|
|
|
*
|
2002-04-23 08:43:04 +00:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <errno.h>
|
2002-05-13 12:29:34 +00:00
|
|
|
|
#include <stdbool.h>
|
2002-05-08 15:36:18 +00:00
|
|
|
|
#include "file.h"
|
2002-06-26 14:51:09 +00:00
|
|
|
|
#include "debug.h"
|
2002-06-26 21:11:29 +00:00
|
|
|
|
#include "atoi.h"
|
2002-04-30 12:42:37 +00:00
|
|
|
|
|
2002-05-05 10:32:20 +00:00
|
|
|
|
#include "id3.h"
|
2002-04-23 08:43:04 +00:00
|
|
|
|
|
2002-10-01 13:20:23 +00:00
|
|
|
|
#define UNSYNC(b0,b1,b2,b3) (((b0 & 0x7F) << (3*7)) | \
|
|
|
|
|
((b1 & 0x7F) << (2*7)) | \
|
|
|
|
|
((b2 & 0x7F) << (1*7)) | \
|
|
|
|
|
((b3 & 0x7F) << (0*7)))
|
|
|
|
|
|
|
|
|
|
#define BYTES2INT(b0,b1,b2,b3) (((b0 & 0xFF) << (3*8)) | \
|
|
|
|
|
((b1 & 0xFF) << (2*8)) | \
|
|
|
|
|
((b2 & 0xFF) << (1*8)) | \
|
|
|
|
|
((b3 & 0xFF) << (0*8)))
|
2002-09-30 18:41:59 +00:00
|
|
|
|
|
2002-04-23 08:43:04 +00:00
|
|
|
|
/* Table of bitrates for MP3 files, all values in kilo.
|
|
|
|
|
* Indexed by version, layer and value of bit 15-12 in header.
|
|
|
|
|
*/
|
|
|
|
|
const int bitrate_table[2][3][16] =
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
{0,32,64,96,128,160,192,224,256,288,320,352,384,416,448,0},
|
|
|
|
|
{0,32,48,56, 64,80, 96, 112,128,160,192,224,256,320,384,0},
|
|
|
|
|
{0,32,40,48, 56,64, 80, 96, 112,128,160,192,224,256,320,0}
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
{0,32,48,56,64,80,96,112,128,144,160,176,192,224,256,0},
|
|
|
|
|
{0, 8,16,24,32,40,48, 56, 64, 80, 96,112,128,144,160,0},
|
|
|
|
|
{0, 8,16,24,32,40,48, 56, 64, 80, 96,112,128,144,160,0}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Table of samples per frame for MP3 files.
|
|
|
|
|
* Indexed by layer. Multiplied with 1000.
|
|
|
|
|
*/
|
|
|
|
|
const int bs[4] = {0, 384000, 1152000, 1152000};
|
|
|
|
|
|
|
|
|
|
/* Table of sample frequency for MP3 files.
|
|
|
|
|
* Indexed by version and layer.
|
|
|
|
|
*/
|
2002-08-19 14:15:33 +00:00
|
|
|
|
const int freqtab[][4] =
|
2002-04-23 08:43:04 +00:00
|
|
|
|
{
|
2002-08-19 14:15:33 +00:00
|
|
|
|
{11025, 12000, 8000, 0}, /* MPEG version 2.5 */
|
|
|
|
|
{44100, 48000, 32000, 0}, /* MPEG Version 1 */
|
|
|
|
|
{22050, 24000, 16000, 0}, /* MPEG version 2 */
|
2002-04-23 08:43:04 +00:00
|
|
|
|
};
|
|
|
|
|
|
2002-09-30 18:45:50 +00:00
|
|
|
|
/* Checks to see if the passed in string is a 16-bit wide Unicode v2
|
|
|
|
|
string. If it is, we attempt to convert it to a 8-bit ASCII string
|
|
|
|
|
(for valid 8-bit ASCII characters). If it's not unicode, we leave
|
|
|
|
|
it alone. At some point we should fully support unicode strings */
|
2002-10-01 13:20:23 +00:00
|
|
|
|
static int unicode_munge(char** string, int *len) {
|
|
|
|
|
int tmp;
|
|
|
|
|
bool le = false;
|
|
|
|
|
int i;
|
|
|
|
|
char *str = *string;
|
|
|
|
|
char *outstr = *string;
|
|
|
|
|
|
|
|
|
|
if(str[0] > 0x03) {
|
|
|
|
|
/* Plain old string */
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Type 0x00 is ordinary ISO 8859-1 */
|
|
|
|
|
if(str[0] == 0x00) {
|
2002-10-01 14:36:37 +00:00
|
|
|
|
(*len)--;
|
|
|
|
|
(*string)++; /* Skip the encoding type byte */
|
2002-10-01 13:20:23 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Unicode with or without BOM */
|
|
|
|
|
if(str[0] == 0x01 || str[0] == 0x02) {
|
|
|
|
|
str++;
|
2002-11-12 22:35:32 +00:00
|
|
|
|
tmp = BYTES2INT(0, 0, str[0], str[1]);
|
2002-10-01 13:20:23 +00:00
|
|
|
|
|
2002-11-12 22:35:32 +00:00
|
|
|
|
/* Now check if there is a BOM (zero-width non-breaking space, 0xfeff)
|
|
|
|
|
and if it is in little or big endian format */
|
|
|
|
|
if(tmp == 0xfffe) { /* Little endian? */
|
2002-10-01 13:20:23 +00:00
|
|
|
|
le = true;
|
|
|
|
|
str += 2;
|
|
|
|
|
}
|
|
|
|
|
|
2002-11-12 22:35:32 +00:00
|
|
|
|
if(tmp == 0xfeff) /* Big endian? */
|
2002-10-01 13:20:23 +00:00
|
|
|
|
str += 2;
|
|
|
|
|
|
|
|
|
|
i = 0;
|
2002-09-30 18:45:50 +00:00
|
|
|
|
|
|
|
|
|
do {
|
2002-10-01 13:20:23 +00:00
|
|
|
|
if(le) {
|
|
|
|
|
if(str[1])
|
|
|
|
|
outstr[i++] = '.';
|
|
|
|
|
else
|
|
|
|
|
outstr[i++] = str[0];
|
|
|
|
|
} else {
|
|
|
|
|
if(str[0])
|
|
|
|
|
outstr[i++] = '.';
|
|
|
|
|
else
|
|
|
|
|
outstr[i++] = str[1];
|
2002-09-30 18:45:50 +00:00
|
|
|
|
}
|
2002-11-12 22:35:32 +00:00
|
|
|
|
str += 2;
|
2002-10-01 13:20:23 +00:00
|
|
|
|
} while(str[0] || str[1]);
|
|
|
|
|
|
|
|
|
|
*len = i;
|
|
|
|
|
return 0;
|
2002-09-30 18:45:50 +00:00
|
|
|
|
}
|
2002-10-01 13:20:23 +00:00
|
|
|
|
|
|
|
|
|
/* If we come here, the string was of an unsupported type */
|
|
|
|
|
*len = 1;
|
|
|
|
|
outstr[0] = 0;
|
|
|
|
|
return -1;
|
2002-09-30 18:45:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-04-23 08:43:04 +00:00
|
|
|
|
/*
|
|
|
|
|
* Removes trailing spaces from a string.
|
|
|
|
|
*
|
|
|
|
|
* Arguments: buffer - the string to process
|
|
|
|
|
*
|
|
|
|
|
* Returns: void
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
stripspaces(char *buffer)
|
|
|
|
|
{
|
|
|
|
|
int i = 0;
|
|
|
|
|
while(*(buffer + i) != '\0')
|
|
|
|
|
i++;
|
2002-07-04 22:10:43 +00:00
|
|
|
|
|
2002-04-23 08:43:04 +00:00
|
|
|
|
for(;i >= 0; i--) {
|
|
|
|
|
if(*(buffer + i) == ' ')
|
|
|
|
|
*(buffer + i) = '\0';
|
|
|
|
|
else if(*(buffer + i) == '\0')
|
|
|
|
|
continue;
|
|
|
|
|
else
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Sets the title of an MP3 entry based on its ID3v1 tag.
|
|
|
|
|
*
|
|
|
|
|
* Arguments: file - the MP3 file to scen for a ID3v1 tag
|
|
|
|
|
* entry - the entry to set the title in
|
|
|
|
|
*
|
2002-05-13 12:29:34 +00:00
|
|
|
|
* Returns: true if a title was found and created, else false
|
2002-04-23 08:43:04 +00:00
|
|
|
|
*/
|
2002-07-04 22:10:43 +00:00
|
|
|
|
static bool setid3v1title(int fd, struct mp3entry *entry)
|
2002-04-23 08:43:04 +00:00
|
|
|
|
{
|
2002-09-09 22:31:11 +00:00
|
|
|
|
unsigned char buffer[31];
|
|
|
|
|
int offsets[4] = {-95,-65,-125,-31};
|
2002-04-23 08:43:04 +00:00
|
|
|
|
int i;
|
|
|
|
|
|
2002-09-09 22:31:11 +00:00
|
|
|
|
for (i=0;i<4;i++) {
|
|
|
|
|
if (-1 == lseek(fd, offsets[i], SEEK_END))
|
2002-05-13 12:29:34 +00:00
|
|
|
|
return false;
|
2002-04-23 08:43:04 +00:00
|
|
|
|
|
2002-05-06 15:21:43 +00:00
|
|
|
|
buffer[30]=0;
|
|
|
|
|
read(fd, buffer, 30);
|
2002-04-23 08:43:04 +00:00
|
|
|
|
stripspaces(buffer);
|
|
|
|
|
|
2002-09-09 22:31:11 +00:00
|
|
|
|
if (buffer[0] || i == 3) {
|
2002-04-23 08:43:04 +00:00
|
|
|
|
switch(i) {
|
2002-09-09 22:31:11 +00:00
|
|
|
|
case 0:
|
|
|
|
|
strcpy(entry->id3v1buf[0], buffer);
|
|
|
|
|
entry->artist = entry->id3v1buf[0];
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
strcpy(entry->id3v1buf[1], buffer);
|
|
|
|
|
entry->album = entry->id3v1buf[1];
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
strcpy(entry->id3v1buf[2], buffer);
|
|
|
|
|
entry->title = entry->id3v1buf[2];
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
/* id3v1.1 uses last two bytes of comment field for track
|
|
|
|
|
number: first must be 0 and second is track num */
|
|
|
|
|
if (buffer[28] == 0)
|
|
|
|
|
entry->tracknum = buffer[29];
|
|
|
|
|
break;
|
2002-04-23 08:43:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-13 12:29:34 +00:00
|
|
|
|
return true;
|
2002-04-23 08:43:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Sets the title of an MP3 entry based on its ID3v2 tag.
|
|
|
|
|
*
|
2002-10-29 10:29:57 +00:00
|
|
|
|
* Arguments: file - the MP3 file to scan for a ID3v2 tag
|
2002-04-23 08:43:04 +00:00
|
|
|
|
* entry - the entry to set the title in
|
|
|
|
|
*
|
2002-05-13 12:29:34 +00:00
|
|
|
|
* Returns: true if a title was found and created, else false
|
2002-04-23 08:43:04 +00:00
|
|
|
|
*/
|
2002-07-04 22:10:43 +00:00
|
|
|
|
static void setid3v2title(int fd, struct mp3entry *entry)
|
2002-04-23 08:43:04 +00:00
|
|
|
|
{
|
2002-08-30 22:01:35 +00:00
|
|
|
|
int minframesize;
|
2002-04-30 12:42:37 +00:00
|
|
|
|
int size;
|
2002-10-28 23:00:57 +00:00
|
|
|
|
int bufferpos = 0, totframelen, framelen;
|
2002-04-23 08:43:04 +00:00
|
|
|
|
char header[10];
|
|
|
|
|
unsigned short int version;
|
2002-06-04 22:05:00 +00:00
|
|
|
|
char *buffer = entry->id3v2buf;
|
2002-10-28 23:00:57 +00:00
|
|
|
|
char *tracknum = NULL;
|
|
|
|
|
int bytesread = 0;
|
|
|
|
|
int buffersize = sizeof(entry->id3v2buf);
|
2002-04-23 08:43:04 +00:00
|
|
|
|
|
2002-10-28 23:00:57 +00:00
|
|
|
|
/* Bail out if the tag is shorter than 10 bytes */
|
2002-04-23 08:43:04 +00:00
|
|
|
|
if(entry->id3v2len < 10)
|
|
|
|
|
return;
|
|
|
|
|
|
2002-10-28 23:00:57 +00:00
|
|
|
|
/* Read the ID3 tag version from the header */
|
2002-04-30 12:42:37 +00:00
|
|
|
|
lseek(fd, 0, SEEK_SET);
|
2002-05-08 07:10:16 +00:00
|
|
|
|
if(10 != read(fd, header, 10))
|
|
|
|
|
return;
|
|
|
|
|
|
2002-04-23 08:43:04 +00:00
|
|
|
|
version = (unsigned short int)header[3];
|
2002-08-30 22:01:35 +00:00
|
|
|
|
|
2002-10-28 23:00:57 +00:00
|
|
|
|
/* Get the total ID3 tag size */
|
2002-04-23 08:43:04 +00:00
|
|
|
|
size = entry->id3v2len - 10;
|
2002-04-23 11:46:16 +00:00
|
|
|
|
|
2002-08-30 22:01:35 +00:00
|
|
|
|
/* Set minimum frame size according to ID3v2 version */
|
2002-04-23 08:43:04 +00:00
|
|
|
|
if(version > 2)
|
|
|
|
|
minframesize = 12;
|
|
|
|
|
else
|
|
|
|
|
minframesize = 8;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* We must have at least minframesize bytes left for the
|
|
|
|
|
* remaining frames to be interesting
|
|
|
|
|
*/
|
2002-10-28 23:00:57 +00:00
|
|
|
|
while(size > minframesize) {
|
2002-04-23 08:43:04 +00:00
|
|
|
|
/* Read frame header and check length */
|
|
|
|
|
if(version > 2) {
|
2002-10-28 23:00:57 +00:00
|
|
|
|
if(10 != read(fd, header, 10))
|
|
|
|
|
return;
|
|
|
|
|
/* Adjust for the 10 bytes we read */
|
|
|
|
|
size -= 10;
|
|
|
|
|
|
2002-09-30 18:41:59 +00:00
|
|
|
|
if (version > 3) {
|
2002-10-28 23:00:57 +00:00
|
|
|
|
framelen = UNSYNC(header[4], header[5],
|
|
|
|
|
header[6], header[7]);
|
2002-09-30 18:41:59 +00:00
|
|
|
|
} else {
|
|
|
|
|
/* version .3 files don't use synchsafe ints for
|
|
|
|
|
* size */
|
2002-10-28 23:00:57 +00:00
|
|
|
|
framelen = BYTES2INT(header[4], header[5],
|
|
|
|
|
header[6], header[7]);
|
2002-09-30 18:41:59 +00:00
|
|
|
|
}
|
2002-04-23 08:43:04 +00:00
|
|
|
|
} else {
|
2002-10-28 23:00:57 +00:00
|
|
|
|
if(6 != read(fd, header, 6))
|
|
|
|
|
return;
|
|
|
|
|
/* Adjust for the 6 bytes we read */
|
|
|
|
|
size -= 6;
|
|
|
|
|
|
|
|
|
|
framelen = BYTES2INT(0, header[3], header[4], header[5]);
|
2002-04-23 08:43:04 +00:00
|
|
|
|
}
|
2002-08-30 22:01:35 +00:00
|
|
|
|
|
2002-10-28 23:00:57 +00:00
|
|
|
|
/* Keep track of the total size */
|
2002-10-29 10:29:57 +00:00
|
|
|
|
totframelen = framelen;
|
2002-10-28 23:00:57 +00:00
|
|
|
|
|
|
|
|
|
if(framelen == 0)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* If the frame is larger than the remaining buffer space we try
|
|
|
|
|
to read as much as would fit in the buffer */
|
|
|
|
|
if(framelen >= buffersize - bufferpos)
|
|
|
|
|
framelen = buffersize - bufferpos - 1;
|
2002-10-29 10:29:57 +00:00
|
|
|
|
|
2002-04-23 08:43:04 +00:00
|
|
|
|
/* Check for certain frame headers */
|
|
|
|
|
if(!strncmp(header, "TPE1", strlen("TPE1")) ||
|
|
|
|
|
!strncmp(header, "TP1", strlen("TP1"))) {
|
2002-10-28 23:00:57 +00:00
|
|
|
|
bytesread = read(fd, buffer + bufferpos, framelen);
|
|
|
|
|
entry->artist = buffer + bufferpos;
|
|
|
|
|
unicode_munge(&entry->artist, &bytesread);
|
|
|
|
|
entry->artist[bytesread + 1] = '\0';
|
|
|
|
|
bufferpos += bytesread + 2;
|
|
|
|
|
size -= bytesread;
|
2002-04-23 08:43:04 +00:00
|
|
|
|
}
|
|
|
|
|
else if(!strncmp(header, "TIT2", strlen("TIT2")) ||
|
|
|
|
|
!strncmp(header, "TT2", strlen("TT2"))) {
|
2002-10-28 23:00:57 +00:00
|
|
|
|
bytesread = read(fd, buffer + bufferpos, framelen);
|
|
|
|
|
entry->title = buffer + bufferpos;
|
|
|
|
|
unicode_munge(&entry->title, &bytesread);
|
|
|
|
|
entry->title[bytesread + 1] = '\0';
|
|
|
|
|
bufferpos += bytesread + 2;
|
|
|
|
|
size -= bytesread;
|
2002-04-23 08:43:04 +00:00
|
|
|
|
}
|
|
|
|
|
else if(!strncmp(header, "TALB", strlen("TALB"))) {
|
2002-10-28 23:00:57 +00:00
|
|
|
|
bytesread = read(fd, buffer + bufferpos, framelen);
|
|
|
|
|
entry->album = buffer + bufferpos;
|
|
|
|
|
unicode_munge(&entry->album, &bytesread);
|
|
|
|
|
entry->album[bytesread + 1] = '\0';
|
|
|
|
|
bufferpos += bytesread + 2;
|
|
|
|
|
size -= bytesread;
|
2002-04-23 08:43:04 +00:00
|
|
|
|
}
|
2002-06-26 21:11:29 +00:00
|
|
|
|
else if(!strncmp(header, "TRCK", strlen("TRCK"))) {
|
2002-10-28 23:00:57 +00:00
|
|
|
|
bytesread = read(fd, buffer + bufferpos, framelen);
|
|
|
|
|
tracknum = buffer + bufferpos;
|
|
|
|
|
unicode_munge(&tracknum, &bytesread);
|
|
|
|
|
tracknum[bytesread + 1] = '\0';
|
|
|
|
|
entry->tracknum = atoi(tracknum);
|
|
|
|
|
bufferpos += bytesread + 1;
|
|
|
|
|
size -= bytesread;
|
2002-06-26 21:11:29 +00:00
|
|
|
|
}
|
2002-10-29 10:29:57 +00:00
|
|
|
|
else {
|
|
|
|
|
/* Unknown frame, skip it using the total size in case
|
|
|
|
|
it was truncated */
|
|
|
|
|
size -= totframelen;
|
|
|
|
|
lseek(fd, totframelen, SEEK_CUR);
|
|
|
|
|
}
|
2002-06-26 21:11:29 +00:00
|
|
|
|
}
|
2002-04-23 08:43:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Calculates the size of the ID3v2 tag.
|
|
|
|
|
*
|
|
|
|
|
* Arguments: file - the file to search for a tag.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the size of the tag or 0 if none was found
|
|
|
|
|
*/
|
2002-07-04 22:10:43 +00:00
|
|
|
|
static int getid3v2len(int fd)
|
2002-04-23 08:43:04 +00:00
|
|
|
|
{
|
|
|
|
|
char buf[6];
|
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
|
|
/* Make sure file has a ID3 tag */
|
2002-04-30 12:42:37 +00:00
|
|
|
|
if((-1 == lseek(fd, 0, SEEK_SET)) ||
|
|
|
|
|
(read(fd, buf, 6) != 6) ||
|
2002-04-23 08:43:04 +00:00
|
|
|
|
(strncmp(buf, "ID3", strlen("ID3")) != 0))
|
|
|
|
|
offset = 0;
|
2002-07-04 22:10:43 +00:00
|
|
|
|
|
2002-04-23 08:43:04 +00:00
|
|
|
|
/* Now check what the ID3v2 size field says */
|
2002-04-30 12:42:37 +00:00
|
|
|
|
else if(read(fd, buf, 4) != 4)
|
2002-04-23 08:43:04 +00:00
|
|
|
|
offset = 0;
|
|
|
|
|
else
|
|
|
|
|
offset = UNSYNC(buf[0], buf[1], buf[2], buf[3]) + 10;
|
2002-07-04 22:10:43 +00:00
|
|
|
|
|
2002-04-23 08:43:04 +00:00
|
|
|
|
return offset;
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-04 22:10:43 +00:00
|
|
|
|
static int getfilesize(int fd)
|
2002-04-23 08:43:04 +00:00
|
|
|
|
{
|
2002-04-30 12:42:37 +00:00
|
|
|
|
int size;
|
|
|
|
|
|
2002-04-23 08:43:04 +00:00
|
|
|
|
/* seek to the end of it */
|
2002-04-30 12:42:37 +00:00
|
|
|
|
size = lseek(fd, 0, SEEK_END);
|
|
|
|
|
if(-1 == size)
|
2002-04-23 08:43:04 +00:00
|
|
|
|
return 0; /* unknown */
|
|
|
|
|
|
2002-04-30 12:42:37 +00:00
|
|
|
|
return size;
|
2002-04-23 08:43:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Calculates the size of the ID3v1 tag.
|
|
|
|
|
*
|
|
|
|
|
* Arguments: file - the file to search for a tag.
|
|
|
|
|
*
|
|
|
|
|
* Returns: the size of the tag or 0 if none was found
|
|
|
|
|
*/
|
2002-07-04 22:10:43 +00:00
|
|
|
|
static int getid3v1len(int fd)
|
2002-04-23 08:43:04 +00:00
|
|
|
|
{
|
|
|
|
|
char buf[3];
|
|
|
|
|
int offset;
|
|
|
|
|
|
|
|
|
|
/* Check if we find "TAG" 128 bytes from EOF */
|
2002-05-05 13:25:29 +00:00
|
|
|
|
if((lseek(fd, -128, SEEK_END) == -1) ||
|
2002-04-30 12:42:37 +00:00
|
|
|
|
(read(fd, buf, 3) != 3) ||
|
2002-04-23 08:43:04 +00:00
|
|
|
|
(strncmp(buf, "TAG", 3) != 0))
|
|
|
|
|
offset = 0;
|
|
|
|
|
else
|
|
|
|
|
offset = 128;
|
|
|
|
|
|
|
|
|
|
return offset;
|
|
|
|
|
}
|
|
|
|
|
|
2002-07-18 15:21:45 +00:00
|
|
|
|
/* check if 'head' is a valid mp3 frame header */
|
|
|
|
|
static bool mp3frameheader(unsigned long head)
|
|
|
|
|
{
|
|
|
|
|
if ((head & 0xffe00000) != 0xffe00000) /* bad sync? */
|
|
|
|
|
return false;
|
|
|
|
|
if (!((head >> 17) & 3)) /* no layer? */
|
|
|
|
|
return false;
|
|
|
|
|
if (((head >> 12) & 0xf) == 0xf) /* bad bitrate? */
|
|
|
|
|
return false;
|
|
|
|
|
if (!((head >> 12) & 0xf)) /* no bitrate? */
|
|
|
|
|
return false;
|
|
|
|
|
if (((head >> 10) & 0x3) == 0x3) /* bad sample rate? */
|
|
|
|
|
return false;
|
|
|
|
|
if (((head >> 19) & 1) == 1 &&
|
|
|
|
|
((head >> 17) & 3) == 3 &&
|
|
|
|
|
((head >> 16) & 1) == 1)
|
|
|
|
|
return false;
|
|
|
|
|
if ((head & 0xffff0000) == 0xfffe0000)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2002-04-23 08:43:04 +00:00
|
|
|
|
/*
|
2002-08-19 14:15:33 +00:00
|
|
|
|
* Calculates the length (in milliseconds) of an MP3 file.
|
2002-04-23 08:43:04 +00:00
|
|
|
|
*
|
|
|
|
|
* Modified to only use integers.
|
|
|
|
|
*
|
|
|
|
|
* Arguments: file - the file to calculate the length upon
|
|
|
|
|
* entry - the entry to update with the length
|
|
|
|
|
*
|
|
|
|
|
* Returns: the song length in milliseconds,
|
2002-08-22 07:59:31 +00:00
|
|
|
|
* 0 means that it couldn't be calculated
|
2002-04-23 08:43:04 +00:00
|
|
|
|
*/
|
2002-07-04 22:10:43 +00:00
|
|
|
|
static int getsonglength(int fd, struct mp3entry *entry)
|
2002-04-23 08:43:04 +00:00
|
|
|
|
{
|
2002-07-03 21:04:09 +00:00
|
|
|
|
unsigned int filetime = 0;
|
2002-05-27 14:03:17 +00:00
|
|
|
|
unsigned long header=0;
|
|
|
|
|
unsigned char tmp;
|
2002-08-14 19:23:34 +00:00
|
|
|
|
unsigned char frame[156];
|
2002-07-18 02:08:23 +00:00
|
|
|
|
unsigned char* xing;
|
2002-07-03 21:04:09 +00:00
|
|
|
|
|
2002-08-19 14:15:33 +00:00
|
|
|
|
enum {
|
|
|
|
|
MPEG_VERSION2_5,
|
|
|
|
|
MPEG_VERSION1,
|
|
|
|
|
MPEG_VERSION2
|
|
|
|
|
} version;
|
2002-04-23 08:43:04 +00:00
|
|
|
|
int layer;
|
|
|
|
|
int bitindex;
|
|
|
|
|
int bitrate;
|
|
|
|
|
int freqindex;
|
|
|
|
|
int frequency;
|
2002-07-18 02:08:23 +00:00
|
|
|
|
int chmode;
|
2002-07-22 16:05:46 +00:00
|
|
|
|
int bytecount;
|
2002-09-25 12:34:21 +00:00
|
|
|
|
int bytelimit;
|
2002-08-19 14:15:33 +00:00
|
|
|
|
int bittable; /* which bitrate table to use */
|
2002-09-19 09:03:16 +00:00
|
|
|
|
bool header_found = false;
|
2002-04-23 08:43:04 +00:00
|
|
|
|
|
|
|
|
|
long bpf;
|
|
|
|
|
long tpf;
|
|
|
|
|
|
|
|
|
|
/* Start searching after ID3v2 header */
|
2002-04-30 12:42:37 +00:00
|
|
|
|
if(-1 == lseek(fd, entry->id3v2len, SEEK_SET))
|
2002-08-22 07:59:31 +00:00
|
|
|
|
return 0;
|
2002-04-23 08:43:04 +00:00
|
|
|
|
|
|
|
|
|
/* Fill up header with first 24 bits */
|
|
|
|
|
for(version = 0; version < 3; version++) {
|
|
|
|
|
header <<= 8;
|
2002-05-27 14:03:17 +00:00
|
|
|
|
if(!read(fd, &tmp, 1))
|
2002-08-22 07:59:31 +00:00
|
|
|
|
return 0;
|
2002-05-27 14:03:17 +00:00
|
|
|
|
header |= tmp;
|
2002-04-23 08:43:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Loop trough file until we find a frame header */
|
2002-09-16 13:32:12 +00:00
|
|
|
|
bytecount = entry->id3v2len - 1;
|
2002-09-25 12:34:21 +00:00
|
|
|
|
bytelimit = entry->id3v2len + 0x20000;
|
2002-08-14 19:23:34 +00:00
|
|
|
|
restart:
|
2002-04-23 08:43:04 +00:00
|
|
|
|
do {
|
|
|
|
|
header <<= 8;
|
2002-05-27 14:03:17 +00:00
|
|
|
|
if(!read(fd, &tmp, 1))
|
2002-08-22 07:59:31 +00:00
|
|
|
|
return 0;
|
2002-05-27 14:03:17 +00:00
|
|
|
|
header |= tmp;
|
2002-07-22 16:05:46 +00:00
|
|
|
|
|
|
|
|
|
/* Quit if we haven't found a valid header within 128K */
|
|
|
|
|
bytecount++;
|
2002-09-25 12:34:21 +00:00
|
|
|
|
if(bytecount > bytelimit)
|
2002-08-22 07:59:31 +00:00
|
|
|
|
return 0;
|
2002-07-18 15:21:45 +00:00
|
|
|
|
} while(!mp3frameheader(header));
|
2002-04-23 08:43:04 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Some files are filled with garbage in the beginning,
|
|
|
|
|
* if the bitrate index of the header is binary 1111
|
2002-07-03 21:04:09 +00:00
|
|
|
|
* that is a good indicator
|
2002-04-23 08:43:04 +00:00
|
|
|
|
*/
|
|
|
|
|
if((header & 0xF000) == 0xF000)
|
|
|
|
|
goto restart;
|
|
|
|
|
|
|
|
|
|
/* MPEG Audio Version */
|
|
|
|
|
switch((header & 0x180000) >> 19) {
|
2002-08-19 14:15:33 +00:00
|
|
|
|
case 0:
|
|
|
|
|
/* MPEG version 2.5 is not an official standard */
|
|
|
|
|
version = MPEG_VERSION2_5;
|
|
|
|
|
bittable = MPEG_VERSION2; /* use the V2 bit rate table */
|
|
|
|
|
break;
|
|
|
|
|
|
2002-08-14 19:23:34 +00:00
|
|
|
|
case 2:
|
2002-08-19 14:15:33 +00:00
|
|
|
|
/* MPEG version 2 (ISO/IEC 13818-3) */
|
|
|
|
|
version = MPEG_VERSION2;
|
|
|
|
|
bittable = MPEG_VERSION2;
|
2002-08-14 19:23:34 +00:00
|
|
|
|
break;
|
2002-08-19 14:15:33 +00:00
|
|
|
|
|
2002-08-14 19:23:34 +00:00
|
|
|
|
case 3:
|
2002-08-19 14:15:33 +00:00
|
|
|
|
/* MPEG version 1 (ISO/IEC 11172-3) */
|
|
|
|
|
version = MPEG_VERSION1;
|
|
|
|
|
bittable = MPEG_VERSION1;
|
2002-08-14 19:23:34 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
goto restart;
|
2002-04-23 08:43:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Layer */
|
|
|
|
|
switch((header & 0x060000) >> 17) {
|
2002-08-14 19:23:34 +00:00
|
|
|
|
case 1:
|
|
|
|
|
layer = 3;
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
layer = 2;
|
|
|
|
|
break;
|
|
|
|
|
case 3:
|
|
|
|
|
layer = 1;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
goto restart;
|
2002-04-23 08:43:04 +00:00
|
|
|
|
}
|
2002-07-18 02:08:23 +00:00
|
|
|
|
|
2002-04-23 08:43:04 +00:00
|
|
|
|
/* Bitrate */
|
|
|
|
|
bitindex = (header & 0xF000) >> 12;
|
2002-08-19 14:15:33 +00:00
|
|
|
|
bitrate = bitrate_table[bittable-1][layer-1][bitindex];
|
2002-04-23 08:43:04 +00:00
|
|
|
|
if(bitrate == 0)
|
2002-07-22 16:05:46 +00:00
|
|
|
|
goto restart;
|
2002-04-23 08:43:04 +00:00
|
|
|
|
|
|
|
|
|
/* Sampling frequency */
|
|
|
|
|
freqindex = (header & 0x0C00) >> 10;
|
2002-08-19 14:15:33 +00:00
|
|
|
|
frequency = freqtab[version][freqindex];
|
2002-04-23 08:43:04 +00:00
|
|
|
|
if(frequency == 0)
|
2002-07-22 16:05:46 +00:00
|
|
|
|
goto restart;
|
2002-04-23 08:43:04 +00:00
|
|
|
|
|
2002-04-23 11:46:16 +00:00
|
|
|
|
#ifdef DEBUG_VERBOSE
|
2002-07-18 02:08:23 +00:00
|
|
|
|
DEBUGF( "Version %i, lay %i, biti %i, bitr %i, freqi %i, freq %i, chmode %d\n",
|
|
|
|
|
version, layer, bitindex, bitrate, freqindex, frequency, chmode);
|
2002-04-23 08:43:04 +00:00
|
|
|
|
#endif
|
2002-05-12 14:28:51 +00:00
|
|
|
|
entry->version = version;
|
|
|
|
|
entry->layer = layer;
|
2002-04-23 08:43:04 +00:00
|
|
|
|
entry->frequency = frequency;
|
|
|
|
|
|
|
|
|
|
/* Calculate bytes per frame, calculation depends on layer */
|
|
|
|
|
switch(layer) {
|
2002-08-14 19:23:34 +00:00
|
|
|
|
case 1:
|
2002-08-19 14:15:33 +00:00
|
|
|
|
bpf = bitrate_table[bittable - 1][layer - 1][bitindex];
|
2002-08-14 19:23:34 +00:00
|
|
|
|
bpf *= 48000;
|
2002-08-19 14:15:33 +00:00
|
|
|
|
bpf /= freqtab[version][freqindex] << (bittable - 1);
|
2002-08-14 19:23:34 +00:00
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
case 3:
|
2002-08-19 14:15:33 +00:00
|
|
|
|
bpf = bitrate_table[bittable - 1][layer - 1][bitindex];
|
2002-08-14 19:23:34 +00:00
|
|
|
|
bpf *= 144000;
|
2002-08-19 14:15:33 +00:00
|
|
|
|
bpf /= freqtab[version][freqindex] << (bittable - 1);
|
2002-08-14 19:23:34 +00:00
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
bpf = 1;
|
2002-04-23 08:43:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Calculate time per frame */
|
2002-08-19 14:15:33 +00:00
|
|
|
|
tpf = bs[layer] / (freqtab[version][freqindex] << (bittable - 1));
|
2002-07-03 21:04:09 +00:00
|
|
|
|
|
2002-08-14 19:23:34 +00:00
|
|
|
|
entry->bpf = bpf;
|
|
|
|
|
entry->tpf = tpf;
|
|
|
|
|
|
2002-07-03 21:04:09 +00:00
|
|
|
|
/* OK, we have found a frame. Let's see if it has a Xing header */
|
2002-07-10 13:17:31 +00:00
|
|
|
|
if(read(fd, frame, sizeof frame) < 0)
|
2002-07-03 21:04:09 +00:00
|
|
|
|
return -1;
|
2002-04-23 08:43:04 +00:00
|
|
|
|
|
2002-07-18 02:08:23 +00:00
|
|
|
|
/* Channel mode (stereo/mono) */
|
|
|
|
|
chmode = (header & 0xc0) >> 6;
|
|
|
|
|
|
|
|
|
|
/* calculate position of Xing VBR header */
|
|
|
|
|
if ( version == 1 ) {
|
|
|
|
|
if ( chmode == 3 ) /* mono */
|
|
|
|
|
xing = frame + 17;
|
|
|
|
|
else
|
|
|
|
|
xing = frame + 32;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
if ( chmode == 3 ) /* mono */
|
|
|
|
|
xing = frame + 9;
|
|
|
|
|
else
|
|
|
|
|
xing = frame + 17;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (xing[0] == 'X' &&
|
|
|
|
|
xing[1] == 'i' &&
|
|
|
|
|
xing[2] == 'n' &&
|
|
|
|
|
xing[3] == 'g')
|
2002-07-03 21:04:09 +00:00
|
|
|
|
{
|
2002-09-17 07:10:41 +00:00
|
|
|
|
int i = 8; /* Where to start parsing info */
|
|
|
|
|
|
2002-07-05 07:13:43 +00:00
|
|
|
|
/* Yes, it is a VBR file */
|
|
|
|
|
entry->vbr = true;
|
2002-08-15 19:11:26 +00:00
|
|
|
|
entry->vbrflags = xing[7];
|
2002-07-05 07:13:43 +00:00
|
|
|
|
|
2002-08-14 19:23:34 +00:00
|
|
|
|
if (entry->vbrflags & VBR_FRAMES_FLAG) /* Is the frame count there? */
|
2002-07-03 21:04:09 +00:00
|
|
|
|
{
|
2002-09-16 13:32:12 +00:00
|
|
|
|
int framecount = (xing[i] << 24) | (xing[i+1] << 16) |
|
|
|
|
|
(xing[i+2] << 8) | xing[i+3];
|
2002-08-14 19:23:34 +00:00
|
|
|
|
|
2002-07-03 21:04:09 +00:00
|
|
|
|
filetime = framecount * tpf;
|
2002-09-16 13:32:12 +00:00
|
|
|
|
i += 4;
|
2002-07-03 21:04:09 +00:00
|
|
|
|
}
|
2002-08-14 19:23:34 +00:00
|
|
|
|
|
|
|
|
|
if (entry->vbrflags & VBR_BYTES_FLAG) /* is byte count there? */
|
2002-07-10 13:17:31 +00:00
|
|
|
|
{
|
2002-09-16 13:32:12 +00:00
|
|
|
|
int bytecount = (xing[i] << 24) | (xing[i+1] << 16) |
|
|
|
|
|
(xing[i+2] << 8) | xing[i+3];
|
2002-08-14 19:23:34 +00:00
|
|
|
|
|
2002-07-10 13:17:31 +00:00
|
|
|
|
bitrate = bytecount * 8 / filetime;
|
2002-09-16 13:32:12 +00:00
|
|
|
|
i += 4;
|
2002-07-10 13:17:31 +00:00
|
|
|
|
}
|
2002-08-14 19:23:34 +00:00
|
|
|
|
|
|
|
|
|
if (entry->vbrflags & VBR_TOC_FLAG) /* is table-of-contents there? */
|
|
|
|
|
{
|
2002-09-16 13:32:12 +00:00
|
|
|
|
memcpy( entry->toc, xing+i, 100 );
|
2002-08-14 19:23:34 +00:00
|
|
|
|
}
|
2002-09-16 13:32:12 +00:00
|
|
|
|
|
|
|
|
|
/* Make sure we skip this frame in playback */
|
|
|
|
|
bytecount += bpf;
|
2002-09-19 09:03:16 +00:00
|
|
|
|
|
|
|
|
|
header_found = true;
|
2002-09-16 13:32:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-09-27 08:21:23 +00:00
|
|
|
|
if (xing[0] == 'V' &&
|
|
|
|
|
xing[1] == 'B' &&
|
|
|
|
|
xing[2] == 'R' &&
|
|
|
|
|
xing[3] == 'I')
|
|
|
|
|
{
|
|
|
|
|
int framecount;
|
|
|
|
|
int bytecount;
|
|
|
|
|
|
|
|
|
|
/* Yes, it is a FhG VBR file */
|
|
|
|
|
entry->vbr = true;
|
|
|
|
|
entry->vbrflags = 0;
|
|
|
|
|
|
|
|
|
|
bytecount = (xing[10] << 24) | (xing[11] << 16) |
|
|
|
|
|
(xing[12] << 8) | xing[13];
|
|
|
|
|
|
|
|
|
|
framecount = (xing[14] << 24) | (xing[15] << 16) |
|
|
|
|
|
(xing[16] << 8) | xing[17];
|
|
|
|
|
|
|
|
|
|
filetime = framecount * tpf;
|
|
|
|
|
bitrate = bytecount * 8 / filetime;
|
|
|
|
|
|
|
|
|
|
/* We don't parse the TOC, since we don't yet know how to (FIXME) */
|
|
|
|
|
|
|
|
|
|
/* Make sure we skip this frame in playback */
|
|
|
|
|
bytecount += bpf;
|
|
|
|
|
|
|
|
|
|
header_found = true;
|
|
|
|
|
}
|
|
|
|
|
|
2002-09-16 13:32:12 +00:00
|
|
|
|
/* Is it a LAME Info frame? */
|
|
|
|
|
if (xing[0] == 'I' &&
|
|
|
|
|
xing[1] == 'n' &&
|
|
|
|
|
xing[2] == 'f' &&
|
|
|
|
|
xing[3] == 'o')
|
|
|
|
|
{
|
|
|
|
|
/* Make sure we skip this frame in playback */
|
|
|
|
|
bytecount += bpf;
|
2002-09-19 09:03:16 +00:00
|
|
|
|
|
|
|
|
|
header_found = true;
|
2002-07-03 21:04:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-09-16 13:32:12 +00:00
|
|
|
|
|
2002-07-10 13:17:31 +00:00
|
|
|
|
entry->bitrate = bitrate;
|
|
|
|
|
|
2002-07-03 21:04:09 +00:00
|
|
|
|
/* If the file time hasn't been established, this may be a fixed
|
|
|
|
|
rate MP3, so just use the default formula */
|
|
|
|
|
if(filetime == 0)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
* Now song length is
|
|
|
|
|
* ((filesize)/(bytes per frame))*(time per frame)
|
|
|
|
|
*/
|
|
|
|
|
filetime = entry->filesize/bpf*tpf;
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-27 23:07:26 +00:00
|
|
|
|
/* Update the seek point for the first playable frame */
|
|
|
|
|
entry->first_frame_offset = bytecount;
|
|
|
|
|
DEBUGF("First frame is at %x\n", entry->first_frame_offset);
|
|
|
|
|
|
2002-07-03 21:04:09 +00:00
|
|
|
|
return filetime;
|
2002-04-23 08:43:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Checks all relevant information (such as ID3v1 tag, ID3v2 tag, length etc)
|
|
|
|
|
* about an MP3 file and updates it's entry accordingly.
|
|
|
|
|
*
|
|
|
|
|
* Arguments: entry - the entry to check and update with the new information
|
|
|
|
|
*
|
|
|
|
|
* Returns: void
|
|
|
|
|
*/
|
2002-07-04 22:10:43 +00:00
|
|
|
|
bool mp3info(struct mp3entry *entry, char *filename)
|
2002-04-23 08:43:04 +00:00
|
|
|
|
{
|
2002-04-30 12:42:37 +00:00
|
|
|
|
int fd;
|
|
|
|
|
fd = open(filename, O_RDONLY);
|
|
|
|
|
if(-1 == fd)
|
2002-05-13 12:29:34 +00:00
|
|
|
|
return true;
|
2002-04-23 08:43:04 +00:00
|
|
|
|
|
2002-06-25 11:39:22 +00:00
|
|
|
|
memset(entry, 0, sizeof(struct mp3entry));
|
2002-06-27 08:33:58 +00:00
|
|
|
|
|
|
|
|
|
strncpy(entry->path, filename, sizeof(entry->path));
|
|
|
|
|
|
2002-04-23 08:43:04 +00:00
|
|
|
|
entry->title = NULL;
|
2002-06-26 15:20:00 +00:00
|
|
|
|
entry->filesize = getfilesize(fd);
|
2002-06-26 14:51:09 +00:00
|
|
|
|
entry->id3v2len = getid3v2len(fd);
|
2002-06-26 21:11:29 +00:00
|
|
|
|
entry->tracknum = 0;
|
|
|
|
|
|
2002-09-16 08:18:51 +00:00
|
|
|
|
if (entry->id3v2len)
|
2002-04-30 12:42:37 +00:00
|
|
|
|
setid3v2title(fd, entry);
|
2002-06-26 14:51:09 +00:00
|
|
|
|
entry->length = getsonglength(fd, entry);
|
2002-04-23 08:43:04 +00:00
|
|
|
|
|
2002-06-26 14:51:09 +00:00
|
|
|
|
entry->id3v1len = getid3v1len(fd);
|
2002-08-14 10:15:27 +00:00
|
|
|
|
if(entry->id3v1len && !entry->title)
|
2002-04-30 12:42:37 +00:00
|
|
|
|
setid3v1title(fd, entry);
|
|
|
|
|
|
|
|
|
|
close(fd);
|
2002-04-23 08:43:04 +00:00
|
|
|
|
|
2002-08-22 07:59:31 +00:00
|
|
|
|
if(!entry->length || (entry->filesize < 8 ))
|
|
|
|
|
/* no song length or less than 8 bytes is hereby considered to be an
|
|
|
|
|
invalid mp3 and won't be played by us! */
|
|
|
|
|
return true;
|
|
|
|
|
|
2002-05-13 12:29:34 +00:00
|
|
|
|
return false;
|
2002-04-23 08:43:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef DEBUG_STANDALONE
|
|
|
|
|
|
2002-04-23 11:46:16 +00:00
|
|
|
|
char *secs2str(int ms)
|
|
|
|
|
{
|
|
|
|
|
static char buffer[32];
|
|
|
|
|
int secs = ms/1000;
|
|
|
|
|
ms %= 1000;
|
2002-05-02 11:44:15 +00:00
|
|
|
|
snprintf(buffer, sizeof(buffer), "%d:%02d.%d", secs/60, secs%60, ms/100);
|
2002-04-23 11:46:16 +00:00
|
|
|
|
return buffer;
|
|
|
|
|
}
|
|
|
|
|
|
2002-04-23 08:43:04 +00:00
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
|
{
|
2002-04-23 11:46:16 +00:00
|
|
|
|
int i;
|
|
|
|
|
for(i=1; i<argc; i++) {
|
2002-06-25 11:39:22 +00:00
|
|
|
|
struct mp3entry mp3;
|
2002-04-23 11:46:16 +00:00
|
|
|
|
if(mp3info(&mp3, argv[i])) {
|
|
|
|
|
printf("Failed to get %s\n", argv[i]);
|
2002-04-23 08:43:04 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2002-04-23 11:46:16 +00:00
|
|
|
|
printf("****** File: %s\n"
|
|
|
|
|
" Title: %s\n"
|
|
|
|
|
" Artist: %s\n"
|
|
|
|
|
" Album: %s\n"
|
2002-04-26 08:56:43 +00:00
|
|
|
|
" Length: %s / %d s\n"
|
2002-04-23 11:46:16 +00:00
|
|
|
|
" Bitrate: %d\n"
|
|
|
|
|
" Frequency: %d\n",
|
|
|
|
|
argv[i],
|
2002-04-23 08:43:04 +00:00
|
|
|
|
mp3.title?mp3.title:"<blank>",
|
|
|
|
|
mp3.artist?mp3.artist:"<blank>",
|
|
|
|
|
mp3.album?mp3.album:"<blank>",
|
2002-04-23 11:46:16 +00:00
|
|
|
|
secs2str(mp3.length),
|
2002-04-26 08:56:43 +00:00
|
|
|
|
mp3.length/1000,
|
2002-04-23 08:43:04 +00:00
|
|
|
|
mp3.bitrate,
|
|
|
|
|
mp3.frequency);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------
|
|
|
|
|
* local variables:
|
|
|
|
|
* eval: (load-file "rockbox-mode.el")
|
|
|
|
|
* end:
|
|
|
|
|
*/
|