summaryrefslogtreecommitdiff
path: root/apps/metadata/aiff.c
diff options
context:
space:
mode:
authorMarcoen Hirschberg <marcoen@gmail.com>2007-06-16 18:19:51 +0000
committerMarcoen Hirschberg <marcoen@gmail.com>2007-06-16 18:19:51 +0000
commit2175d1edf65367fd3fe3cff266b8d6ea12930f2f (patch)
tree9d6f50ebfc7919b4e2f0853fc8c0cb844cabe995 /apps/metadata/aiff.c
parentc3206a455a455fadb282d09f9af482c66b6bdf8e (diff)
downloadrockbox-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/aiff.c')
-rw-r--r--apps/metadata/aiff.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/apps/metadata/aiff.c b/apps/metadata/aiff.c
new file mode 100644
index 0000000..3b155ca
--- /dev/null
+++ b/apps/metadata/aiff.c
@@ -0,0 +1,98 @@
+/***************************************************************************
+ * __________ __ ___.
+ * 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_aiff_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 numChannels = 0;
+ unsigned long numSampleFrames = 0;
+ unsigned long sampleSize = 0;
+ unsigned long sampleRate = 0;
+ unsigned long numbytes = 0;
+ int read_bytes;
+ int i;
+
+ if ((lseek(fd, 0, SEEK_SET) < 0)
+ || ((read_bytes = read(fd, buf, sizeof(id3->path))) < 54))
+ {
+ return false;
+ }
+
+ if ((memcmp(buf, "FORM",4) != 0)
+ || (memcmp(&buf[8], "AIFF", 4) !=0 ))
+ {
+ return false;
+ }
+
+ buf += 12;
+ read_bytes -= 12;
+
+ while ((numbytes == 0) && (read_bytes >= 8))
+ {
+ /* chunkSize */
+ i = get_long_be(&buf[4]);
+
+ if (memcmp(buf, "COMM", 4) == 0)
+ {
+ /* numChannels */
+ numChannels = ((buf[8]<<8)|buf[9]);
+ /* numSampleFrames */
+ numSampleFrames = get_long_be(&buf[10]);
+ /* sampleSize */
+ sampleSize = ((buf[14]<<8)|buf[15]);
+ /* sampleRate */
+ sampleRate = get_long_be(&buf[18]);
+ sampleRate = sampleRate >> (16+14-buf[17]);
+ /* save format infos */
+ id3->bitrate = (sampleSize * numChannels * sampleRate) / 1000;
+ id3->frequency = sampleRate;
+ id3->length = ((int64_t) numSampleFrames * 1000) / id3->frequency;
+
+ id3->vbr = false; /* AIFF files are CBR */
+ id3->filesize = filesize(fd);
+ }
+ else if (memcmp(buf, "SSND", 4) == 0)
+ {
+ numbytes = i - 8;
+ }
+
+ if (i & 0x01)
+ {
+ i++; /* odd chunk sizes must be padded */
+ }
+ buf += i + 8;
+ read_bytes -= i + 8;
+ }
+
+ if ((numbytes == 0) || (numChannels == 0))
+ {
+ return false;
+ }
+ return true;
+}