mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-12-09 21:25:19 -05:00
Put A52/AC3 metadata parser in its own file. Cosmetic changes in metadata.c. Remove some unneeded headers from MPC metadata parser.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15874 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
b911ee822a
commit
5915736dd5
5 changed files with 110 additions and 75 deletions
|
|
@ -126,6 +126,7 @@ metadata/spc.c
|
|||
metadata/vorbis.c
|
||||
metadata/wave.c
|
||||
metadata/wavpack.c
|
||||
metadata/a52.c
|
||||
#endif
|
||||
#ifdef HAVE_TAGCACHE
|
||||
tagcache.c
|
||||
|
|
|
|||
|
|
@ -36,24 +36,6 @@
|
|||
#include "metadata/metadata_common.h"
|
||||
#include "metadata/metadata_parsers.h"
|
||||
|
||||
static const unsigned short a52_bitrates[] =
|
||||
{
|
||||
32, 40, 48, 56, 64, 80, 96, 112, 128, 160,
|
||||
192, 224, 256, 320, 384, 448, 512, 576, 640
|
||||
};
|
||||
|
||||
/* Only store frame sizes for 44.1KHz - others are simply multiples
|
||||
of the bitrate */
|
||||
static const unsigned short a52_441framesizes[] =
|
||||
{
|
||||
69 * 2, 70 * 2, 87 * 2, 88 * 2, 104 * 2, 105 * 2, 121 * 2,
|
||||
122 * 2, 139 * 2, 140 * 2, 174 * 2, 175 * 2, 208 * 2, 209 * 2,
|
||||
243 * 2, 244 * 2, 278 * 2, 279 * 2, 348 * 2, 349 * 2, 417 * 2,
|
||||
418 * 2, 487 * 2, 488 * 2, 557 * 2, 558 * 2, 696 * 2, 697 * 2,
|
||||
835 * 2, 836 * 2, 975 * 2, 976 * 2, 1114 * 2, 1115 * 2, 1253 * 2,
|
||||
1254 * 2, 1393 * 2, 1394 * 2
|
||||
};
|
||||
|
||||
#endif /* CONFIG_CODEC == SWCODEC */
|
||||
|
||||
|
||||
|
|
@ -100,8 +82,6 @@ bool get_metadata(struct mp3entry* id3, int fd, const char* trackname)
|
|||
{
|
||||
#if CONFIG_CODEC == SWCODEC
|
||||
unsigned char* buf;
|
||||
unsigned long totalsamples;
|
||||
int i;
|
||||
#endif
|
||||
|
||||
/* Clear the mp3entry to avoid having bogus pointers appear */
|
||||
|
|
@ -179,64 +159,19 @@ bool get_metadata(struct mp3entry* id3, int fd, const char* trackname)
|
|||
|
||||
case AFMT_WAVPACK:
|
||||
if (!get_wavpack_metadata(fd, id3))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
read_ape_tags(fd, id3); /* use any apetag info we find */
|
||||
break;
|
||||
|
||||
case AFMT_A52:
|
||||
/* Use the trackname part of the id3 structure as a temporary buffer */
|
||||
buf = (unsigned char *)id3->path;
|
||||
|
||||
if ((lseek(fd, 0, SEEK_SET) < 0) || (read(fd, buf, 5) < 5))
|
||||
if (!get_a52_metadata(fd, id3))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((buf[0] != 0x0b) || (buf[1] != 0x77))
|
||||
{
|
||||
logf("%s is not an A52/AC3 file\n",trackname);
|
||||
return false;
|
||||
}
|
||||
|
||||
i = buf[4] & 0x3e;
|
||||
|
||||
if (i > 36)
|
||||
{
|
||||
logf("A52: Invalid frmsizecod: %d\n",i);
|
||||
return false;
|
||||
}
|
||||
|
||||
id3->bitrate = a52_bitrates[i >> 1];
|
||||
id3->vbr = false;
|
||||
id3->filesize = filesize(fd);
|
||||
|
||||
switch (buf[4] & 0xc0)
|
||||
{
|
||||
case 0x00:
|
||||
id3->frequency = 48000;
|
||||
id3->bytesperframe=id3->bitrate * 2 * 2;
|
||||
break;
|
||||
|
||||
case 0x40:
|
||||
id3->frequency = 44100;
|
||||
id3->bytesperframe = a52_441framesizes[i];
|
||||
break;
|
||||
|
||||
case 0x80:
|
||||
id3->frequency = 32000;
|
||||
id3->bytesperframe = id3->bitrate * 3 * 2;
|
||||
break;
|
||||
|
||||
default:
|
||||
logf("A52: Invalid samplerate code: 0x%02x\n", buf[4] & 0xc0);
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
/* One A52 frame contains 6 blocks, each containing 256 samples */
|
||||
totalsamples = id3->filesize / id3->bytesperframe * 6 * 256;
|
||||
id3->length = totalsamples / id3->frequency * 1000;
|
||||
break;
|
||||
|
||||
case AFMT_ALAC:
|
||||
|
|
@ -264,15 +199,17 @@ bool get_metadata(struct mp3entry* id3, int fd, const char* trackname)
|
|||
return false;
|
||||
}
|
||||
break;
|
||||
|
||||
case AFMT_SPC:
|
||||
if(!get_spc_metadata(fd, id3))
|
||||
if (!get_spc_metadata(fd, id3))
|
||||
{
|
||||
DEBUGF("get_spc_metadata error\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
id3->filesize = filesize(fd);
|
||||
id3->genre_string = id3_get_num_genre(36);
|
||||
break;
|
||||
|
||||
case AFMT_ADX:
|
||||
if (!get_adx_metadata(fd, id3))
|
||||
{
|
||||
|
|
@ -281,6 +218,7 @@ bool get_metadata(struct mp3entry* id3, int fd, const char* trackname)
|
|||
}
|
||||
|
||||
break;
|
||||
|
||||
case AFMT_NSF:
|
||||
buf = (unsigned char *)id3->path;
|
||||
if ((lseek(fd, 0, SEEK_SET) < 0) || ((read(fd, buf, 8)) < 8))
|
||||
|
|
|
|||
98
apps/metadata/a52.c
Normal file
98
apps/metadata/a52.c
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
/***************************************************************************
|
||||
* __________ __ ___.
|
||||
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
||||
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
||||
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
||||
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
||||
* \/ \/ \/ \/ \/
|
||||
* $Id: metadata.c 15859 2007-11-30 18:48:07Z lostlogic $
|
||||
*
|
||||
* Copyright (C) 2005 Magnus Holmgren
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#include "id3.h"
|
||||
#include "logf.h"
|
||||
|
||||
static const unsigned short a52_bitrates[] =
|
||||
{
|
||||
32, 40, 48, 56, 64, 80, 96, 112, 128, 160,
|
||||
192, 224, 256, 320, 384, 448, 512, 576, 640
|
||||
};
|
||||
|
||||
/* Only store frame sizes for 44.1KHz - others are simply multiples
|
||||
of the bitrate */
|
||||
static const unsigned short a52_441framesizes[] =
|
||||
{
|
||||
69 * 2, 70 * 2, 87 * 2, 88 * 2, 104 * 2, 105 * 2, 121 * 2,
|
||||
122 * 2, 139 * 2, 140 * 2, 174 * 2, 175 * 2, 208 * 2, 209 * 2,
|
||||
243 * 2, 244 * 2, 278 * 2, 279 * 2, 348 * 2, 349 * 2, 417 * 2,
|
||||
418 * 2, 487 * 2, 488 * 2, 557 * 2, 558 * 2, 696 * 2, 697 * 2,
|
||||
835 * 2, 836 * 2, 975 * 2, 976 * 2, 1114 * 2, 1115 * 2, 1253 * 2,
|
||||
1254 * 2, 1393 * 2, 1394 * 2
|
||||
};
|
||||
|
||||
bool get_a52_metadata(int fd, struct mp3entry *id3)
|
||||
{
|
||||
/* Use the trackname part of the id3 structure as a temporary buffer */
|
||||
unsigned char* buf = (unsigned char *)id3->path;
|
||||
unsigned long totalsamples;
|
||||
int i;
|
||||
|
||||
if ((lseek(fd, 0, SEEK_SET) < 0) || (read(fd, buf, 5) < 5))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((buf[0] != 0x0b) || (buf[1] != 0x77))
|
||||
{
|
||||
logf("%s is not an A52/AC3 file\n",trackname);
|
||||
return false;
|
||||
}
|
||||
|
||||
i = buf[4] & 0x3e;
|
||||
|
||||
if (i > 36)
|
||||
{
|
||||
logf("A52: Invalid frmsizecod: %d\n",i);
|
||||
return false;
|
||||
}
|
||||
|
||||
id3->bitrate = a52_bitrates[i >> 1];
|
||||
id3->vbr = false;
|
||||
id3->filesize = filesize(fd);
|
||||
|
||||
switch (buf[4] & 0xc0)
|
||||
{
|
||||
case 0x00:
|
||||
id3->frequency = 48000;
|
||||
id3->bytesperframe=id3->bitrate * 2 * 2;
|
||||
break;
|
||||
|
||||
case 0x40:
|
||||
id3->frequency = 44100;
|
||||
id3->bytesperframe = a52_441framesizes[i];
|
||||
break;
|
||||
|
||||
case 0x80:
|
||||
id3->frequency = 32000;
|
||||
id3->bytesperframe = id3->bitrate * 3 * 2;
|
||||
break;
|
||||
|
||||
default:
|
||||
logf("A52: Invalid samplerate code: 0x%02x\n", buf[4] & 0xc0);
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
/* One A52 frame contains 6 blocks, each containing 256 samples */
|
||||
totalsamples = id3->filesize / id3->bytesperframe * 6 * 256;
|
||||
id3->length = totalsamples / id3->frequency * 1000;
|
||||
return true;
|
||||
}
|
||||
|
|
@ -30,4 +30,5 @@ bool get_speex_metadata(int fd, struct mp3entry* id3);
|
|||
bool get_vorbis_metadata(int fd, struct mp3entry* id3);
|
||||
bool get_wave_metadata(int fd, struct mp3entry* id3);
|
||||
bool get_wavpack_metadata(int fd, struct mp3entry* id3);
|
||||
bool get_a52_metadata(int fd, struct mp3entry* id3);
|
||||
bool get_asf_metadata(int fd, struct mp3entry* id3);
|
||||
|
|
|
|||
|
|
@ -16,12 +16,9 @@
|
|||
* KIND, either express or implied.
|
||||
*
|
||||
****************************************************************************/
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <inttypes.h>
|
||||
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include "system.h"
|
||||
#include "id3.h"
|
||||
#include "metadata_common.h"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue