summaryrefslogtreecommitdiff
path: root/apps/codecs/alac.c
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2005-10-29 17:12:52 +0000
committerDave Chapman <dave@dchapman.com>2005-10-29 17:12:52 +0000
commit45f9e5d7b02ce3b9d165f45d63825d50244634d4 (patch)
tree900097f56dbecc41ea4fc6cd50366f0af3164e84 /apps/codecs/alac.c
parente75cbdd2a84904e9294091c0ae599762b067077a (diff)
Remove generic M4A parsing code from libalac and create a libm4a - so it can be used by other codecs
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@7682 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/alac.c')
-rw-r--r--apps/codecs/alac.c212
1 files changed, 6 insertions, 206 deletions
diff --git a/apps/codecs/alac.c b/apps/codecs/alac.c
index d4823233f2..916dd06262 100644
--- a/apps/codecs/alac.c
+++ b/apps/codecs/alac.c
@@ -18,9 +18,8 @@
****************************************************************************/
#include "codeclib.h"
-#include <codecs/libalac/demux.h>
-#include <codecs/libalac/decomp.h>
-#include <codecs/libalac/stream.h>
+#include "libm4a/m4a.h"
+#include "libalac/decomp.h"
#ifndef SIMULATOR
extern char iramcopy[];
@@ -32,212 +31,16 @@ extern char iramend[];
char inputBuffer[1024*32]; /* Input buffer */
int32_t outputbuffer[ALAC_MAX_CHANNELS][ALAC_BLOCKSIZE] IBSS_ATTR;
-size_t mdat_offset;
+
struct codec_api* rb;
struct codec_api* ci;
-/* Implementation of the stream.h functions used by libalac */
-
-#define _Swap32(v) do { \
- v = (((v) & 0x000000FF) << 0x18) | \
- (((v) & 0x0000FF00) << 0x08) | \
- (((v) & 0x00FF0000) >> 0x08) | \
- (((v) & 0xFF000000) >> 0x18); } while(0)
-
-#define _Swap16(v) do { \
- v = (((v) & 0x00FF) << 0x08) | \
- (((v) & 0xFF00) >> 0x08); } while (0)
-
-/* A normal read without any byte-swapping */
-void stream_read(stream_t *stream, size_t size, void *buf)
-{
- ci->read_filebuf(buf,size);
- if (ci->curpos >= ci->filesize) { stream->eof=1; }
-}
-
-int32_t stream_read_int32(stream_t *stream)
-{
- int32_t v;
- stream_read(stream, 4, &v);
-#ifdef ROCKBOX_LITTLE_ENDIAN
- _Swap32(v);
-#endif
- return v;
-}
-
-uint32_t stream_read_uint32(stream_t *stream)
-{
- uint32_t v;
- stream_read(stream, 4, &v);
-#ifdef ROCKBOX_LITTLE_ENDIAN
- _Swap32(v);
-#endif
- return v;
-}
-
-int16_t stream_read_int16(stream_t *stream)
-{
- int16_t v;
- stream_read(stream, 2, &v);
-#ifdef ROCKBOX_LITTLE_ENDIAN
- _Swap16(v);
-#endif
- return v;
-}
-
-uint16_t stream_read_uint16(stream_t *stream)
-{
- uint16_t v;
- stream_read(stream, 2, &v);
-#ifdef ROCKBOX_LITTLE_ENDIAN
- _Swap16(v);
-#endif
- return v;
-}
-
-int8_t stream_read_int8(stream_t *stream)
-{
- int8_t v;
- stream_read(stream, 1, &v);
- return v;
-}
-
-uint8_t stream_read_uint8(stream_t *stream)
-{
- uint8_t v;
- stream_read(stream, 1, &v);
- return v;
-}
-
-void stream_skip(stream_t *stream, size_t skip)
-{
- (void)stream;
- ci->advance_buffer(skip);
-}
-
-int stream_eof(stream_t *stream)
-{
- return stream->eof;
-}
-
-void stream_create(stream_t *stream)
-{
- stream->eof=0;
-}
-
-/* This function was part of the original alac decoder implementation */
-
-static int get_sample_info(demux_res_t *demux_res, uint32_t samplenum,
- uint32_t *sample_duration,
- uint32_t *sample_byte_size)
-{
- unsigned int duration_index_accum = 0;
- unsigned int duration_cur_index = 0;
-
- if (samplenum >= demux_res->num_sample_byte_sizes) {
- return 0;
- }
-
- if (!demux_res->num_time_to_samples) {
- return 0;
- }
-
- while ((demux_res->time_to_sample[duration_cur_index].sample_count
- + duration_index_accum) <= samplenum) {
- duration_index_accum +=
- demux_res->time_to_sample[duration_cur_index].sample_count;
-
- duration_cur_index++;
- if (duration_cur_index >= demux_res->num_time_to_samples) {
- return 0;
- }
- }
-
- *sample_duration =
- demux_res->time_to_sample[duration_cur_index].sample_duration;
- *sample_byte_size = demux_res->sample_byte_size[samplenum];
-
- return 1;
-}
-
-/* Seek to sample_loc (or close to it). Return 1 on success (and
- modify samplesdone and currentblock), 0 if failed
-
- Seeking uses the following two arrays:
-
- 1) the sample_byte_size array contains the length in bytes of
- each block ("sample" in Applespeak).
-
- 2) the time_to_sample array contains the duration (in samples) of
- each block of data.
-
- So we just find the block number we are going to seek to (using
- time_to_sample) and then find the offset in the file (using
- sample_byte_size).
-
- Each ALAC block seems to be independent of all the others.
- */
-
-static unsigned int alac_seek (demux_res_t* demux_res,
- unsigned int sample_loc,
- uint32_t* samplesdone, int* currentblock)
-{
- int flag;
- unsigned int i,j;
- unsigned int newblock;
- unsigned int newsample;
- unsigned int newpos;
-
- /* First check we have the appropriate metadata - we should always
- have it. */
- if ((demux_res->num_time_to_samples==0) ||
- (demux_res->num_sample_byte_sizes==0)) { return 0; }
-
- /* Find the destination block from time_to_sample array */
- i=0;
- newblock=0;
- newsample=0;
- flag=0;
-
- while ((i<demux_res->num_time_to_samples) && (flag==0) &&
- (newsample < sample_loc)) {
- j=(sample_loc-newsample) /
- demux_res->time_to_sample[i].sample_duration;
-
- if (j <= demux_res->time_to_sample[i].sample_count) {
- newblock+=j;
- newsample+=j*demux_res->time_to_sample[i].sample_duration;
- flag=1;
- } else {
- newsample+=(demux_res->time_to_sample[i].sample_duration
- * demux_res->time_to_sample[i].sample_count);
- newblock+=demux_res->time_to_sample[i].sample_count;
- i++;
- }
- }
-
- /* We know the new block, now calculate the file position */
- newpos=mdat_offset;
- for (i=0;i<newblock;i++) {
- newpos+=demux_res->sample_byte_size[i];
- }
-
- /* We know the new file position, so let's try to seek to it */
- if (ci->seek_buffer(newpos)) {
- *samplesdone=newsample;
- *currentblock=newblock;
- return 1;
- } else {
- return 0;
- }
-}
-
/* this is the codec entry point */
enum codec_status codec_start(struct codec_api* api)
{
size_t n;
demux_res_t demux_res;
- static stream_t input_stream;
+ stream_t input_stream;
uint32_t samplesdone;
uint32_t elapsedtime;
uint32_t sample_duration;
@@ -278,7 +81,7 @@ enum codec_status codec_start(struct codec_api* api)
ci->configure(DSP_SET_FREQUENCY, (long *)(rb->id3->frequency));
- stream_create(&input_stream);
+ stream_create(&input_stream,ci);
/* if qtmovie_read returns successfully, the stream is up to
* the movie data, which can be used directly by the decoder */
@@ -287,9 +90,6 @@ enum codec_status codec_start(struct codec_api* api)
return CODEC_ERROR;
}
- /* Keep track of start of stream in file - used for seeking */
- mdat_offset=ci->curpos;
-
/* initialise the sound converter */
create_alac(demux_res.sample_size, demux_res.num_channels,&alac);
alac_set_info(&alac, demux_res.codecdata);
@@ -305,7 +105,7 @@ enum codec_status codec_start(struct codec_api* api)
/* Deal with any pending seek requests */
if (ci->seek_time) {
- if (alac_seek(&demux_res,
+ if (alac_seek(&demux_res,&input_stream,
(ci->seek_time/10) * (ci->id3->frequency/100),
&samplesdone, &i)) {
elapsedtime=(samplesdone*10)/(ci->id3->frequency/100);