diff options
Diffstat (limited to 'apps/metadata/aiff.c')
-rw-r--r-- | apps/metadata/aiff.c | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/apps/metadata/aiff.c b/apps/metadata/aiff.c new file mode 100644 index 0000000000..3b155caa2b --- /dev/null +++ b/apps/metadata/aiff.c | |||
@@ -0,0 +1,98 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2005 Dave Chapman | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include <stdio.h> | ||
20 | #include <string.h> | ||
21 | #include <stdlib.h> | ||
22 | #include <ctype.h> | ||
23 | #include <inttypes.h> | ||
24 | |||
25 | #include "system.h" | ||
26 | #include "id3.h" | ||
27 | #include "metadata_common.h" | ||
28 | |||
29 | bool get_aiff_metadata(int fd, struct mp3entry* id3) | ||
30 | { | ||
31 | /* Use the trackname part of the id3 structure as a temporary buffer */ | ||
32 | unsigned char* buf = (unsigned char *)id3->path; | ||
33 | unsigned long numChannels = 0; | ||
34 | unsigned long numSampleFrames = 0; | ||
35 | unsigned long sampleSize = 0; | ||
36 | unsigned long sampleRate = 0; | ||
37 | unsigned long numbytes = 0; | ||
38 | int read_bytes; | ||
39 | int i; | ||
40 | |||
41 | if ((lseek(fd, 0, SEEK_SET) < 0) | ||
42 | || ((read_bytes = read(fd, buf, sizeof(id3->path))) < 54)) | ||
43 | { | ||
44 | return false; | ||
45 | } | ||
46 | |||
47 | if ((memcmp(buf, "FORM",4) != 0) | ||
48 | || (memcmp(&buf[8], "AIFF", 4) !=0 )) | ||
49 | { | ||
50 | return false; | ||
51 | } | ||
52 | |||
53 | buf += 12; | ||
54 | read_bytes -= 12; | ||
55 | |||
56 | while ((numbytes == 0) && (read_bytes >= 8)) | ||
57 | { | ||
58 | /* chunkSize */ | ||
59 | i = get_long_be(&buf[4]); | ||
60 | |||
61 | if (memcmp(buf, "COMM", 4) == 0) | ||
62 | { | ||
63 | /* numChannels */ | ||
64 | numChannels = ((buf[8]<<8)|buf[9]); | ||
65 | /* numSampleFrames */ | ||
66 | numSampleFrames = get_long_be(&buf[10]); | ||
67 | /* sampleSize */ | ||
68 | sampleSize = ((buf[14]<<8)|buf[15]); | ||
69 | /* sampleRate */ | ||
70 | sampleRate = get_long_be(&buf[18]); | ||
71 | sampleRate = sampleRate >> (16+14-buf[17]); | ||
72 | /* save format infos */ | ||
73 | id3->bitrate = (sampleSize * numChannels * sampleRate) / 1000; | ||
74 | id3->frequency = sampleRate; | ||
75 | id3->length = ((int64_t) numSampleFrames * 1000) / id3->frequency; | ||
76 | |||
77 | id3->vbr = false; /* AIFF files are CBR */ | ||
78 | id3->filesize = filesize(fd); | ||
79 | } | ||
80 | else if (memcmp(buf, "SSND", 4) == 0) | ||
81 | { | ||
82 | numbytes = i - 8; | ||
83 | } | ||
84 | |||
85 | if (i & 0x01) | ||
86 | { | ||
87 | i++; /* odd chunk sizes must be padded */ | ||
88 | } | ||
89 | buf += i + 8; | ||
90 | read_bytes -= i + 8; | ||
91 | } | ||
92 | |||
93 | if ((numbytes == 0) || (numChannels == 0)) | ||
94 | { | ||
95 | return false; | ||
96 | } | ||
97 | return true; | ||
98 | } | ||