1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2010 Yoshihisa Uchida
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
27 #include "metadata_common.h"
28 #include "metadata_parsers.h"
31 static const unsigned char bitspersamples
[9] = {
33 8, /* 1: G.711 MULAW */
34 8, /* 2: Linear PCM 8bit */
35 16, /* 3: Linear PCM 16bit */
36 24, /* 4: Linear PCM 24bit */
37 32, /* 5: Linear PCM 32bit */
38 32, /* 6: IEEE float 32bit */
39 64, /* 7: IEEE float 64bit */
40 /* encoding 8 - 26 unsupported. */
41 8, /* 27: G.711 ALAW */
44 static inline unsigned char get_au_bitspersample(unsigned int encoding
)
47 return bitspersamples
[encoding
];
48 else if (encoding
== 27)
49 return bitspersamples
[8];
54 bool get_au_metadata(int fd
, struct mp3entry
* id3
)
56 /* temporary buffer */
57 unsigned char* buf
= (unsigned char *)id3
->path
;
58 unsigned long numbytes
= 0;
61 id3
->vbr
= false; /* All Sun audio files are CBR */
62 id3
->filesize
= filesize(fd
);
65 lseek(fd
, 0, SEEK_SET
);
66 if ((read(fd
, buf
, 24) < 24) || (memcmp(buf
, ".snd", 4) != 0))
72 * bits per sample: 8 bit
75 numbytes
= id3
->filesize
;
76 id3
->frequency
= 8000;
84 offset
= get_long_be(buf
+ 4);
87 DEBUGF("CODEC_ERROR: sun audio offset size is small: %d\n", offset
);
91 numbytes
= get_long_be(buf
+ 8);
92 if (numbytes
== (uint32_t)0xffffffff)
93 numbytes
= id3
->filesize
- offset
;
95 id3
->frequency
= get_long_be(buf
+ 16);
96 id3
->bitrate
= get_au_bitspersample(get_long_be(buf
+ 12)) * get_long_be(buf
+ 20)
97 * id3
->frequency
/ 1000;
100 /* Calculate track length [ms] */
102 id3
->length
= (numbytes
<< 3) / id3
->bitrate
;