diff options
| author | Marcoen Hirschberg <marcoen@gmail.com> | 2007-06-16 18:19:51 +0000 |
|---|---|---|
| committer | Marcoen Hirschberg <marcoen@gmail.com> | 2007-06-16 18:19:51 +0000 |
| commit | 2175d1edf65367fd3fe3cff266b8d6ea12930f2f (patch) | |
| tree | 9d6f50ebfc7919b4e2f0853fc8c0cb844cabe995 /apps/metadata/monkeys.c | |
| parent | c3206a455a455fadb282d09f9af482c66b6bdf8e (diff) | |
| download | rockbox-2175d1edf65367fd3fe3cff266b8d6ea12930f2f.zip rockbox-2175d1edf65367fd3fe3cff266b8d6ea12930f2f.tar.gz rockbox-2175d1edf65367fd3fe3cff266b8d6ea12930f2f.tar.bz2 rockbox-2175d1edf65367fd3fe3cff266b8d6ea12930f2f.tar.xz | |
split up the metadata parser
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13637 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/metadata/monkeys.c')
| -rw-r--r-- | apps/metadata/monkeys.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/apps/metadata/monkeys.c b/apps/metadata/monkeys.c new file mode 100644 index 0000000..bda3a01 --- /dev/null +++ b/apps/metadata/monkeys.c @@ -0,0 +1,92 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2005 Dave Chapman + * + * 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 <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <ctype.h> +#include <inttypes.h> + +#include "system.h" +#include "id3.h" +#include "metadata_common.h" + +bool get_monkeys_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 char* header; + bool rc = false; + uint32_t descriptorlength; + uint32_t totalsamples; + uint32_t blocksperframe, finalframeblocks, totalframes; + int fileversion; + + lseek(fd, 0, SEEK_SET); + + if (read(fd, buf, 4) < 4) + { + return rc; + } + + if (memcmp(buf, "MAC ", 4) != 0) + { + return rc; + } + + read(fd, buf + 4, MAX_PATH - 4); + + fileversion = get_short_le(buf+4); + if (fileversion < 3970) + { + /* Not supported */ + return false; + } + + if (fileversion >= 3980) + { + descriptorlength = get_long_le(buf+8); + + header = buf + descriptorlength; + + blocksperframe = get_long_le(header+4); + finalframeblocks = get_long_le(header+8); + totalframes = get_long_le(header+12); + id3->frequency = get_long_le(header+20); + } + else + { + /* v3.95 and later files all have a fixed framesize */ + blocksperframe = 73728 * 4; + + finalframeblocks = get_long_le(buf+28); + totalframes = get_long_le(buf+24); + id3->frequency = get_long_le(buf+12); + } + + id3->vbr = true; /* All FLAC files are VBR */ + id3->filesize = filesize(fd); + + totalsamples = finalframeblocks; + if (totalframes > 1) + totalsamples += blocksperframe * (totalframes-1); + + id3->length = ((int64_t) totalsamples * 1000) / id3->frequency; + id3->bitrate = (id3->filesize * 8) / id3->length; + return true; +} |