summaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
authorYoshihisa Uchida <uchida@rockbox.org>2010-03-13 05:19:40 +0000
committerYoshihisa Uchida <uchida@rockbox.org>2010-03-13 05:19:40 +0000
commit4446d1bc857b41e491d04b05eeccc873a206fd18 (patch)
tree47a50663e5680e115e32bed19b1f76e073b81c05 /apps
parent131bb698ada664a49e0a548b515b14733914654e (diff)
reduce firmware and sun audio codec.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@25140 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r--apps/codecs/au.c63
-rw-r--r--apps/codecs/libpcm/ieee_float.c10
-rw-r--r--apps/codecs/libpcm/itut_g711.c17
-rw-r--r--apps/codecs/libpcm/linear_pcm.c16
-rw-r--r--apps/metadata/au.c73
5 files changed, 81 insertions, 98 deletions
diff --git a/apps/codecs/au.c b/apps/codecs/au.c
index cf2a799be6..19348bc299 100644
--- a/apps/codecs/au.c
+++ b/apps/codecs/au.c
@@ -45,35 +45,17 @@ enum
AU_FORMAT_ALAW, /* G.711 ALAW */
};
-static int support_formats[28][2] = {
- { AU_FORMAT_UNSUPPORT, 0 },
- { AU_FORMAT_MULAW, 8 }, /* G.711 MULAW */
- { AU_FORMAT_PCM, 8 }, /* Linear PCM 8bit (signed) */
- { AU_FORMAT_PCM, 16 }, /* Linear PCM 16bit (signed, big endian) */
- { AU_FORMAT_PCM, 24 }, /* Linear PCM 24bit (signed, big endian) */
- { AU_FORMAT_PCM, 32 }, /* Linear PCM 32bit (signed, big endian) */
- { AU_FORMAT_IEEE_FLOAT, 32 }, /* Linear PCM float 32bit (signed, big endian) */
- { AU_FORMAT_IEEE_FLOAT, 64 }, /* Linear PCM float 64bit (signed, big endian) */
- { AU_FORMAT_UNSUPPORT, 0 }, /* Fragmented sample data */
- { AU_FORMAT_UNSUPPORT, 0 }, /* DSP program */
- { AU_FORMAT_UNSUPPORT, 0 }, /* 8bit fixed point */
- { AU_FORMAT_UNSUPPORT, 0 }, /* 16bit fixed point */
- { AU_FORMAT_UNSUPPORT, 0 }, /* 24bit fixed point */
- { AU_FORMAT_UNSUPPORT, 0 }, /* 32bit fixed point */
- { AU_FORMAT_UNSUPPORT, 0 },
- { AU_FORMAT_UNSUPPORT, 0 },
- { AU_FORMAT_UNSUPPORT, 0 },
- { AU_FORMAT_UNSUPPORT, 0 },
- { AU_FORMAT_UNSUPPORT, 0 }, /* 16bit linear with emphasis */
- { AU_FORMAT_UNSUPPORT, 0 }, /* 16bit linear compressed */
- { AU_FORMAT_UNSUPPORT, 0 }, /* 16bit linear with emphasis and compression */
- { AU_FORMAT_UNSUPPORT, 0 }, /* Music kit DSP commands */
- { AU_FORMAT_UNSUPPORT, 0 },
- { AU_FORMAT_UNSUPPORT, 0 }, /* G.721 MULAW */
- { AU_FORMAT_UNSUPPORT, 0 }, /* G.722 */
- { AU_FORMAT_UNSUPPORT, 0 }, /* G.723 3bit */
- { AU_FORMAT_UNSUPPORT, 0 }, /* G.723 5bit */
- { AU_FORMAT_ALAW, 8 }, /* G.711 ALAW */
+static const char support_formats[9][2] = {
+ { AU_FORMAT_UNSUPPORT, 0 }, /* encoding */
+ { AU_FORMAT_MULAW, 8 }, /* 1: G.711 MULAW */
+ { AU_FORMAT_PCM, 8 }, /* 2: Linear PCM 8bit (signed) */
+ { AU_FORMAT_PCM, 16 }, /* 3: Linear PCM 16bit (signed, big endian) */
+ { AU_FORMAT_PCM, 24 }, /* 4: Linear PCM 24bit (signed, big endian) */
+ { AU_FORMAT_PCM, 32 }, /* 5: Linear PCM 32bit (signed, big endian) */
+ { AU_FORMAT_IEEE_FLOAT, 32 }, /* 6: Linear PCM float 32bit (signed, big endian) */
+ { AU_FORMAT_IEEE_FLOAT, 64 }, /* 7: Linear PCM float 64bit (signed, big endian) */
+ /* encoding 8 - 26 unsupported. */
+ { AU_FORMAT_ALAW, 8 }, /* 27: G.711 ALAW */
};
const struct pcm_entry au_codecs[] = {
@@ -108,16 +90,17 @@ static unsigned int get_be32(uint8_t *buf)
static int convert_au_format(unsigned int encoding, struct pcm_format *fmt)
{
- if (encoding > 27)
- {
- fmt->formattag = AU_FORMAT_UNSUPPORT;
- fmt->bitspersample = 0;
- }
- else
+ fmt->formattag = AU_FORMAT_UNSUPPORT;
+ if (encoding < 8)
{
fmt->formattag = support_formats[encoding][0];
fmt->bitspersample = support_formats[encoding][1];
}
+ else if (encoding == 27)
+ {
+ fmt->formattag = support_formats[8][0];
+ fmt->bitspersample = support_formats[8][1];
+ }
return fmt->formattag;
}
@@ -138,7 +121,7 @@ enum codec_status codec_main(void)
int offset = 0;
/* Generic codec initialisation */
- ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH);
+ ci->configure(DSP_SET_SAMPLE_DEPTH, PCM_OUTPUT_DEPTH-1);
next_track:
if (codec_init()) {
@@ -199,11 +182,6 @@ next_track:
}
/* skip sample rate */
format.channels = get_be32(buf + 20);
- if (format.channels == 0) {
- DEBUGF("CODEC_ERROR: sun audio 0-channels file\n");
- status = CODEC_ERROR;
- goto done;
- }
}
/* advance to first WAVE chunk */
@@ -215,9 +193,6 @@ next_track:
codec = 0;
bytesdone = 0;
- /* blockalign = 1 sample */
- format.blockalign = format.bitspersample * format.channels >> 3;
-
/* get codec */
codec = get_au_codec(format.formattag);
if (!codec)
diff --git a/apps/codecs/libpcm/ieee_float.c b/apps/codecs/libpcm/ieee_float.c
index 0530993f31..7e3498edcb 100644
--- a/apps/codecs/libpcm/ieee_float.c
+++ b/apps/codecs/libpcm/ieee_float.c
@@ -32,6 +32,12 @@ static bool set_format(struct pcm_format *format)
{
fmt = format;
+ if (fmt->channels == 0)
+ {
+ DEBUGF("CODEC_ERROR: channels is 0\n");
+ return false;
+ }
+
if (fmt->bitspersample != 32 && fmt->bitspersample != 64)
{
DEBUGF("CODEC_ERROR: ieee float must be 32 or 64 bitspersample: %d\n",
@@ -40,6 +46,10 @@ static bool set_format(struct pcm_format *format)
}
fmt->bytespersample = fmt->bitspersample >> 3;
+
+ if (fmt->blockalign == 0)
+ fmt->blockalign = fmt->bytespersample * fmt->channels;
+
fmt->samplesperblock = fmt->blockalign / (fmt->bytespersample * fmt->channels);
/* chunksize = about 1/50[sec] data */
diff --git a/apps/codecs/libpcm/itut_g711.c b/apps/codecs/libpcm/itut_g711.c
index 4644a9c694..097dd5cc25 100644
--- a/apps/codecs/libpcm/itut_g711.c
+++ b/apps/codecs/libpcm/itut_g711.c
@@ -112,6 +112,12 @@ static bool set_format(struct pcm_format *format)
{
fmt = format;
+ if (fmt->channels == 0)
+ {
+ DEBUGF("CODEC_ERROR: channels is 0\n");
+ return false;
+ }
+
if (fmt->bitspersample != 8)
{
DEBUGF("CODEC_ERROR: alaw and mulaw must have 8 bitspersample: %d\n",
@@ -119,13 +125,12 @@ static bool set_format(struct pcm_format *format)
return false;
}
- if (fmt->totalsamples == 0)
- {
- fmt->bytespersample = 1;
- fmt->totalsamples = fmt->numbytes / (fmt->bytespersample * fmt->channels);
- }
+ fmt->bytespersample = 1;
+
+ if (fmt->blockalign == 0)
+ fmt->blockalign = fmt->channels;
- fmt->samplesperblock = fmt->blockalign / (fmt->bytespersample * fmt->channels);
+ fmt->samplesperblock = fmt->blockalign / fmt->channels;
/* chunksize = about 1/50[sec] data */
fmt->chunksize = (ci->id3->frequency / (50 * fmt->samplesperblock))
diff --git a/apps/codecs/libpcm/linear_pcm.c b/apps/codecs/libpcm/linear_pcm.c
index 82c70eb3b6..e58856efe8 100644
--- a/apps/codecs/libpcm/linear_pcm.c
+++ b/apps/codecs/libpcm/linear_pcm.c
@@ -38,6 +38,18 @@ static bool set_format(struct pcm_format *format)
{
fmt = format;
+ if (fmt->channels == 0)
+ {
+ DEBUGF("CODEC_ERROR: channels is 0\n");
+ return false;
+ }
+
+ if (fmt->bitspersample == 0)
+ {
+ DEBUGF("CODEC_ERROR: bitspersample is 0\n");
+ return false;
+ }
+
if (fmt->bitspersample > 32)
{
DEBUGF("CODEC_ERROR: pcm with more than 32 bitspersample "
@@ -47,8 +59,8 @@ static bool set_format(struct pcm_format *format)
fmt->bytespersample = fmt->bitspersample >> 3;
- if (fmt->totalsamples == 0)
- fmt->totalsamples = fmt->numbytes/fmt->bytespersample;
+ if (fmt->blockalign == 0)
+ fmt->blockalign = fmt->bytespersample * fmt->channels;
fmt->samplesperblock = fmt->blockalign / (fmt->bytespersample * fmt->channels);
diff --git a/apps/metadata/au.c b/apps/metadata/au.c
index 0639bd11e6..94e7453644 100644
--- a/apps/metadata/au.c
+++ b/apps/metadata/au.c
@@ -20,8 +20,6 @@
****************************************************************************/
#include <stdio.h>
#include <string.h>
-#include <stdlib.h>
-#include <ctype.h>
#include <inttypes.h>
#include "system.h"
@@ -30,62 +28,42 @@
#include "metadata_parsers.h"
#include "logf.h"
-/* table of bits per sample / 8 */
-static const unsigned char bitspersamples[28] = {
- 0,
- 1, /* G.711 MULAW */
- 1, /* 8bit */
- 2, /* 16bit */
- 3, /* 24bit */
- 4, /* 32bit */
- 4, /* 32bit */
- 8, /* 64bit */
- 0, /* Fragmented sample data */
- 0, /* DSP program */
- 0, /* 8bit fixed point */
- 0, /* 16bit fixed point */
- 0, /* 24bit fixed point */
- 0, /* 32bit fixed point */
- 0,
- 0,
- 0,
- 0,
- 0, /* 16bit linear with emphasis */
- 0, /* 16bit linear compressed */
- 0, /* 16bit linear with emphasis and compression */
- 0, /* Music kit DSP commands */
- 0,
- 0, /* G.721 MULAW */
- 0, /* G.722 */
- 0, /* G.723 3bit */
- 0, /* G.723 5bit */
- 1, /* G.711 ALAW */
+static const unsigned char bitspersamples[9] = {
+ 0, /* encoding */
+ 8, /* 1: G.711 MULAW */
+ 8, /* 2: Linear PCM 8bit */
+ 16, /* 3: Linear PCM 16bit */
+ 24, /* 4: Linear PCM 24bit */
+ 32, /* 5: Linear PCM 32bit */
+ 32, /* 6: IEEE float 32bit */
+ 64, /* 7: IEEE float 64bit */
+ /* encoding 8 - 26 unsupported. */
+ 8, /* 27: G.711 ALAW */
};
static inline unsigned char get_au_bitspersample(unsigned int encoding)
{
- if (encoding > 27)
- return 0;
- return bitspersamples[encoding];
+ if (encoding < 8)
+ return bitspersamples[encoding];
+ else if (encoding == 27)
+ return bitspersamples[8];
+
+ return 0;
}
bool get_au_metadata(int fd, struct mp3entry* id3)
{
- /* Use the trackname part of the id3 structure as a temporary buffer */
+ /* temporary buffer */
unsigned char* buf = (unsigned char *)id3->path;
unsigned long numbytes = 0;
- int read_bytes;
int offset;
- unsigned char bits_ch; /* bitspersample * channels */
id3->vbr = false; /* All Sun audio files are CBR */
id3->filesize = filesize(fd);
id3->length = 0;
- if ((lseek(fd, 0, SEEK_SET) < 0) || ((read_bytes = read(fd, buf, 24)) < 0))
- return false;
-
- if (read_bytes < 24 || (memcmp(buf, ".snd", 4) != 0))
+ lseek(fd, 0, SEEK_SET);
+ if ((read(fd, buf, 24) < 24) || (memcmp(buf, ".snd", 4) != 0))
{
/*
* no header
@@ -96,10 +74,12 @@ bool get_au_metadata(int fd, struct mp3entry* id3)
*/
numbytes = id3->filesize;
id3->frequency = 8000;
- bits_ch = 1;
+ id3->bitrate = 8;
}
else
{
+ /* parse header */
+
/* data offset */
offset = get_long_be(buf + 4);
if (offset < 24)
@@ -112,13 +92,14 @@ bool get_au_metadata(int fd, struct mp3entry* id3)
if (numbytes == (uint32_t)0xffffffff)
numbytes = id3->filesize - offset;
- bits_ch = get_au_bitspersample(get_long_be(buf + 12)) * get_long_be(buf + 20);
id3->frequency = get_long_be(buf + 16);
+ id3->bitrate = get_au_bitspersample(get_long_be(buf + 12)) * get_long_be(buf + 20)
+ * id3->frequency / 1000;
}
/* Calculate track length [ms] */
- if (bits_ch)
- id3->length = ((int64_t)numbytes * 1000LL) / (bits_ch * id3->frequency);
+ if (id3->bitrate)
+ id3->length = (numbytes << 3) / id3->bitrate;
return true;
}