summaryrefslogtreecommitdiff
path: root/apps/metadata
diff options
context:
space:
mode:
authorYoshihisa Uchida <uchida@rockbox.org>2010-02-28 07:22:20 +0000
committerYoshihisa Uchida <uchida@rockbox.org>2010-02-28 07:22:20 +0000
commit4e3c8074664fa87b023643f375171d544d662141 (patch)
tree62e61e1eda814db6bd766b443b0b40d8c2e86bb7 /apps/metadata
parent1fefb48e871cee8328d8f9a5d375cde0627e603a (diff)
downloadrockbox-4e3c8074664fa87b023643f375171d544d662141.tar.gz
rockbox-4e3c8074664fa87b023643f375171d544d662141.zip
Add Sun Audio codec. (FS#10433)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24955 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/metadata')
-rw-r--r--apps/metadata/au.c122
-rw-r--r--apps/metadata/metadata_parsers.h1
2 files changed, 123 insertions, 0 deletions
diff --git a/apps/metadata/au.c b/apps/metadata/au.c
new file mode 100644
index 0000000000..1a7eef03c9
--- /dev/null
+++ b/apps/metadata/au.c
@@ -0,0 +1,122 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2010 Yoshihisa Uchida
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include <stdio.h>
22#include <string.h>
23#include <stdlib.h>
24#include <ctype.h>
25#include <inttypes.h>
26
27#include "system.h"
28#include "metadata.h"
29#include "metadata_common.h"
30#include "metadata_parsers.h"
31#include "logf.h"
32
33static int bitspersamples[28] = {
34 0,
35 8, /* G.711 MULAW */
36 8, /* 8bit */
37 16, /* 16bit */
38 24, /* 24bit */
39 32, /* 32bit */
40 32, /* 32bit */
41 64, /* 64bit */
42 0, /* Fragmented sample data */
43 0, /* DSP program */
44 0, /* 8bit fixed point */
45 0, /* 16bit fixed point */
46 0, /* 24bit fixed point */
47 0, /* 32bit fixed point */
48 0,
49 0,
50 0,
51 0,
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 */
56 0,
57 0, /* G.721 MULAW */
58 0, /* G.722 */
59 0, /* G.723 3bit */
60 0, /* G.723 5bit */
61 8, /* G.711 ALAW */
62};
63
64static int get_au_bitspersample(unsigned int encoding)
65{
66 if (encoding > 27)
67 return 0;
68 return bitspersamples[encoding];
69}
70
71bool get_au_metadata(int fd, struct mp3entry* id3)
72{
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;
79 int read_bytes;
80 int offset;
81
82 id3->vbr = false; /* All Sun audio files are CBR */
83 id3->filesize = filesize(fd);
84
85 if ((lseek(fd, 0, SEEK_SET) < 0) || ((read_bytes = read(fd, buf, 24)) < 0))
86 return false;
87
88 if (read_bytes < 24 || (memcmp(buf, ".snd", 4) != 0))
89 {
90 /* no header */
91 numbytes = id3->filesize;
92 bitspersample = 8;
93 id3->frequency = 8000;
94 channels = 1;
95 }
96 else
97 {
98 /* data offset */
99 offset = get_long_be(buf + 4);
100 if (offset < 24)
101 {
102 DEBUGF("CODEC_ERROR: sun audio offset size is small: %d\n", offset);
103 return false;
104 }
105 /* data size */
106 numbytes = get_long_be(buf + 8);
107 if (numbytes == (uint32_t)0xffffffff)
108 numbytes = id3->filesize - offset;
109 /* bitspersample */
110 bitspersample = get_au_bitspersample(get_long_be(buf + 12));
111 /* sample rate */
112 id3->frequency = get_long_be(buf + 16);
113 channels = get_long_be(buf + 20);
114 }
115
116 totalsamples = numbytes / ((((bitspersample - 1) / 8) + 1) * channels);
117
118 /* Calculate track length (in ms) and estimate the bitrate (in kbit/s) */
119 id3->length = ((int64_t) totalsamples * 1000) / id3->frequency;
120
121 return true;
122}
diff --git a/apps/metadata/metadata_parsers.h b/apps/metadata/metadata_parsers.h
index 1e439c807b..392f16a8d9 100644
--- a/apps/metadata/metadata_parsers.h
+++ b/apps/metadata/metadata_parsers.h
@@ -43,3 +43,4 @@ bool get_rm_metadata(int fd, struct mp3entry* id3);
43bool get_nsf_metadata(int fd, struct mp3entry* id3); 43bool get_nsf_metadata(int fd, struct mp3entry* id3);
44bool get_oma_metadata(int fd, struct mp3entry* id3); 44bool get_oma_metadata(int fd, struct mp3entry* id3);
45bool get_smaf_metadata(int fd, struct mp3entry* id3); 45bool get_smaf_metadata(int fd, struct mp3entry* id3);
46bool get_au_metadata(int fd, struct mp3entry* id3);