summaryrefslogtreecommitdiff
path: root/lib/rbcodec/metadata/aiff.c
diff options
context:
space:
mode:
authorSean Bartell <wingedtachikoma@gmail.com>2011-06-24 01:25:21 -0400
committerNils Wallménius <nils@rockbox.org>2012-03-18 12:00:39 +0100
commitb5716df4cb2837bbbc42195cf1aefcf03e21d6a6 (patch)
tree130cd712e2e00893b6df9959a375a8d9523a1aca /lib/rbcodec/metadata/aiff.c
parent24bd9d5393dbe39a5c6194877bc00ede669b1d5d (diff)
downloadrockbox-b5716df4cb2837bbbc42195cf1aefcf03e21d6a6.tar.gz
rockbox-b5716df4cb2837bbbc42195cf1aefcf03e21d6a6.zip
Build librbcodec with DSP and metadata.
All associated files are moved to /lib/rbcodec. Change-Id: I572ddd2b8a996aae1e98c081d06b1ed356dce222
Diffstat (limited to 'lib/rbcodec/metadata/aiff.c')
-rw-r--r--lib/rbcodec/metadata/aiff.c108
1 files changed, 108 insertions, 0 deletions
diff --git a/lib/rbcodec/metadata/aiff.c b/lib/rbcodec/metadata/aiff.c
new file mode 100644
index 0000000000..654f37cf98
--- /dev/null
+++ b/lib/rbcodec/metadata/aiff.c
@@ -0,0 +1,108 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 Dave Chapman
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include <stdio.h>
22#include <string.h>
23#include <stdlib.h>
24#include <ctype.h>
25#include <inttypes.h>
26
27#include "system.h"
28#include "metadata.h"
29#include "metadata_common.h"
30#include "metadata_parsers.h"
31
32#include "debug.h"
33
34/* compressionType: AIFC QuickTime IMA ADPCM */
35#define AIFC_FORMAT_QT_IMA_ADPCM "ima4"
36
37bool get_aiff_metadata(int fd, struct mp3entry* id3)
38{
39 unsigned char buf[512];
40 unsigned long numChannels = 0;
41 unsigned long numSampleFrames = 0;
42 unsigned long numbytes = 0;
43 bool is_aifc = false;
44
45 if ((lseek(fd, 0, SEEK_SET) < 0) || (read(fd, &buf[0], 12) < 12) ||
46 (memcmp(&buf[0], "FORM", 4) != 0) || (memcmp(&buf[8], "AIF", 3) != 0) ||
47 (!(is_aifc = (buf[11] == 'C')) && buf[11] != 'F'))
48 {
49 return false;
50 }
51
52 while (read(fd, &buf[0], 8) == 8)
53 {
54 size_t size = get_long_be(&buf[4]); /* chunkSize */
55
56 if (memcmp(&buf[0], "SSND", 4) == 0)
57 {
58 numbytes = size - 8;
59 break; /* assume COMM was already read */
60 }
61
62 /* odd chunk sizes must be padded */
63 size += size & 1;
64
65 if (size > sizeof(buf))
66 {
67 DEBUGF("AIFF \"%4.4s\" chunk too large (%zd > %zd)",
68 (char*) &buf[0], size, sizeof(buf));
69 }
70
71 if (memcmp(&buf[0], "COMM", 4) == 0)
72 {
73 if (size > sizeof(buf) || read(fd, &buf[0], size) != (ssize_t)size)
74 return false;
75
76 numChannels = ((buf[0]<<8)|buf[1]);
77
78 numSampleFrames = get_long_be(&buf[2]);
79
80 /* sampleRate */
81 id3->frequency = get_long_be(&buf[10]);
82 id3->frequency >>= (16+14-buf[9]);
83
84 /* save format infos */
85 id3->bitrate = ((buf[6]<<8)|buf[7]) * numChannels * id3->frequency;
86 id3->bitrate /= 1000;
87
88 if (!is_aifc || memcmp(&buf[18], AIFC_FORMAT_QT_IMA_ADPCM, 4) != 0)
89 id3->length = ((int64_t) numSampleFrames * 1000) / id3->frequency;
90 else
91 {
92 /* QuickTime IMA ADPCM is 1block = 64 data for each channel */
93 id3->length = ((int64_t) numSampleFrames * 64000LL) / id3->frequency;
94 }
95
96 id3->vbr = false; /* AIFF files are CBR */
97 id3->filesize = filesize(fd);
98 }
99 else
100 {
101 /* skip chunk */
102 if (lseek(fd, size, SEEK_CUR) < 0)
103 return false;
104 }
105 }
106
107 return numbytes && numChannels;
108}