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 ****************************************************************************/
29 #include "metadata_common.h"
30 #include "metadata_parsers.h"
33 /* table of bits per sample / 8 */
34 static const unsigned char bitspersamples
[28] = {
43 0, /* Fragmented sample data */
45 0, /* 8bit fixed point */
46 0, /* 16bit fixed point */
47 0, /* 24bit fixed point */
48 0, /* 32bit fixed point */
53 0, /* 16bit linear with emphasis */
54 0, /* 16bit linear compressed */
55 0, /* 16bit linear with emphasis and compression */
56 0, /* Music kit DSP commands */
65 static inline unsigned char get_au_bitspersample(unsigned int encoding
)
69 return bitspersamples
[encoding
];
72 bool get_au_metadata(int fd
, struct mp3entry
* id3
)
74 /* Use the trackname part of the id3 structure as a temporary buffer */
75 unsigned char* buf
= (unsigned char *)id3
->path
;
76 unsigned long numbytes
= 0;
79 unsigned char bits_ch
; /* bitspersample * channels */
81 id3
->vbr
= false; /* All Sun audio files are CBR */
82 id3
->filesize
= filesize(fd
);
85 if ((lseek(fd
, 0, SEEK_SET
) < 0) || ((read_bytes
= read(fd
, buf
, 24)) < 0))
88 if (read_bytes
< 24 || (memcmp(buf
, ".snd", 4) != 0))
94 * bits per sample: 8 bit
97 numbytes
= id3
->filesize
;
98 id3
->frequency
= 8000;
104 offset
= get_long_be(buf
+ 4);
107 DEBUGF("CODEC_ERROR: sun audio offset size is small: %d\n", offset
);
111 numbytes
= get_long_be(buf
+ 8);
112 if (numbytes
== (uint32_t)0xffffffff)
113 numbytes
= id3
->filesize
- offset
;
115 bits_ch
= get_au_bitspersample(get_long_be(buf
+ 12)) * get_long_be(buf
+ 20);
116 id3
->frequency
= get_long_be(buf
+ 16);
119 /* Calculate track length [ms] */
121 id3
->length
= ((int64_t)numbytes
* 1000LL) / (bits_ch
* id3
->frequency
);