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 static unsigned char bitspersamples
[28] = {
42 0, /* Fragmented sample data */
44 0, /* 8bit fixed point */
45 0, /* 16bit fixed point */
46 0, /* 24bit fixed point */
47 0, /* 32bit fixed point */
52 0, /* 16bit linear with emphasis */
53 0, /* 16bit linear compressed */
54 0, /* 16bit linear with emphasis and compression */
55 0, /* Music kit DSP commands */
64 static int get_au_bitspersample(unsigned int encoding
)
68 return bitspersamples
[encoding
];
71 bool get_au_metadata(int fd
, struct mp3entry
* id3
)
73 /* Use the trackname part of the id3 structure as a temporary buffer */
74 unsigned char* buf
= (unsigned char *)id3
->path
;
75 unsigned long totalsamples
= 0;
76 unsigned long channels
= 0;
77 unsigned long bitspersample
= 0;
78 unsigned long numbytes
= 0;
82 id3
->vbr
= false; /* All Sun audio files are CBR */
83 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))
91 numbytes
= id3
->filesize
;
93 id3
->frequency
= 8000;
99 offset
= get_long_be(buf
+ 4);
102 DEBUGF("CODEC_ERROR: sun audio offset size is small: %d\n", offset
);
106 numbytes
= get_long_be(buf
+ 8);
107 if (numbytes
== (uint32_t)0xffffffff)
108 numbytes
= id3
->filesize
- offset
;
110 bitspersample
= get_au_bitspersample(get_long_be(buf
+ 12));
112 id3
->frequency
= get_long_be(buf
+ 16);
113 channels
= get_long_be(buf
+ 20);
116 totalsamples
= numbytes
/ ((((bitspersample
- 1) / 8) + 1) * channels
);
118 /* Calculate track length (in ms) and estimate the bitrate (in kbit/s) */
119 id3
->length
= ((int64_t) totalsamples
* 1000) / id3
->frequency
;