1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 Dave Chapman
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.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
27 #include "metadata_common.h"
29 bool get_aiff_metadata(int fd
, struct mp3entry
* id3
)
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;
41 if ((lseek(fd
, 0, SEEK_SET
) < 0)
42 || ((read_bytes
= read(fd
, buf
, sizeof(id3
->path
))) < 54))
47 if ((memcmp(buf
, "FORM",4) != 0)
48 || (memcmp(&buf
[8], "AIFF", 4) !=0 ))
56 while ((numbytes
== 0) && (read_bytes
>= 8))
59 i
= get_long_be(&buf
[4]);
61 if (memcmp(buf
, "COMM", 4) == 0)
64 numChannels
= ((buf
[8]<<8)|buf
[9]);
66 numSampleFrames
= get_long_be(&buf
[10]);
68 sampleSize
= ((buf
[14]<<8)|buf
[15]);
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
;
77 id3
->vbr
= false; /* AIFF files are CBR */
78 id3
->filesize
= filesize(fd
);
80 else if (memcmp(buf
, "SSND", 4) == 0)
87 i
++; /* odd chunk sizes must be padded */
93 if ((numbytes
== 0) || (numChannels
== 0))