Index: apps/metadata.c =================================================================== --- apps/metadata.c (revision 13537) +++ apps/metadata.c (working copy) @@ -982,6 +982,56 @@ return true; } +static bool get_monkeys_metadata(int fd, struct mp3entry* id3) +{ + /* Use the trackname part of the id3 structure as a temporary buffer */ + unsigned char* buf = (unsigned char *)id3->path; + unsigned char* header; + bool rc = false; + uint32_t descriptorlength; + uint32_t totalsamples; + uint32_t blocksperframe, finalframeblocks, totalframes; + + lseek(fd, 0, SEEK_SET); + + if (read(fd, buf, 4) < 4) + { + return rc; + } + + if (memcmp(buf, "MAC ", 4) != 0) + { + return rc; + } + + read(fd, buf + 4, MAX_PATH - 4); + + descriptorlength = buf[8] | (buf[9] << 8) | + (buf[10] << 16) | (buf[11] << 24); + + header = buf + descriptorlength; + + blocksperframe = header[4] | (header[5] << 8) | + (header[6] << 16) | (header[7] << 24); + finalframeblocks = header[8] | (header[9] << 8) | + (header[10] << 16) | (header[11] << 24); + totalframes = header[12] | (header[13] << 8) | + (header[14] << 16) | (header[15] << 24); + + id3->vbr = true; /* All FLAC files are VBR */ + id3->filesize = filesize(fd); + id3->frequency = header[20] | (header[21] << 8) | + (header[22] << 16) | (header[23] << 24); + + totalsamples = finalframeblocks; + if (totalframes > 1) + totalsamples += blocksperframe * (totalframes-1); + + id3->length = ((int64_t) totalsamples * 1000) / id3->frequency; + id3->bitrate = (id3->filesize * 8) / id3->length; + return true; +} + static bool get_wave_metadata(int fd, struct mp3entry* id3) { /* Use the trackname part of the id3 structure as a temporary buffer */ @@ -2152,6 +2202,14 @@ break; + case AFMT_APE: + if (!get_monkeys_metadata(fd, &(track->id3))) + { + return false; + } + read_ape_tags(fd, &(track->id3)); + break; + case AFMT_MPC: if (!get_musepack_metadata(fd, &(track->id3))) return false; Index: apps/filetypes.c =================================================================== --- apps/filetypes.c (revision 13537) +++ apps/filetypes.c (working copy) @@ -76,6 +76,8 @@ { "nsf", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, { "nsfe",FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, { "spc", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, + { "ape", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, + { "mac", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, #endif { "m3u", FILE_ATTR_M3U, Icon_Playlist, LANG_PLAYLIST }, { "m3u8",FILE_ATTR_M3U, Icon_Playlist, LANG_PLAYLIST }, Index: apps/codecs/ape.c =================================================================== --- apps/codecs/ape.c (revision 0) +++ apps/codecs/ape.c (revision 0) @@ -0,0 +1,162 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: flac.c 12830 2007-03-18 09:50:53Z learman $ + * + * Copyright (C) 2007 Dave Chapman + * + * All files in this archive are subject to the GNU General Public License. + * See the file COPYING in the source tree root for full license agreement. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include "codeclib.h" +#define ROCKBOX +#include + +CODEC_HEADER + +#define BLOCKS_PER_LOOP 4608 +#define MAX_CHANNELS 2 +#define MAX_BYTESPERSAMPLE 3 + +#define INPUT_CHUNKSIZE (32*1024) + +/* 4608*4 = 18432 bytes per channel */ +static int32_t decoded0[BLOCKS_PER_LOOP] IBSS_ATTR; +static int32_t decoded1[BLOCKS_PER_LOOP] IBSS_ATTR; + +#define MAX_SUPPORTED_SEEKTABLE_SIZE 5000 + +/* this is the codec entry point */ +enum codec_status codec_main(void) +{ + struct ape_ctx_t ape_ctx; + uint32_t samplesdone; + uint32_t elapsedtime; + size_t bytesleft; + int retval; + + uint32_t currentframe; + int nblocks; + int bytesconsumed; + unsigned char* inbuffer; + int blockstodecode; + int res; + int firstbyte; + + /* Generic codec initialisation */ + ci->configure(CODEC_SET_FILEBUF_WATERMARK, 1024*512); + ci->configure(CODEC_SET_FILEBUF_CHUNKSIZE, 1024*128); + + ci->configure(DSP_SET_SAMPLE_DEPTH, APE_OUTPUT_DEPTH-1); + + next_track: + + if (codec_init()) { + LOGF("APE: Error initialising codec\n"); + retval = CODEC_ERROR; + goto exit; + } + + inbuffer = ci->request_buffer(&bytesleft, INPUT_CHUNKSIZE); + + /* Read the file headers to populate the ape_ctx struct */ + if (ape_parseheaderbuf(inbuffer,&ape_ctx) < 0) { + LOGF("APE: Error reading header\n"); + retval = CODEC_ERROR; + goto exit; + } + ci->advance_buffer(ape_ctx.firstframe); + + while (!*ci->taginfo_ready && !ci->stop_codec) + ci->sleep(1); + + ci->configure(DSP_SWITCH_FREQUENCY, ape_ctx.samplerate); + ci->configure(DSP_SET_STEREO_MODE, ape_ctx.channels == 1 ? + STEREO_MONO : STEREO_NONINTERLEAVED); + codec_set_replaygain(ci->id3); + + /* The main decoding loop */ + + currentframe = 0; + samplesdone = 0; + + /* Initialise the buffer */ + inbuffer = ci->request_buffer(&bytesleft, INPUT_CHUNKSIZE); + firstbyte = 3; /* Take account of the little-endian 32-bit byte ordering */ + + /* The main decoding loop - we decode the frames a small chunk at a time */ + while (currentframe < ape_ctx.totalframes) + { + /* Calculate how many blocks there are in this frame */ + if (currentframe == (ape_ctx.totalframes - 1)) + nblocks = ape_ctx.finalframeblocks; + else + nblocks = ape_ctx.blocksperframe; + + ape_ctx.currentframeblocks = nblocks; + + /* Initialise the frame decoder */ + init_frame_decoder(&ape_ctx, inbuffer, &firstbyte, &bytesconsumed); + + ci->advance_buffer(bytesconsumed); + inbuffer = ci->request_buffer(&bytesleft, INPUT_CHUNKSIZE); + + /* Decode the frame a chunk at a time */ + while (nblocks > 0) + { + ci->yield(); + if (ci->stop_codec || ci->new_track) { + break; + } + + blockstodecode = MIN(BLOCKS_PER_LOOP, nblocks); + + if ((res = decode_chunk(&ape_ctx, inbuffer, &firstbyte, + &bytesconsumed, + decoded0, decoded1, + blockstodecode)) < 0) + { + /* Frame decoding error, abort */ + LOGF("APE: Frame %d, error %d\n",currentframe,res); + retval = CODEC_ERROR; + goto done; + } + + ci->yield(); + ci->pcmbuf_insert(decoded0, decoded1, blockstodecode); + + /* Update the elapsed-time indicator */ + samplesdone += blockstodecode; + elapsedtime = (samplesdone*10)/(ape_ctx.samplerate/100); + ci->set_elapsed(elapsedtime); + + ci->advance_buffer(bytesconsumed); + inbuffer = ci->request_buffer(&bytesleft, INPUT_CHUNKSIZE); + + /* Decrement the block count */ + nblocks -= blockstodecode; + } + + currentframe++; + } + + retval = CODEC_OK; + +done: + LOGF("APE: Decoded %ld samples\n",samplesdone); + + if (ci->request_next_track()) + goto next_track; + +exit: + return retval; +} Index: apps/codecs/Makefile =================================================================== --- apps/codecs/Makefile (revision 13537) +++ apps/codecs/Makefile (working copy) @@ -17,7 +17,7 @@ endif ifdef SOFTWARECODECS - CODECLIBS = -lmad -la52 -lffmpegFLAC -lTremor -lwavpack -lmusepack -lalac -lfaad -lm4a -lspeex + CODECLIBS = -lmad -la52 -lffmpegFLAC -lTremor -lwavpack -lmusepack -lalac -lfaad -lm4a -lspeex -ldemac endif # we "borrow" the plugin LDS file @@ -39,7 +39,7 @@ CODECDEPS = $(LINKCODEC) $(BUILDDIR)/libcodec.a -.PHONY: libmad liba52 libffmpegFLAC libTremor libspeex libwavpack libmusepack libalac libfaad libm4a +.PHONY: libmad liba52 libffmpegFLAC libTremor libspeex libwavpack libmusepack libalac libfaad libm4a libdemac OUTPUT = $(SOFTWARECODECS) @@ -64,6 +64,7 @@ $(OBJDIR)/alac.elf : $(OBJDIR)/alac.o $(BUILDDIR)/libalac.a $(BUILDDIR)/libm4a.a $(OBJDIR)/codec_crt0.o $(OBJDIR)/aac.elf : $(OBJDIR)/aac.o $(BUILDDIR)/libfaad.a $(BUILDDIR)/libm4a.a $(OBJDIR)/codec_crt0.o $(OBJDIR)/shorten.elf : $(OBJDIR)/shorten.o $(BUILDDIR)/libffmpegFLAC.a $(OBJDIR)/codec_crt0.o +$(OBJDIR)/ape.elf : $(OBJDIR)/ape.o $(BUILDDIR)/libdemac.a $(OBJDIR)/codec_crt0.o $(OBJDIR)/aiff_enc.elf: $(OBJDIR)/aiff_enc.o $(OBJDIR)/codec_crt0.o $(OBJDIR)/mp3_enc.elf: $(OBJDIR)/mp3_enc.o $(OBJDIR)/codec_crt0.o $(OBJDIR)/wav_enc.elf: $(OBJDIR)/wav_enc.o $(OBJDIR)/codec_crt0.o @@ -198,18 +199,25 @@ $(SILENT)mkdir -p $(OBJDIR)/libfaad $(call PRINTS,MAKE in libfaad)$(MAKE) -C libfaad OBJDIR=$(OBJDIR)/libfaad OUTPUT=$(BUILDDIR)/libfaad.a +$(BUILDDIR)/libdemac.a: libdemac + +libdemac: + $(SILENT)mkdir -p $(OBJDIR)/libdemac + $(call PRINTS,MAKE in libdemac)$(MAKE) -C libdemac OBJDIR=$(OBJDIR)/libdemac OUTPUT=$(BUILDDIR)/libdemac.a + clean: - $(call PRINTS,cleaning codecs)rm -fr $(OBJDIR)/libmad $(BUILDDIR)/libmad.a $(OBJDIR)/liba52 $(BUILDDIR)/liba52.a $(OBJDIR)/libffmpegFLAC $(BUILDDIR)/libffmpegFLAC.a $(OBJDIR)/Tremor $(BUILDDIR)/libTremor.a $(OBJDIR)/libspeex $(BUILDDIR)/libSpeex.a $(OBJDIR)/libwavpack $(BUILDDIR)/libwavpack.a $(OBJDIR)/libmusepack $(BUILDDIR)/libmusepack.a $(OBJDIR)/libalac $(BUILDDIR)/libalac.a $(OBJDIR)/libfaad $(BUILDDIR)/libfaad.a $(OBJDIR)/libm4a $(BUILDDIR)/libm4a.a + $(call PRINTS,cleaning codecs)rm -fr $(OBJDIR)/libmad $(BUILDDIR)/libmad.a $(OBJDIR)/liba52 $(BUILDDIR)/liba52.a $(OBJDIR)/libffmpegFLAC $(BUILDDIR)/libffmpegFLAC.a $(OBJDIR)/Tremor $(BUILDDIR)/libTremor.a $(OBJDIR)/libspeex $(BUILDDIR)/libSpeex.a $(OBJDIR)/libwavpack $(BUILDDIR)/libwavpack.a $(OBJDIR)/libmusepack $(BUILDDIR)/libmusepack.a $(OBJDIR)/libalac $(BUILDDIR)/libalac.a $(OBJDIR)/libfaad $(BUILDDIR)/libfaad.a $(OBJDIR)/libm4a $(BUILDDIR)/libm4a.a $(OBJDIR)/libdemac $(BUILDDIR)/libdemac.a $(SILENT)$(MAKE) -C libmad clean OBJDIR=$(OBJDIR)/libmad $(SILENT)$(MAKE) -C liba52 clean OBJDIR=$(OBJDIR)/liba52 $(SILENT)$(MAKE) -C libffmpegFLAC clean OBJDIR=$(OBJDIR)/libffmpegFLAC $(SILENT)$(MAKE) -C Tremor clean OBJDIR=$(OBJDIR)/Tremor - $(SILENT)$(MAKE) -C libspeex clean OBJDIR=$(OBJDIR)/libspeex + $(SILENT)$(MAKE) -C libspeex clean OBJDIR=$(OBJDIR)/libspeex $(SILENT)$(MAKE) -C libwavpack clean OBJDIR=$(OBJDIR)/libwavpack $(SILENT)$(MAKE) -C libmusepack clean OBJDIR=$(OBJDIR)/libmusepack $(SILENT)$(MAKE) -C libalac clean OBJDIR=$(OBJDIR)/libalac $(SILENT)$(MAKE) -C libfaad clean OBJDIR=$(OBJDIR)/libfaad $(SILENT)$(MAKE) -C libm4a clean OBJDIR=$(OBJDIR)/libm4a + $(SILENT)$(MAKE) -C libdemac clean OBJDIR=$(OBJDIR)/libdemac $(SILENT)$(MAKE) -C lib clean OBJDIR=$(OBJDIR)/lib ifneq ($(MAKECMDGOALS),clean) Index: apps/codecs/SOURCES =================================================================== --- apps/codecs/SOURCES (revision 13537) +++ apps/codecs/SOURCES (working copy) @@ -11,6 +11,7 @@ #if MEMORYSIZE > 1 aac.c #endif +ape.c shorten.c aiff.c speex.c Index: apps/codecs/libdemac/filter_64_11.c =================================================================== --- apps/codecs/libdemac/filter_64_11.c (revision 0) +++ apps/codecs/libdemac/filter_64_11.c (revision 0) @@ -0,0 +1,25 @@ +/* + +libdemac - A Monkey's Audio decoder + +Copyright (C) Dave Chapman 2007 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA + +*/ + +#define ORDER 64 +#define FRACBITS 11 +#include "filter.c" Index: apps/codecs/libdemac/entropy.c =================================================================== --- apps/codecs/libdemac/entropy.c (revision 0) +++ apps/codecs/libdemac/entropy.c (revision 0) @@ -0,0 +1,290 @@ +#include +#include + +#include "parser.h" +#include "entropy.h" +#include "rangecoding.h" /* Range-coding (static inline) functions */ + +#define MODEL_ELEMENTS 64 + +/* + The following counts arrays for use with the range decoder are + hard-coded in the Monkey's Audio decoder. +*/ + +static const int counts_3970[65] ICONST_ATTR = +{ + 0,14824,28224,39348,47855,53994,58171,60926, + 62682,63786,64463,64878,65126,65276,65365,65419, + 65450,65469,65480,65487,65491,65493,65494,65495, + 65496,65497,65498,65499,65500,65501,65502,65503, + 65504,65505,65506,65507,65508,65509,65510,65511, + 65512,65513,65514,65515,65516,65517,65518,65519, + 65520,65521,65522,65523,65524,65525,65526,65527, + 65528,65529,65530,65531,65532,65533,65534,65535, + 65536 +}; + +/* counts_diff_3970[i] = counts_3970[i+1] - counts_3970[i] */ +static const int counts_diff_3970[64] ICONST_ATTR = +{ + 14824,13400,11124,8507,6139,4177,2755,1756, + 1104,677,415,248,150,89,54,31, + 19,11,7,4,2,1,1,1, + 1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1 +}; + +static const int counts_3980[65] ICONST_ATTR = +{ + 0,19578,36160,48417,56323,60899,63265,64435, + 64971,65232,65351,65416,65447,65466,65476,65482, + 65485,65488,65490,65491,65492,65493,65494,65495, + 65496,65497,65498,65499,65500,65501,65502,65503, + 65504,65505,65506,65507,65508,65509,65510,65511, + 65512,65513,65514,65515,65516,65517,65518,65519, + 65520,65521,65522,65523,65524,65525,65526,65527, + 65528,65529,65530,65531,65532,65533,65534,65535, + 65536 +}; + +/* counts_diff_3980[i] = counts_3980[i+1] - counts_3980[i] */ + +static const int counts_diff_3980[64] ICONST_ATTR = +{ + 19578,16582,12257,7906,4576,2366,1170,536, + 261,119,65,31,19,10,6,3, + 3,2,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1 +}; + +/* + range_get_symbol_* functions based on main decoding loop in simple_d.c from + http://www.compressconsult.com/rangecoder/rngcod13.zip + (c) Michael Schindler +*/ + +static inline int range_get_symbol_3980(void) +{ + int symbol, cf; + + cf = range_decode_culshift(16); + + /* figure out the symbol inefficiently; a binary search would be much better */ + for (symbol = 0; counts_3980[symbol+1] <= cf; symbol++); + + range_decode_update(counts_diff_3980[symbol],counts_3980[symbol]); + + return symbol; +} + +static inline int range_get_symbol_3970(void) +{ + int symbol, cf; + + cf = range_decode_culshift(16); + + /* figure out the symbol inefficiently; a binary search would be much better */ + for (symbol = 0; counts_3970[symbol+1] <= cf; symbol++); + + range_decode_update(counts_diff_3970[symbol],counts_3970[symbol]); + + return symbol; +} + +/* MAIN DECODING FUNCTIONS */ + +struct rice_t +{ + uint32_t k; + uint32_t ksum; +}; + +static struct rice_t riceX IBSS_ATTR; +static struct rice_t riceY IBSS_ATTR; + +static inline void update_rice(struct rice_t* rice, int x) +{ + rice->ksum += ((x + 1) / 2) - ((rice->ksum + 16) >> 5); + + if (rice->k == 0) { + rice->k = 1; + } else if (rice->ksum < ((uint32_t)1 << (rice->k + 4))) { + rice->k--; + } else if (rice->ksum >= ((uint32_t)1 << (rice->k + 5))) { + rice->k++; + } +} + +static inline int entropy_decode3980(struct rice_t* rice) +{ + int base, x, pivot, overflow; + + pivot = rice->ksum >> 5; + if (pivot == 0) pivot=1; + + overflow = range_get_symbol_3980(); + + if (overflow == (MODEL_ELEMENTS-1)) { + overflow = range_decode_short() << 16; + overflow |= range_decode_short(); + } + + if (pivot >= 0x10000) { + /* Codepath for 24-bit streams */ + int nbits, lo_bits, base_hi, base_lo; + + /* Count the number of bits in pivot */ + nbits = 17; /* We know there must be at least 17 bits */ + while ((pivot >> nbits) > 0) { nbits++; } + + /* base_lo is the low (nbits-16) bits of base + base_hi is the high 16 bits of base + */ + lo_bits = (nbits - 16); + + base_hi = range_decode_culfreq((pivot >> lo_bits) + 1); + range_decode_update(1, base_hi); + + base_lo = range_decode_culfreq(1 << lo_bits); + range_decode_update(1, base_lo); + + base = (base_hi << lo_bits) + base_lo; + } else { + /* Codepath for 16-bit streams */ + base = range_decode_culfreq(pivot); + range_decode_update(1, base); + } + + x = base + (overflow * pivot); + update_rice(rice, x); + + /* Convert to signed */ + if (x & 1) + return (x >> 1) + 1; + else + return -(x >> 1); +} + + +static inline int entropy_decode3970(struct rice_t* rice) +{ + int x, tmpk; + + int overflow = range_get_symbol_3970(); + + if (overflow == (MODEL_ELEMENTS - 1)) { + tmpk = range_decode_bits(5); + overflow = 0; + } else { + tmpk = (rice->k < 1) ? 0 : rice->k - 1; + } + + if (tmpk <= 16) { + x = range_decode_bits(tmpk); + } else { + x = range_decode_short(); + x |= (range_decode_bits(tmpk - 16) << 16); + } + x += (overflow << tmpk); + + update_rice(rice, x); + + /* Convert to signed */ + if (x & 1) + return (x >> 1) + 1; + else + return -(x >> 1); +} + +void init_entropy_decoder(struct ape_ctx_t* ape_ctx, + unsigned char* inbuffer, int* firstbyte, + int* bytesconsumed) +{ + bytebuffer = inbuffer; + bytebufferoffset = *firstbyte; + + /* Read the CRC */ + ape_ctx->CRC = read_byte(); + ape_ctx->CRC = (ape_ctx->CRC << 8) | read_byte(); + ape_ctx->CRC = (ape_ctx->CRC << 8) | read_byte(); + ape_ctx->CRC = (ape_ctx->CRC << 8) | read_byte(); + + /* Read the frame flags if they exist */ + ape_ctx->frameflags = 0; + if ((ape_ctx->fileversion > 3820) && (ape_ctx->CRC & 0x80000000)) { + ape_ctx->CRC &= ~0x80000000; + + ape_ctx->frameflags = read_byte(); + ape_ctx->frameflags = (ape_ctx->frameflags << 8) | read_byte(); + ape_ctx->frameflags = (ape_ctx->frameflags << 8) | read_byte(); + ape_ctx->frameflags = (ape_ctx->frameflags << 8) | read_byte(); + } + /* Keep a count of the blocks decoded in this frame */ + ape_ctx->blocksdecoded = 0; + + /* Initialise the rice structs */ + riceX.k = 10; + riceX.ksum = (1 << riceX.k) * 16; + riceY.k = 10; + riceY.ksum = (1 << riceY.k) * 16; + + /* The first 8 bits of input are ignored. */ + skip_byte(); + + range_start_decoding(); + + /* Return the new state of the buffer */ + *bytesconsumed = (intptr_t)bytebuffer - (intptr_t)inbuffer; + *firstbyte = bytebufferoffset; +} + +int entropy_decode(struct ape_ctx_t* ape_ctx, + unsigned char* inbuffer, int* firstbyte, + int* bytesconsumed, + int32_t* decoded0, int32_t* decoded1, + int blockstodecode) +{ + bytebuffer = inbuffer; + bytebufferoffset = *firstbyte; + + ape_ctx->blocksdecoded += blockstodecode; + + if (ape_ctx->frameflags & APE_FRAMECODE_STEREO_SILENCE) { + /* We are pure silence, just memset the output buffer. */ + memset(decoded0, 0, blockstodecode * sizeof(int32_t)); + memset(decoded1, 0, blockstodecode * sizeof(int32_t)); + } else { + if (ape_ctx->fileversion > 3970) { + while (blockstodecode--) { + *(decoded0++) = entropy_decode3980(&riceY); + if (decoded1 != NULL) + *(decoded1++) = entropy_decode3980(&riceX); + } + } else { + while (blockstodecode--) { + *(decoded0++) = entropy_decode3970(&riceY); + if (decoded1 != NULL) + *(decoded1++) = entropy_decode3970(&riceX); + } + } + } + + if (ape_ctx->blocksdecoded == ape_ctx->currentframeblocks) + { + range_done_decoding(); + } + + /* Return the new state of the buffer */ + *bytesconsumed = bytebuffer - inbuffer; + *firstbyte = bytebufferoffset; + + return(0); +} Index: apps/codecs/libdemac/predictor.h =================================================================== --- apps/codecs/libdemac/predictor.h (revision 0) +++ apps/codecs/libdemac/predictor.h (revision 0) @@ -0,0 +1,34 @@ +/* + +libdemac - A Monkey's Audio decoder + +Copyright (C) Dave Chapman 2007 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA + +*/ + +#ifndef _APE_PREDICTOR_H +#define _APE_PREDICTOR_H + +#include +#include "parser.h" +#include "filter.h" + +void init_predictor_decoder(struct ape_ctx_t* ape_ctx); +int predictor_decode_stereo(struct ape_ctx_t* ape_ctx, int32_t* decoded0, int32_t* decoded1, int count); +int predictor_decode_mono(struct ape_ctx_t* ape_ctx, int32_t* decoded0, int count); + +#endif Index: apps/codecs/libdemac/parser.h =================================================================== --- apps/codecs/libdemac/parser.h (revision 0) +++ apps/codecs/libdemac/parser.h (revision 0) @@ -0,0 +1,135 @@ +/* + +libdemac - A Monkey's Audio decoder + +Copyright (C) Dave Chapman 2007 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA + +*/ + +#ifndef _APE_PARSER_H +#define _APE_PARSER_H + +#include + +#ifdef ROCKBOX +/* Include the Rockbox Codec API when building for Rockbox */ +#define APE_OUTPUT_DEPTH 29 +#ifndef ROCKBOX_PLUGIN +#include "../lib/codeclib.h" +#include +#endif +#else +#define APE_OUTPUT_DEPTH (ape_ctx->bps) +#define IBSS_ATTR +#define ICONST_ATTR +#define ICODE_ATTR +#endif + +/* The earliest and latest file formats supported by this library */ +#define APE_MIN_VERSION 3970 +#define APE_MAX_VERSION 3990 + +#define MAC_FORMAT_FLAG_8_BIT 1 // is 8-bit [OBSOLETE] +#define MAC_FORMAT_FLAG_CRC 2 // uses the new CRC32 error detection [OBSOLETE] +#define MAC_FORMAT_FLAG_HAS_PEAK_LEVEL 4 // uint32 nPeakLevel after the header [OBSOLETE] +#define MAC_FORMAT_FLAG_24_BIT 8 // is 24-bit [OBSOLETE] +#define MAC_FORMAT_FLAG_HAS_SEEK_ELEMENTS 16 // has the number of seek elements after the peak level +#define MAC_FORMAT_FLAG_CREATE_WAV_HEADER 32 // create the wave header on decompression (not stored) + + +/* Special frame codes: + + MONO_SILENCE - All PCM samples in frame are zero (mono streams only) + LEFT_SILENCE - All PCM samples for left channel in frame are zero (stereo streams) + RIGHT_SILENCE - All PCM samples for left channel in frame are zero (stereo streams) + PSEUDO_STEREO - Left and Right channels are identical + +*/ + +#define APE_FRAMECODE_MONO_SILENCE 1 +#define APE_FRAMECODE_STEREO_SILENCE 3 +#define APE_FRAMECODE_PSEUDO_STEREO 4 + +#define HISTORY_SIZE 512 +#define PREDICTOR_ORDER 8 + +struct predictor_t +{ + /* Adaption co-efficients */ + int32_t coeffsA[4]; + int32_t coeffsB[5]; + + /* Filter histories */ + int32_t historybuffer[HISTORY_SIZE + PREDICTOR_ORDER * 4]; + int32_t* delayA; + int32_t* delayB; + int32_t* adaptcoeffsA; + int32_t* adaptcoeffsB; + + int32_t lastA; + + int32_t filterA; + int32_t filterB; +}; + +struct ape_ctx_t +{ + /* Derived fields */ + uint32_t junklength; + uint32_t firstframe; + uint32_t totalsamples; + + /* Info from Descriptor Block */ + char magic[4]; + int16_t fileversion; + int16_t padding1; + uint32_t descriptorlength; + uint32_t headerlength; + uint32_t seektablelength; + uint32_t wavheaderlength; + uint32_t audiodatalength; + uint32_t audiodatalength_high; + uint32_t wavtaillength; + uint8_t md5[16]; + + /* Info from Header Block */ + uint16_t compressiontype; + uint16_t formatflags; + uint32_t blocksperframe; + uint32_t finalframeblocks; + uint32_t totalframes; + uint16_t bps; + uint16_t channels; + uint32_t samplerate; + + /* Seektable */ + uint32_t* seektable; + + /* Decoder state */ + uint32_t CRC; + int frameflags; + int currentframeblocks; + int blocksdecoded; + struct predictor_t predictorY; + struct predictor_t predictorX; +}; + +int ape_parseheader(int fd, struct ape_ctx_t* ape_ctx); +int ape_parseheaderbuf(unsigned char* buf, struct ape_ctx_t* ape_ctx); +void ape_dumpinfo(struct ape_ctx_t* ape_ctx); + +#endif Index: apps/codecs/libdemac/SOURCES =================================================================== --- apps/codecs/libdemac/SOURCES (revision 0) +++ apps/codecs/libdemac/SOURCES (revision 0) @@ -0,0 +1,10 @@ +crc.c +predictor.c +entropy.c +decoder.c +parser.c +filter_1280_15.c +filter_16_11.c +filter_256_13.c +filter_32_10.c +filter_64_11.c Index: apps/codecs/libdemac/filter_1280_15.c =================================================================== --- apps/codecs/libdemac/filter_1280_15.c (revision 0) +++ apps/codecs/libdemac/filter_1280_15.c (revision 0) @@ -0,0 +1,25 @@ +/* + +libdemac - A Monkey's Audio decoder + +Copyright (C) Dave Chapman 2007 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA + +*/ + +#define ORDER 1280 +#define FRACBITS 15 +#include "filter.c" Index: apps/codecs/libdemac/decoder.c =================================================================== --- apps/codecs/libdemac/decoder.c (revision 0) +++ apps/codecs/libdemac/decoder.c (revision 0) @@ -0,0 +1,182 @@ +/* + +libdemac - A Monkey's Audio decoder + +Copyright (C) Dave Chapman 2007 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA + +*/ + +#include +#include + +#include "demac.h" +#include "predictor.h" +#include "entropy.h" +#include "filter.h" + +/* Statically allocate the filter buffers */ + +static int16_t filterbuf32[(32*3 + HISTORY_SIZE) * 2] IBSS_ATTR; /* 4480 bytes */ +static int16_t filterbuf256[(256*3 + HISTORY_SIZE) * 2] IBSS_ATTR; /* 5120 bytes */ + +/* This is only needed for "insane" files, and no Rockbox targets can + hope to decode them in realtime anyway. */ +static int16_t filterbuf1280[(1280*3 + HISTORY_SIZE) * 2]; /* 17408 bytes */ + +void init_frame_decoder(struct ape_ctx_t* ape_ctx, + unsigned char* inbuffer, int* firstbyte, + int* bytesconsumed) +{ + init_entropy_decoder(ape_ctx, inbuffer, firstbyte, bytesconsumed); + //printf("CRC=0x%08x\n",ape_ctx->CRC); + //printf("Flags=0x%08x\n",ape_ctx->frameflags); + + init_predictor_decoder(ape_ctx); + + switch (ape_ctx->compressiontype) + { + case 2000: + init_filter_16_11(filterbuf32); + break; + + case 3000: + init_filter_64_11(filterbuf256); + break; + + case 4000: + init_filter_256_13(filterbuf256); + init_filter_32_10(filterbuf32); + break; + + case 5000: + init_filter_1280_15(filterbuf1280); + init_filter_256_13(filterbuf256); + init_filter_16_11(filterbuf32); + } +} + +int decode_chunk(struct ape_ctx_t* ape_ctx, + unsigned char* inbuffer, int* firstbyte, + int* bytesconsumed, + int32_t* decoded0, int32_t* decoded1, + int count) +{ + int res; + int32_t left, right; +#ifdef ROCKBOX + int scale = (APE_OUTPUT_DEPTH - ape_ctx->bps); + #define SCALE(x) ((x) << scale) +#else + #define SCALE(x) (x) +#endif + + if ((ape_ctx->channels==1) || (ape_ctx->frameflags & APE_FRAMECODE_PSEUDO_STEREO)) { + if (ape_ctx->frameflags & APE_FRAMECODE_STEREO_SILENCE) { + res = entropy_decode(ape_ctx, inbuffer, firstbyte, bytesconsumed, decoded0, decoded1, count); + /* We are pure silence, so we're done. */ + return 0; + } else { + res = entropy_decode(ape_ctx, inbuffer, firstbyte, bytesconsumed, decoded0, NULL, count); + } + + switch (ape_ctx->compressiontype) + { + case 2000: + apply_filter_16_11(ape_ctx->fileversion,decoded0,NULL,count); + break; + + case 3000: + apply_filter_64_11(ape_ctx->fileversion,decoded0,NULL,count); + break; + + case 4000: + apply_filter_32_10(ape_ctx->fileversion,decoded0,NULL,count); + apply_filter_256_13(ape_ctx->fileversion,decoded0,NULL,count); + break; + + case 5000: + apply_filter_16_11(ape_ctx->fileversion,decoded0,NULL,count); + apply_filter_256_13(ape_ctx->fileversion,decoded0,NULL,count); + apply_filter_1280_15(ape_ctx->fileversion,decoded0,NULL,count); + } + + /* Now apply the predictor decoding */ + predictor_decode_mono(ape_ctx,decoded0,count); + + if (ape_ctx->channels==2) { + /* Pseudo-stereo - just copy left channel to right channel */ + while (count--) + { + left = *decoded0; + *(decoded1++) = *(decoded0++) = SCALE(left); + } + } else { + /* Mono - do nothing unless it's 8-bit audio */ + if (ape_ctx->bps == 8) { + /* TODO: Handle 8-bit streams */ + } + } + } else { /* Stereo */ + if (ape_ctx->frameflags & APE_FRAMECODE_STEREO_SILENCE) { + /* We are pure silence, so we're done. */ + return 0; + } + + res = entropy_decode(ape_ctx, inbuffer, firstbyte, bytesconsumed, decoded0, decoded1, count); + + /* Apply filters - compression type 1000 doesn't have any */ + switch (ape_ctx->compressiontype) + { + case 2000: + apply_filter_16_11(ape_ctx->fileversion,decoded0,decoded1,count); + break; + + case 3000: + apply_filter_64_11(ape_ctx->fileversion,decoded0,decoded1,count); + break; + + case 4000: + apply_filter_32_10(ape_ctx->fileversion,decoded0,decoded1,count); + apply_filter_256_13(ape_ctx->fileversion,decoded0,decoded1,count); + break; + + case 5000: + apply_filter_16_11(ape_ctx->fileversion,decoded0,decoded1,count); + apply_filter_256_13(ape_ctx->fileversion,decoded0,decoded1,count); + apply_filter_1280_15(ape_ctx->fileversion,decoded0,decoded1,count); + } + + /* Now apply the predictor decoding */ + predictor_decode_stereo(ape_ctx,decoded0,decoded1,count); + + if (ape_ctx->bps == 8) { + /* TODO: Handle 8-bit streams */ + } else { + /* Decorrelate and scale to output depth */ + while (count--) + { + left = *decoded1 - (*decoded0 / 2); + right = left + *decoded0; + + *(decoded0++) = SCALE(left); + *(decoded1++) = SCALE(right); + } + } + } + + return res; +} Index: apps/codecs/libdemac/entropy.h =================================================================== --- apps/codecs/libdemac/entropy.h (revision 0) +++ apps/codecs/libdemac/entropy.h (revision 0) @@ -0,0 +1,38 @@ +/* + +libdemac - A Monkey's Audio decoder + +Copyright (C) Dave Chapman 2007 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA + +*/ + +#ifndef _APE_ENTROPY_H +#define _APE_ENTROPY_H + +#include + +void init_entropy_decoder(struct ape_ctx_t* ape_ctx, + unsigned char* inbuffer, int* firstbyte, + int* bytesconsumed); + +int entropy_decode(struct ape_ctx_t* ape_ctx, + unsigned char* inbuffer, int* firstbyte, + int* bytesconsumed, + int32_t* decoded0, int32_t* decoded1, + int blockstodecode); + +#endif Index: apps/codecs/libdemac/crc.c =================================================================== --- apps/codecs/libdemac/crc.c (revision 0) +++ apps/codecs/libdemac/crc.c (revision 0) @@ -0,0 +1,117 @@ +/* + +libdemac - A Monkey's Audio decoder + +Copyright (C) Dave Chapman 2007 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA + +*/ + +#include + +static uint32_t crctab32[] = +{ + 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, + 0x076DC419, 0x706AF48F, 0xE963A535, 0x9E6495A3, + 0x0EDB8832, 0x79DCB8A4, 0xE0D5E91E, 0x97D2D988, + 0x09B64C2B, 0x7EB17CBD, 0xE7B82D07, 0x90BF1D91, + 0x1DB71064, 0x6AB020F2, 0xF3B97148, 0x84BE41DE, + 0x1ADAD47D, 0x6DDDE4EB, 0xF4D4B551, 0x83D385C7, + 0x136C9856, 0x646BA8C0, 0xFD62F97A, 0x8A65C9EC, + 0x14015C4F, 0x63066CD9, 0xFA0F3D63, 0x8D080DF5, + 0x3B6E20C8, 0x4C69105E, 0xD56041E4, 0xA2677172, + 0x3C03E4D1, 0x4B04D447, 0xD20D85FD, 0xA50AB56B, + 0x35B5A8FA, 0x42B2986C, 0xDBBBC9D6, 0xACBCF940, + 0x32D86CE3, 0x45DF5C75, 0xDCD60DCF, 0xABD13D59, + 0x26D930AC, 0x51DE003A, 0xC8D75180, 0xBFD06116, + 0x21B4F4B5, 0x56B3C423, 0xCFBA9599, 0xB8BDA50F, + 0x2802B89E, 0x5F058808, 0xC60CD9B2, 0xB10BE924, + 0x2F6F7C87, 0x58684C11, 0xC1611DAB, 0xB6662D3D, + + 0x76DC4190, 0x01DB7106, 0x98D220BC, 0xEFD5102A, + 0x71B18589, 0x06B6B51F, 0x9FBFE4A5, 0xE8B8D433, + 0x7807C9A2, 0x0F00F934, 0x9609A88E, 0xE10E9818, + 0x7F6A0DBB, 0x086D3D2D, 0x91646C97, 0xE6635C01, + 0x6B6B51F4, 0x1C6C6162, 0x856530D8, 0xF262004E, + 0x6C0695ED, 0x1B01A57B, 0x8208F4C1, 0xF50FC457, + 0x65B0D9C6, 0x12B7E950, 0x8BBEB8EA, 0xFCB9887C, + 0x62DD1DDF, 0x15DA2D49, 0x8CD37CF3, 0xFBD44C65, + 0x4DB26158, 0x3AB551CE, 0xA3BC0074, 0xD4BB30E2, + 0x4ADFA541, 0x3DD895D7, 0xA4D1C46D, 0xD3D6F4FB, + 0x4369E96A, 0x346ED9FC, 0xAD678846, 0xDA60B8D0, + 0x44042D73, 0x33031DE5, 0xAA0A4C5F, 0xDD0D7CC9, + 0x5005713C, 0x270241AA, 0xBE0B1010, 0xC90C2086, + 0x5768B525, 0x206F85B3, 0xB966D409, 0xCE61E49F, + 0x5EDEF90E, 0x29D9C998, 0xB0D09822, 0xC7D7A8B4, + 0x59B33D17, 0x2EB40D81, 0xB7BD5C3B, 0xC0BA6CAD, + + 0xEDB88320, 0x9ABFB3B6, 0x03B6E20C, 0x74B1D29A, + 0xEAD54739, 0x9DD277AF, 0x04DB2615, 0x73DC1683, + 0xE3630B12, 0x94643B84, 0x0D6D6A3E, 0x7A6A5AA8, + 0xE40ECF0B, 0x9309FF9D, 0x0A00AE27, 0x7D079EB1, + 0xF00F9344, 0x8708A3D2, 0x1E01F268, 0x6906C2FE, + 0xF762575D, 0x806567CB, 0x196C3671, 0x6E6B06E7, + 0xFED41B76, 0x89D32BE0, 0x10DA7A5A, 0x67DD4ACC, + 0xF9B9DF6F, 0x8EBEEFF9, 0x17B7BE43, 0x60B08ED5, + 0xD6D6A3E8, 0xA1D1937E, 0x38D8C2C4, 0x4FDFF252, + 0xD1BB67F1, 0xA6BC5767, 0x3FB506DD, 0x48B2364B, + 0xD80D2BDA, 0xAF0A1B4C, 0x36034AF6, 0x41047A60, + 0xDF60EFC3, 0xA867DF55, 0x316E8EEF, 0x4669BE79, + 0xCB61B38C, 0xBC66831A, 0x256FD2A0, 0x5268E236, + 0xCC0C7795, 0xBB0B4703, 0x220216B9, 0x5505262F, + 0xC5BA3BBE, 0xB2BD0B28, 0x2BB45A92, 0x5CB36A04, + 0xC2D7FFA7, 0xB5D0CF31, 0x2CD99E8B, 0x5BDEAE1D, + + 0x9B64C2B0, 0xEC63F226, 0x756AA39C, 0x026D930A, + 0x9C0906A9, 0xEB0E363F, 0x72076785, 0x05005713, + 0x95BF4A82, 0xE2B87A14, 0x7BB12BAE, 0x0CB61B38, + 0x92D28E9B, 0xE5D5BE0D, 0x7CDCEFB7, 0x0BDBDF21, + 0x86D3D2D4, 0xF1D4E242, 0x68DDB3F8, 0x1FDA836E, + 0x81BE16CD, 0xF6B9265B, 0x6FB077E1, 0x18B74777, + 0x88085AE6, 0xFF0F6A70, 0x66063BCA, 0x11010B5C, + 0x8F659EFF, 0xF862AE69, 0x616BFFD3, 0x166CCF45, + 0xA00AE278, 0xD70DD2EE, 0x4E048354, 0x3903B3C2, + 0xA7672661, 0xD06016F7, 0x4969474D, 0x3E6E77DB, + 0xAED16A4A, 0xD9D65ADC, 0x40DF0B66, 0x37D83BF0, + 0xA9BCAE53, 0xDEBB9EC5, 0x47B2CF7F, 0x30B5FFE9, + 0xBDBDF21C, 0xCABAC28A, 0x53B39330, 0x24B4A3A6, + 0xBAD03605, 0xCDD70693, 0x54DE5729, 0x23D967BF, + 0xB3667A2E, 0xC4614AB8, 0x5D681B02, 0x2A6F2B94, + 0xB40BBE37, 0xC30C8EA1, 0x5A05DF1B, 0x2D02EF8D +}; + +uint32_t ape_initcrc(void) +{ + return 0xffffffff; +} + +/* Update the CRC from a block of WAV-format audio data */ +uint32_t ape_updatecrc(unsigned char *block, int count, uint32_t crc) +{ + while (count--) + crc = (crc >> 8) ^ crctab32[(crc & 0xff) ^ *block++]; + + return crc; +} + +uint32_t ape_finishcrc(uint32_t crc) +{ + crc ^= 0xffffffff; + crc >>= 1; + + return crc; +} + Index: apps/codecs/libdemac/decoder.h =================================================================== --- apps/codecs/libdemac/decoder.h (revision 0) +++ apps/codecs/libdemac/decoder.h (revision 0) @@ -0,0 +1,38 @@ +/* + +libdemac - A Monkey's Audio decoder + +Copyright (C) Dave Chapman 2007 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA + +*/ + +#ifndef _APE_DECODER_H +#define _APE_DECODER_H + +#include +#include "parser.h" + +void init_frame_decoder(struct ape_ctx_t* ape_ctx, + unsigned char* inbuffer, int* firstbyte, + int* bytesconsumed); + +int decode_chunk(struct ape_ctx_t* ape_ctx, + unsigned char* inbuffer, int* firstbyte, + int* bytesconsumed, + int32_t* decoded0, int32_t* decoded1, + int count); +#endif Index: apps/codecs/libdemac/demac.h =================================================================== --- apps/codecs/libdemac/demac.h (revision 0) +++ apps/codecs/libdemac/demac.h (revision 0) @@ -0,0 +1,43 @@ +/* + +libdemac - A Monkey's Audio decoder + +Copyright (C) Dave Chapman 2007 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA + +*/ + +#ifndef _APE_DECODER_H +#define _APE_DECODER_H + +#include +#include "parser.h" + +void init_frame_decoder(struct ape_ctx_t* ape_ctx, + unsigned char* inbuffer, int* firstbyte, + int* bytesconsumed); + +int decode_chunk(struct ape_ctx_t* ape_ctx, + unsigned char* inbuffer, int* firstbyte, + int* bytesconsumed, + int32_t* decoded0, int32_t* decoded1, + int count); + +uint32_t ape_initcrc(void); +uint32_t ape_updatecrc(unsigned char *block, int count, uint32_t crc); +uint32_t ape_finishcrc(uint32_t crc); + +#endif Index: apps/codecs/libdemac/filter_256_13.c =================================================================== --- apps/codecs/libdemac/filter_256_13.c (revision 0) +++ apps/codecs/libdemac/filter_256_13.c (revision 0) @@ -0,0 +1,25 @@ +/* + +libdemac - A Monkey's Audio decoder + +Copyright (C) Dave Chapman 2007 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA + +*/ + +#define ORDER 256 +#define FRACBITS 13 +#include "filter.c" Index: apps/codecs/libdemac/vector_math32.h =================================================================== --- apps/codecs/libdemac/vector_math32.h (revision 0) +++ apps/codecs/libdemac/vector_math32.h (revision 0) @@ -0,0 +1,52 @@ +/* + +libdemac - A Monkey's Audio decoder + +Copyright (C) Dave Chapman 2007 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA + +*/ + +/* 32-bit vector math functions */ + +#define scalarproduct4_rev32(x,y) ((x[0] * y[0]) + (x[1] * y[-1]) + \ + (x[2] * y[-2]) + (x[3] * y[-3])) + +#define scalarproduct5_rev32(x,y) ((x[0] * y[0]) + (x[1] * y[-1]) + \ + (x[2] * y[-2]) + (x[3] * y[-3]) + \ + (x[4] * y[-4])) + +#define vector_sub4_rev32(x, y) { x[0] -= y[0]; \ + x[1] -= y[-1]; \ + x[2] -= y[-2]; \ + x[3] -= y[-3]; } + +#define vector_sub5_rev32(x, y) { x[0] -= y[0]; \ + x[1] -= y[-1]; \ + x[2] -= y[-2]; \ + x[3] -= y[-3]; \ + x[4] -= y[-4]; } + +#define vector_add4_rev32(x, y) { x[0] += y[0]; \ + x[1] += y[-1]; \ + x[2] += y[-2]; \ + x[3] += y[-3]; } + +#define vector_add5_rev32(x, y) { x[0] += y[0]; \ + x[1] += y[-1]; \ + x[2] += y[-2]; \ + x[3] += y[-3]; \ + x[4] += y[-4]; } Index: apps/codecs/libdemac/filter.c =================================================================== --- apps/codecs/libdemac/filter.c (revision 0) +++ apps/codecs/libdemac/filter.c (revision 0) @@ -0,0 +1,213 @@ +/* + +libdemac - A Monkey's Audio decoder + +Copyright (C) Dave Chapman 2007 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA + +*/ + +#include +#include + +#include "demac.h" +#include "filter.h" + +#include "vector_math16.h" + +struct filter_t { + int16_t* coeffs; /* ORDER entries */ + + /* We store all the filter delays in a single buffer */ + int16_t* historybuffer; /* ORDER*2 + HISTORY_SIZE entries */ + + int16_t* delay; + int16_t* adaptcoeffs; + + int avg; +}; + +/* We name the functions according to the ORDER and FRACBITS + pre-processor symbols and build multiple .o files from this .c file + - this increases code-size but gives the compiler more scope for + optimising the individual functions, as well as replacing a lot of + variables with constants. +*/ + +#if FRACBITS == 11 + #if ORDER == 16 + #define INIT_FILTER init_filter_16_11 + #define APPLY_FILTER apply_filter_16_11 + #elif ORDER == 64 + #define INIT_FILTER init_filter_64_11 + #define APPLY_FILTER apply_filter_64_11 + #endif +#elif FRACBITS == 13 + #define INIT_FILTER init_filter_256_13 + #define APPLY_FILTER apply_filter_256_13 +#elif FRACBITS == 10 + #define INIT_FILTER init_filter_32_10 + #define APPLY_FILTER apply_filter_32_10 +#elif FRACBITS == 15 + #define INIT_FILTER init_filter_1280_15 + #define APPLY_FILTER apply_filter_1280_15 +#endif + +/* Some macros to handle the fixed-point stuff */ + +#define FP_HALF (1 << (FRACBITS - 1)) /* 0.5 in fixed-point format. */ +#define FP_TO_INT(x) ((x + FP_HALF) >> FRACBITS); /* round(x) */ + +#define SATURATE(x) (int16_t)(((x) == (int16_t)(x)) ? (x) : ((x) >> 31) ^ 0x7FFF); + +/* Apply the filter with state f to count entries in data[] */ + +static inline void do_apply_filter_3980(struct filter_t* f, int32_t* data, int count) +{ + int res; + int absres; + + while(count--) + { + res = FP_TO_INT(scalarproduct(f->delay - ORDER, f->coeffs)); + + if (*data < 0) + vector_add(f->coeffs, f->adaptcoeffs - ORDER); + else if (*data > 0) + vector_sub(f->coeffs, f->adaptcoeffs - ORDER); + + /* Convert res from (32-FRACBITS).FRACBITS fixed-point format to an + integer (rounding to nearest) and add the input value to + it */ + res += *data; + + *data++ = res; + + /* Update the output history */ + *f->delay++ = SATURATE(res); + + /* Version 3.98 and later files */ + + /* Update the adaption coefficients */ + absres = (res < 0 ? -res : res); + + if (absres > (f->avg * 3)) + *f->adaptcoeffs = ((res >> 25) & 64) - 32; + else if (absres > (f->avg * 4) / 3) + *f->adaptcoeffs = ((res >> 26) & 32) - 16; + else if (absres > 0) + *f->adaptcoeffs = ((res >> 27) & 16) - 8; + else + *f->adaptcoeffs = 0; + + f->avg += (absres - f->avg) / 16; + + f->adaptcoeffs[-1] >>= 1; + f->adaptcoeffs[-2] >>= 1; + f->adaptcoeffs[-8] >>= 1; + + f->adaptcoeffs++; + + /* Have we filled the history buffer? */ + if (f->delay == f->historybuffer + HISTORY_SIZE + (ORDER*2)) { + memmove(f->historybuffer, f->delay - (ORDER*2), + (ORDER*2) * sizeof(int16_t)); + f->delay = f->historybuffer + ORDER*2; + f->adaptcoeffs = f->historybuffer + ORDER; + } + } +} + +static inline void do_apply_filter_3970(struct filter_t* f, int32_t* data, int count) +{ + int res; + + while(count--) + { + res = FP_TO_INT(scalarproduct(f->delay - ORDER, f->coeffs)); + + if (*data < 0) + vector_add(f->coeffs, f->adaptcoeffs - ORDER); + else if (*data > 0) + vector_sub(f->coeffs, f->adaptcoeffs - ORDER); + + /* Convert res from (32-FRACBITS).FRACBITS fixed-point format to an + integer (rounding to nearest) and add the input value to + it */ + res += *data; + + *data++ = res; + + /* Update the output history */ + *f->delay++ = SATURATE(res); + + /* Version ??? to < 3.98 files (untested) */ + f->adaptcoeffs[0] = (res == 0) ? 0 : ((res >> 28) & 8) - 4; + f->adaptcoeffs[-4] >>= 1; + f->adaptcoeffs[-8] >>= 1; + + f->adaptcoeffs++; + + /* Have we filled the history buffer? */ + if (f->delay == f->historybuffer + HISTORY_SIZE + (ORDER*2)) { + memmove(f->historybuffer, f->delay - (ORDER*2), + (ORDER*2) * sizeof(int16_t)); + f->delay = f->historybuffer + ORDER*2; + f->adaptcoeffs = f->historybuffer + ORDER; + } + } +} + +static struct filter_t filter0 IBSS_ATTR; +static struct filter_t filter1 IBSS_ATTR; + +static void do_init_filter(struct filter_t* f, int16_t* buf) +{ + f->coeffs = buf; + f->historybuffer = buf + ORDER; + + /* Zero the output history buffer */ + memset(f->historybuffer, 0 , (ORDER*2) * sizeof(int16_t)); + f->delay = f->historybuffer + ORDER*2; + f->adaptcoeffs = f->historybuffer + ORDER; + + /* Zero the co-efficients */ + memset(f->coeffs, 0, ORDER * sizeof(int16_t)); + + /* Zero the running average */ + f->avg = 0; +} + +void INIT_FILTER(int16_t* buf) +{ + do_init_filter(&filter0, buf); + do_init_filter(&filter1, buf + ORDER * 3 + HISTORY_SIZE); +} + +int APPLY_FILTER(int fileversion, int32_t* data0, int32_t* data1, int count) +{ + if (fileversion >= 3980) { + do_apply_filter_3980(&filter0, data0, count); + if (data1 != NULL) + do_apply_filter_3980(&filter1, data1, count); + } else { + do_apply_filter_3970(&filter0, data0, count); + if (data1 != NULL) + do_apply_filter_3970(&filter1, data1, count); + } + + return 0; +} Index: apps/codecs/libdemac/rangecoding.h =================================================================== --- apps/codecs/libdemac/rangecoding.h (revision 0) +++ apps/codecs/libdemac/rangecoding.h (revision 0) @@ -0,0 +1,178 @@ +/* + +libdemac - A Monkey's Audio decoder + +Copyright (C) Dave Chapman 2007 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA + +*/ + +/* + +Range decoder adapted from rangecod.c included in: + + http://www.compressconsult.com/rangecoder/rngcod13.zip + + rangecod.c range encoding + + (c) Michael Schindler + 1997, 1998, 1999, 2000 + http://www.compressconsult.com/ + michael@compressconsult.com + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + +The encoding functions were removed, and functions turned into "static +inline" functions and moved to a .h file. Some minor cosmetic changes +were made (e.g. turning pre-processor symbols into upper-case, +removing the rc parameter from each function (and the RNGC macro)). + + +*/ + + +/* BITSTREAM READING FUNCTIONS */ + +/* We deal with the input data one byte at a time - to ensure + functionality on CPUs of any endianness regardless of any requirements + for aligned reads. +*/ + +static unsigned char* bytebuffer IBSS_ATTR; +static int bytebufferoffset IBSS_ATTR; + +static inline void skip_byte(void) +{ + if (bytebufferoffset) { + bytebufferoffset--; + } else { + bytebufferoffset = 3; + bytebuffer += 4; + } +} + +static inline int read_byte(void) +{ + int ch = bytebuffer[bytebufferoffset]; + + skip_byte(); + + return ch; +} + +/* RANGE DECODING FUNCTIONS */ + +/* SIZE OF RANGE ENCODING CODE VALUES. */ + +#define CODE_BITS 32 +#define TOP_VALUE ((unsigned int)1 << (CODE_BITS-1)) +#define SHIFT_BITS (CODE_BITS - 9) +#define EXTRA_BITS ((CODE_BITS-2) % 8 + 1) +#define BOTTOM_VALUE (TOP_VALUE >> 8) + +struct rangecoder_t +{ + uint32_t low; /* low end of interval */ + uint32_t range; /* length of interval */ + uint32_t help; /* bytes_to_follow resp. intermediate value */ + unsigned int buffer; /* buffer for input/output */ +}; + +static struct rangecoder_t rc; + +/* Start the decoder */ +static inline void range_start_decoding(void) +{ + rc.buffer = read_byte(); + rc.low = rc.buffer >> (8 - EXTRA_BITS); + rc.range = (uint32_t) 1 << EXTRA_BITS; +} + +static inline void range_dec_normalize(void) +{ + while (rc.range <= BOTTOM_VALUE) + { + rc.buffer = (rc.buffer << 8) | read_byte(); + rc.low = (rc.low << 8) | ((rc.buffer >> 1) & 0xff); + rc.range <<= 8; + } +} + +/* Calculate culmulative frequency for next symbol. Does NO update!*/ +/* tot_f is the total frequency */ +/* or: totf is (code_value)1<>shift; + tmp = rc.low/rc.help; + return tmp; +} + + +/* Update decoding state */ +/* sy_f is the interval length (frequency of the symbol) */ +/* lt_f is the lower end (frequency sum of < symbols) */ +static inline void range_decode_update(int sy_f, int lt_f) +{ int tmp; + tmp = rc.help * lt_f; + rc.low -= tmp; + rc.range = rc.help * sy_f; +} + + +/* Decode a byte/short without modelling */ +static inline unsigned char decode_byte(void) +{ int tmp = range_decode_culshift(8); + range_decode_update( 1,tmp); + return tmp; +} + +static inline int short range_decode_short(void) +{ int tmp = range_decode_culshift(16); + range_decode_update( 1,tmp); + return tmp; +} + +/* Decode n bits (n <= 16) without modelling - based on range_decode_short */ +static inline int range_decode_bits(int n) +{ int tmp = range_decode_culshift(n); + range_decode_update( 1,tmp); + return tmp; +} + + +/* Finish decoding */ +static inline void range_done_decoding(void) +{ range_dec_normalize(); /* normalize to use up all bytes */ +} Index: apps/codecs/libdemac/vector_math16.h =================================================================== --- apps/codecs/libdemac/vector_math16.h (revision 0) +++ apps/codecs/libdemac/vector_math16.h (revision 0) @@ -0,0 +1,138 @@ +/* + +libdemac - A Monkey's Audio decoder + +Copyright (C) Dave Chapman 2007 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA + +*/ + +static inline void vector_add(int16_t* v1, int16_t* v2) +{ +#if ORDER > 32 + int order = (ORDER >> 5); + while (order--) +#endif + { + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; +#if ORDER > 16 + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; + *v1++ += *v2++; +#endif + } +} + +static inline void vector_sub(int16_t* v1, int16_t* v2) +{ +#if ORDER > 32 + int order = (ORDER >> 5); + while (order--) +#endif + { + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; +#if ORDER > 16 + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; + *v1++ -= *v2++; +#endif + } +} + +static inline int32_t scalarproduct(int16_t* v1, int16_t* v2) +{ + int res = 0; + +#if ORDER > 16 + int order = (ORDER >> 4); + while (order--) +#endif + { + res += *v1++ * *v2++; + res += *v1++ * *v2++; + res += *v1++ * *v2++; + res += *v1++ * *v2++; + res += *v1++ * *v2++; + res += *v1++ * *v2++; + res += *v1++ * *v2++; + res += *v1++ * *v2++; + res += *v1++ * *v2++; + res += *v1++ * *v2++; + res += *v1++ * *v2++; + res += *v1++ * *v2++; + res += *v1++ * *v2++; + res += *v1++ * *v2++; + res += *v1++ * *v2++; + res += *v1++ * *v2++; + } + return res; +} Index: apps/codecs/libdemac/filter_32_10.c =================================================================== --- apps/codecs/libdemac/filter_32_10.c (revision 0) +++ apps/codecs/libdemac/filter_32_10.c (revision 0) @@ -0,0 +1,25 @@ +/* + +libdemac - A Monkey's Audio decoder + +Copyright (C) Dave Chapman 2007 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA + +*/ + +#define ORDER 32 +#define FRACBITS 10 +#include "filter.c" Index: apps/codecs/libdemac/filter.h =================================================================== --- apps/codecs/libdemac/filter.h (revision 0) +++ apps/codecs/libdemac/filter.h (revision 0) @@ -0,0 +1,46 @@ +/* + +libdemac - A Monkey's Audio decoder + +Copyright (C) Dave Chapman 2007 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA + +*/ + +#ifndef _APE_FILTER_H +#define _APE_FILTER_H + +#include + +/* The size of the history buffers */ +#define HISTORY_SIZE 512 + +void init_filter_16_11(int16_t* buf); +int apply_filter_16_11(int fileversion, int32_t* decoded0, int32_t* decoded1, int count); + +void init_filter_64_11(int16_t* buf); +int apply_filter_64_11(int fileversion, int32_t* decoded0, int32_t* decoded1, int count); + +void init_filter_32_10(int16_t* buf); +int apply_filter_32_10(int fileversion, int32_t* decoded0, int32_t* decoded1, int count); + +void init_filter_256_13(int16_t* buf); +int apply_filter_256_13(int fileversion, int32_t* decoded0, int32_t* decoded1, int count); + +void init_filter_1280_15(int16_t* buf); +int apply_filter_1280_15(int fileversion, int32_t* decoded0, int32_t* decoded1, int count); + +#endif Index: apps/codecs/libdemac/predictor.c =================================================================== --- apps/codecs/libdemac/predictor.c (revision 0) +++ apps/codecs/libdemac/predictor.c (revision 0) @@ -0,0 +1,194 @@ +/* + +libdemac - A Monkey's Audio decoder + +Copyright (C) Dave Chapman 2007 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA + +*/ + +#include +#include + +#include "parser.h" +#include "predictor.h" + +#include "vector_math32.h" + +/* Return 0 if x is zero, -1 if x is positive, 1 if x is negative */ +#define SIGN(x) (x) ? (((x) > 0) ? -1 : 1) : 0 + +static const int32_t initial_coeffs[4] = { + 360, 317, -109, 98 +}; + +static void init_predictor(struct predictor_t* p) +{ + /* Zero the history buffers */ + memset(p->historybuffer, 0, (PREDICTOR_ORDER*4) * sizeof(int32_t)); + p->delayA = p->historybuffer + PREDICTOR_ORDER*4; + p->delayB = p->historybuffer + PREDICTOR_ORDER*3; + p->adaptcoeffsA = p->historybuffer + PREDICTOR_ORDER*2; + p->adaptcoeffsB = p->historybuffer + PREDICTOR_ORDER; + + /* Initialise and zero the co-efficients */ + memcpy(p->coeffsA, initial_coeffs, sizeof(initial_coeffs)); + memset(p->coeffsB, 0, sizeof(p->coeffsB)); + + p->filterA = 0; + p->filterB = 0; + + p->lastA = 0; +} + +static int do_predictor_decode(struct predictor_t* p, int32_t A, int32_t nB) +{ + int32_t predictionA, predictionB, currentA; + + p->delayA[0] = p->lastA; + p->delayA[-1] = p->delayA[0] - p->delayA[-1]; + + predictionA = scalarproduct4_rev32(p->coeffsA,p->delayA); + + /* Apply a scaled first-order filter compression */ + p->delayB[0] = nB - ((p->filterB * 31) >> 5); + p->filterB = nB; + + p->delayB[-1] = p->delayB[0] - p->delayB[-1]; + + predictionB = scalarproduct5_rev32(p->coeffsB,p->delayB); + + currentA = A + ((predictionA + (predictionB >> 1)) >> 10); + + p->adaptcoeffsA[0] = SIGN(p->delayA[0]); + p->adaptcoeffsA[-1] = SIGN(p->delayA[-1]); + + p->adaptcoeffsB[0] = SIGN(p->delayB[0]); + p->adaptcoeffsB[-1] = SIGN(p->delayB[-1]); + + if (A > 0) + { + vector_sub4_rev32(p->coeffsA, p->adaptcoeffsA); + vector_sub5_rev32(p->coeffsB, p->adaptcoeffsB); + } + else if (A < 0) + { + vector_add4_rev32(p->coeffsA, p->adaptcoeffsA); + vector_add5_rev32(p->coeffsB, p->adaptcoeffsB); + } + + p->delayA++; + p->delayB++; + p->adaptcoeffsA++; + p->adaptcoeffsB++; + + /* Have we filled the history buffer? */ + if (p->delayA == p->historybuffer + HISTORY_SIZE + (PREDICTOR_ORDER*4)) { + memmove(p->historybuffer, p->delayA - (PREDICTOR_ORDER*4), + (PREDICTOR_ORDER*4) * sizeof(int32_t)); + p->delayA = p->historybuffer + PREDICTOR_ORDER*4; + p->delayB = p->historybuffer + PREDICTOR_ORDER*3; + p->adaptcoeffsA = p->historybuffer + PREDICTOR_ORDER*2; + p->adaptcoeffsB = p->historybuffer + PREDICTOR_ORDER; + } + + p->lastA = currentA; + p->filterA = currentA + ((p->filterA * 31) >> 5); + + return p->filterA; +} + +static int32_t X; + +void init_predictor_decoder(struct ape_ctx_t* ape_ctx) +{ + X = 0; + + init_predictor(&ape_ctx->predictorY); + init_predictor(&ape_ctx->predictorX); +} + +int predictor_decode_stereo(struct ape_ctx_t* ape_ctx, int32_t* decoded0, int32_t* decoded1, int count) ICODE_ATTR; +int predictor_decode_stereo(struct ape_ctx_t* ape_ctx, int32_t* decoded0, int32_t* decoded1, int count) +{ + while (count--) + { + *decoded0 = do_predictor_decode(&ape_ctx->predictorY, *decoded0, X); + X = do_predictor_decode(&ape_ctx->predictorX, *decoded1, *(decoded0)++); + *(decoded1++) = X; + } + + return 0; +} + +int predictor_decode_mono(struct ape_ctx_t* ape_ctx, int32_t* decoded0, int count) +{ + struct predictor_t* p = &ape_ctx->predictorY; + int32_t predictionA, currentA, A; + + currentA = p->lastA; + + while (count--) + { + A = *decoded0; + + p->delayA[0] = currentA; + p->delayA[-1] = p->delayA[0] - p->delayA[-1]; + + predictionA = (p->delayA[0] * p->coeffsA[0]) + + (p->delayA[-1] * p->coeffsA[1]) + + (p->delayA[-2] * p->coeffsA[2]) + + (p->delayA[-3] * p->coeffsA[3]); + + currentA = A + (predictionA >> 10); + + p->adaptcoeffsA[0] = (p->delayA[0]) ? ((p->delayA[0] >> 30) & 2) - 1 : 0; + p->adaptcoeffsA[-1] = (p->delayA[-1]) ? ((p->delayA[-1] >> 30) & 2) - 1 : 0; + + if (A > 0) + { + p->coeffsA[0] -= p->adaptcoeffsA[0]; + p->coeffsA[1] -= p->adaptcoeffsA[-1]; + p->coeffsA[2] -= p->adaptcoeffsA[-2]; + p->coeffsA[3] -= p->adaptcoeffsA[-3]; + } + else if (A < 0) + { + p->coeffsA[0] += p->adaptcoeffsA[0]; + p->coeffsA[1] += p->adaptcoeffsA[-1]; + p->coeffsA[2] += p->adaptcoeffsA[-2]; + p->coeffsA[3] += p->adaptcoeffsA[-3]; + } + + p->delayA++; + p->adaptcoeffsA++; + + /* Have we filled the history buffer? */ + if (p->delayA == p->historybuffer + HISTORY_SIZE + (PREDICTOR_ORDER*4)) { + memmove(p->historybuffer, p->delayA - (PREDICTOR_ORDER*4), + (PREDICTOR_ORDER*4) * sizeof(int32_t)); + p->delayA = p->historybuffer + PREDICTOR_ORDER*4; + p->adaptcoeffsA = p->historybuffer + PREDICTOR_ORDER*2; + } + + p->filterA = currentA + ((p->filterA * 31) >> 5); + *(decoded0++) = p->filterA; + } + + p->lastA = currentA; + + return 0; +} Index: apps/codecs/libdemac/Makefile =================================================================== --- apps/codecs/libdemac/Makefile (revision 0) +++ apps/codecs/libdemac/Makefile (revision 0) @@ -0,0 +1,43 @@ +# __________ __ ___. +# Open \______ \ ____ ____ | | _\_ |__ _______ ___ +# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +# \/ \/ \/ \/ \/ +# $Id: Makefile 11401 2006-10-30 18:14:12Z learman $ +# + +INCLUDES=-I$(APPSDIR) -I.. -I. -I$(FIRMDIR)/include -I$(FIRMDIR)/export \ + -I$(FIRMDIR)/common -I$(FIRMDIR)/drivers -I$(BUILDDIR) + +ifdef APPEXTRA + INCLUDES += $(patsubst %,-I$(APPSDIR)/%,$(subst :, ,$(APPEXTRA))) +endif + +DEMACOPTS = -O3 -DROCKBOX +CFLAGS = $(INCLUDES) $(GCCOPTS) $(TARGET_INC) $(DEMACOPTS) $(TARGET) \ +$(EXTRA_DEFINES) -DMEM=${MEMORYSIZE} $(PROFILE_OPTS) + +# This sets up 'SRC' based on the files mentioned in SOURCES +include $(TOOLSDIR)/makesrc.inc + +SOURCES = $(SRC) +OBJS2 := $(SRC:%.c=$(OBJDIR)/%.o) +OBJS = $(patsubst %.S, $(OBJDIR)/%.o, $(OBJS2)) +DEPFILE = $(OBJDIR)/dep-libdemac +DIRS = + +all: $(OUTPUT) + +$(OUTPUT): $(OBJS) + $(call PRINTS,AR+RANLIB $(@F))$(AR) ruv $@ $+ >/dev/null 2>&1 + $(SILENT)$(RANLIB) $@ + +include $(TOOLSDIR)/make.inc + +clean: + $(call PRINTS,cleaning libdemac)rm -f $(OBJS) $(OUTPUT) $(DEPFILE) + +ifneq ($(MAKECMDGOALS),clean) +-include $(DEPFILE) +endif Index: apps/codecs/libdemac/parser.c =================================================================== --- apps/codecs/libdemac/parser.c (revision 0) +++ apps/codecs/libdemac/parser.c (revision 0) @@ -0,0 +1,355 @@ +/* + +libdemac - A Monkey's Audio decoder + +Copyright (C) Dave Chapman 2007 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA + +*/ + +#include +#include +#ifndef ROCKBOX +#include +#include +#include +#include +#include +#include +#endif + +#include "parser.h" + + +static inline int16_t get_int16(unsigned char* buf) +{ + return(buf[0] | (buf[1] << 8)); +} + +static inline uint16_t get_uint16(unsigned char* buf) +{ + return(buf[0] | (buf[1] << 8)); +} + +static inline uint32_t get_uint32(unsigned char* buf) +{ + return(buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24)); +} + + +int ape_parseheaderbuf(unsigned char* buf, struct ape_ctx_t* ape_ctx) +{ + unsigned char* header; + + memset(ape_ctx,0,sizeof(struct ape_ctx_t)); + /* TODO: Skip any leading junk such as id3v2 tags */ + ape_ctx->junklength = 0; + + memcpy(ape_ctx->magic, buf, 4); + if (memcmp(ape_ctx->magic,"MAC ",4)!=0) + { + return -1; + } + + ape_ctx->fileversion = get_int16(buf + 4); + + if (ape_ctx->fileversion >= 3980) + { + ape_ctx->padding1 = get_int16(buf + 6); + ape_ctx->descriptorlength = get_uint32(buf + 8); + ape_ctx->headerlength = get_uint32(buf + 12); + ape_ctx->seektablelength = get_uint32(buf + 16); + ape_ctx->wavheaderlength = get_uint32(buf + 20); + ape_ctx->audiodatalength = get_uint32(buf + 24); + ape_ctx->audiodatalength_high = get_uint32(buf + 28); + ape_ctx->wavtaillength = get_uint32(buf + 32); + memcpy(ape_ctx->md5, buf + 36, 16); + + header = buf + ape_ctx->descriptorlength; + + /* Read header data */ + ape_ctx->compressiontype = get_uint16(header + 0); + ape_ctx->formatflags = get_uint16(header + 2); + ape_ctx->blocksperframe = get_uint32(header + 4); + ape_ctx->finalframeblocks = get_uint32(header + 8); + ape_ctx->totalframes = get_uint32(header + 12); + ape_ctx->bps = get_uint16(header + 16); + ape_ctx->channels = get_uint16(header + 18); + ape_ctx->samplerate = get_uint32(header + 20); + + ape_ctx->firstframe = ape_ctx->junklength + ape_ctx->descriptorlength + + ape_ctx->headerlength + ape_ctx->seektablelength + + ape_ctx->wavheaderlength; + } else { + ape_ctx->compressiontype = get_uint16(buf + 6); + ape_ctx->formatflags = get_uint16(buf + 8); + ape_ctx->channels = get_uint16(buf + 10); + ape_ctx->samplerate = get_uint32(buf + 14); + ape_ctx->wavheaderlength = get_uint32(buf + 18); + ape_ctx->totalframes = get_uint32(buf + 26); + ape_ctx->finalframeblocks = get_uint32(buf + 30); + } + + ape_ctx->totalsamples = ape_ctx->finalframeblocks; + if (ape_ctx->totalframes > 1) + ape_ctx->totalsamples += ape_ctx->blocksperframe * (ape_ctx->totalframes-1); + + /* TODO: Parse and store seektable */ + + return 0; +} + + +#ifndef ROCKBOX +/* Helper functions */ + +static int read_uint16(int fd, uint16_t* x) +{ + unsigned char tmp[2]; + int n; + + n = read(fd,tmp,2); + + if (n != 2) + return -1; + + *x = tmp[0] | (tmp[1] << 8); + + return 0; +} + +static int read_int16(int fd, int16_t* x) +{ + return read_uint16(fd, (uint16_t*)x); +} + +static int read_uint32(int fd, uint32_t* x) +{ + unsigned char tmp[4]; + int n; + + n = read(fd,tmp,4); + + if (n != 4) + return -1; + + *x = tmp[0] | (tmp[1] << 8) | (tmp[2] << 16) | (tmp[3] << 24); + + return 0; +} + +int ape_parseheader(int fd, struct ape_ctx_t* ape_ctx) +{ + int i,n; + + /* TODO: Skip any leading junk such as id3v2 tags */ + ape_ctx->junklength = 0; + + lseek(fd,ape_ctx->junklength,SEEK_SET); + + n = read(fd,&ape_ctx->magic,4); + if (n != 4) return -1; + + if (memcmp(ape_ctx->magic,"MAC ",4)!=0) + { + return -1; + } + + if (read_int16(fd,&ape_ctx->fileversion) < 0) + return -1; + + if (ape_ctx->fileversion >= 3980) + { + if (read_int16(fd,&ape_ctx->padding1) < 0) + return -1; + if (read_uint32(fd,&ape_ctx->descriptorlength) < 0) + return -1; + if (read_uint32(fd,&ape_ctx->headerlength) < 0) + return -1; + if (read_uint32(fd,&ape_ctx->seektablelength) < 0) + return -1; + if (read_uint32(fd,&ape_ctx->wavheaderlength) < 0) + return -1; + if (read_uint32(fd,&ape_ctx->audiodatalength) < 0) + return -1; + if (read_uint32(fd,&ape_ctx->audiodatalength_high) < 0) + return -1; + if (read_uint32(fd,&ape_ctx->wavtaillength) < 0) + return -1; + if (read(fd,&ape_ctx->md5,16) != 16) + return -1; + + /* Skip any unknown bytes at the end of the descriptor. This is for future + compatibility */ + if (ape_ctx->descriptorlength > 52) + lseek(fd,ape_ctx->descriptorlength - 52, SEEK_CUR); + + /* Read header data */ + if (read_uint16(fd,&ape_ctx->compressiontype) < 0) + return -1; + if (read_uint16(fd,&ape_ctx->formatflags) < 0) + return -1; + if (read_uint32(fd,&ape_ctx->blocksperframe) < 0) + return -1; + if (read_uint32(fd,&ape_ctx->finalframeblocks) < 0) + return -1; + if (read_uint32(fd,&ape_ctx->totalframes) < 0) + return -1; + if (read_uint16(fd,&ape_ctx->bps) < 0) + return -1; + if (read_uint16(fd,&ape_ctx->channels) < 0) + return -1; + if (read_uint32(fd,&ape_ctx->samplerate) < 0) + return -1; + } else { + ape_ctx->descriptorlength = 0; + ape_ctx->headerlength = 32; + + if (read_uint16(fd,&ape_ctx->compressiontype) < 0) + return -1; + if (read_uint16(fd,&ape_ctx->formatflags) < 0) + return -1; + if (read_uint16(fd,&ape_ctx->channels) < 0) + return -1; + if (read_uint32(fd,&ape_ctx->samplerate) < 0) + return -1; + if (read_uint32(fd,&ape_ctx->wavheaderlength) < 0) + return -1; + if (read_uint32(fd,&ape_ctx->wavtaillength) < 0) + return -1; + if (read_uint32(fd,&ape_ctx->totalframes) < 0) + return -1; + if (read_uint32(fd,&ape_ctx->finalframeblocks) < 0) + return -1; + + if (ape_ctx->formatflags & MAC_FORMAT_FLAG_HAS_PEAK_LEVEL) + { + lseek(fd, 4, SEEK_CUR); /* Skip the peak level */ + ape_ctx->headerlength += 4; + } + + if (ape_ctx->formatflags & MAC_FORMAT_FLAG_HAS_SEEK_ELEMENTS) + { + if (read_uint32(fd,&ape_ctx->seektablelength) < 0) + return -1; + ape_ctx->headerlength += 4; + ape_ctx->seektablelength *= sizeof(int32_t); + } else { + ape_ctx->seektablelength = ape_ctx->totalframes * sizeof(int32_t); + } + + if (ape_ctx->formatflags & MAC_FORMAT_FLAG_8_BIT) + ape_ctx->bps = 8; + else if (ape_ctx->formatflags & MAC_FORMAT_FLAG_24_BIT) + ape_ctx->bps = 24; + else + ape_ctx->bps = 16; + + if (ape_ctx->fileversion >= 3950) + ape_ctx->blocksperframe = 73728 * 4; + else if ((ape_ctx->fileversion >= 3900) || (ape_ctx->fileversion >= 3800 && ape_ctx->compressiontype >= 4000)) + ape_ctx->blocksperframe = 73728; + else + ape_ctx->blocksperframe = 9216; + + /* Skip any stored wav header */ + if (!(ape_ctx->formatflags & MAC_FORMAT_FLAG_CREATE_WAV_HEADER)) + { + lseek(fd, ape_ctx->wavheaderlength, SEEK_CUR); + } + } + + ape_ctx->totalsamples = ape_ctx->finalframeblocks; + if (ape_ctx->totalframes > 1) + ape_ctx->totalsamples += ape_ctx->blocksperframe * (ape_ctx->totalframes-1); + + if (ape_ctx->seektablelength > 0) + { + ape_ctx->seektable = malloc(ape_ctx->seektablelength); + if (ape_ctx->seektable == NULL) + return -1; + for (i=0; i < ape_ctx->seektablelength / sizeof(uint32_t); i++) + { + if (read_uint32(fd,&ape_ctx->seektable[i]) < 0) + { + free(ape_ctx->seektable); + return -1; + } + } + } + + ape_ctx->firstframe = ape_ctx->junklength + ape_ctx->descriptorlength + + ape_ctx->headerlength + ape_ctx->seektablelength + + ape_ctx->wavheaderlength; + + return 0; +} + +void ape_dumpinfo(struct ape_ctx_t* ape_ctx) +{ + int i; + + printf("Descriptor Block:\n\n"); + printf("magic = \"%c%c%c%c\"\n", + ape_ctx->magic[0],ape_ctx->magic[1], + ape_ctx->magic[2],ape_ctx->magic[3]); + printf("fileversion = %d\n",ape_ctx->fileversion); + printf("descriptorlength = %d\n",ape_ctx->descriptorlength); + printf("headerlength = %d\n",ape_ctx->headerlength); + printf("seektablelength = %d\n",ape_ctx->seektablelength); + printf("wavheaderlength = %d\n",ape_ctx->wavheaderlength); + printf("audiodatalength = %d\n",ape_ctx->audiodatalength); + printf("audiodatalength_high = %d\n",ape_ctx->audiodatalength_high); + printf("wavtaillength = %d\n",ape_ctx->wavtaillength); + printf("md5 = "); + for (i = 0; i < 16; i++) + printf("%02x",ape_ctx->md5[i]); + printf("\n"); + + printf("\nHeader Block:\n\n"); + + printf("compressiontype = %d\n",ape_ctx->compressiontype); + printf("formatflags = %d\n",ape_ctx->formatflags); + printf("blocksperframe = %d\n",ape_ctx->blocksperframe); + printf("finalframeblocks = %d\n",ape_ctx->finalframeblocks); + printf("totalframes = %d\n",ape_ctx->totalframes); + printf("bps = %d\n",ape_ctx->bps); + printf("channels = %d\n",ape_ctx->channels); + printf("samplerate = %d\n",ape_ctx->samplerate); + + printf("\nSeektable\n\n"); + if ((ape_ctx->seektablelength / sizeof(uint32_t)) != ape_ctx->totalframes) + { + printf("No seektable\n"); + } + else + { + for ( i = 0; i < ape_ctx->seektablelength / sizeof(uint32_t) ; i++) + { + if (i < ape_ctx->totalframes-1) { + printf("%8d %d (%d bytes)\n",i,ape_ctx->seektable[i],ape_ctx->seektable[i+1]-ape_ctx->seektable[i]); + } else { + printf("%8d %d\n",i,ape_ctx->seektable[i]); + } + } + } + printf("\nCalculated information:\n\n"); + printf("junklength = %d\n",ape_ctx->junklength); + printf("firstframe = %d\n",ape_ctx->firstframe); + printf("totalsamples = %d\n",ape_ctx->totalsamples); +} + +#endif /* !ROCKBOX */ Index: apps/codecs/libdemac/filter_16_11.c =================================================================== --- apps/codecs/libdemac/filter_16_11.c (revision 0) +++ apps/codecs/libdemac/filter_16_11.c (revision 0) @@ -0,0 +1,25 @@ +/* + +libdemac - A Monkey's Audio decoder + +Copyright (C) Dave Chapman 2007 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA + +*/ + +#define ORDER 16 +#define FRACBITS 11 +#include "filter.c" Index: tools/configure =================================================================== --- tools/configure (revision 13537) +++ tools/configure (working copy) @@ -756,7 +756,7 @@ archosrom="" flash="$pwd/rombox.iriver" plugins="yes" - codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex" + codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex libdemac" # toolset is the tools within the tools directory that we build for # this particular target. toolset=$iriverbitmaptools @@ -781,7 +781,7 @@ archosrom="" flash="" plugins="yes" - codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex" + codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex libdemac" # toolset is the tools within the tools directory that we build for # this particular target. toolset=$iriverbitmaptools @@ -806,7 +806,7 @@ archosrom="" flash="" plugins="yes" - codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex" + codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex libdemac" # toolset is the tools within the tools directory that we build for # this particular target. toolset=$iriverbitmaptools @@ -831,7 +831,7 @@ archosrom="" flash="" plugins="yes" - codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex" + codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex libdemac" # toolset is the tools within the tools directory that we build for # this particular target. toolset="$iaudiobitmaptools" @@ -857,7 +857,7 @@ archosrom="" flash="" plugins="yes" - codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex" + codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex libdemac" # toolset is the tools within the tools directory that we build for # this particular target. toolset="$iaudiobitmaptools" @@ -881,7 +881,7 @@ archosrom="" flash="" plugins="yes" - codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex" + codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex libdemac" bootoutput="bootloader-$archos.ipod" # toolset is the tools within the tools directory that we build for # this particular target. @@ -906,7 +906,7 @@ archosrom="" flash="" plugins="yes" - codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex" + codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex libdemac" bootoutput="bootloader-$archos.ipod" # toolset is the tools within the tools directory that we build for # this particular target. @@ -930,7 +930,7 @@ archosrom="" flash="" plugins="yes" - codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex" + codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex libdemac" bootoutput="bootloader-$archos.ipod" # toolset is the tools within the tools directory that we build for # this particular target. @@ -955,7 +955,7 @@ archosrom="" flash="" plugins="yes" - codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex" + codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex libdemac" bootoutput="bootloader-$archos.ipod" # toolset is the tools within the tools directory that we build for # this particular target. @@ -980,7 +980,7 @@ archosrom="" flash="" plugins="yes" - codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex" + codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex libdemac" bootoutput="bootloader-$archos.ipod" # toolset is the tools within the tools directory that we build for # this particular target. @@ -1005,7 +1005,7 @@ archosrom="" flash="" plugins="yes" - codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex" + codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex libdemac" bootoutput="bootloader-$archos.ipod" # toolset is the tools within the tools directory that we build for # this particular target. @@ -1030,7 +1030,7 @@ archosrom="" flash="" plugins="yes" - codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex" + codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex libdemac" # toolset is the tools within the tools directory that we build for # this particular target. toolset=$genericbitmaptools @@ -1053,7 +1053,7 @@ archosrom="" flash="" plugins="yes" - codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex" + codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex libdemac" toolset=$gigabeatbitmaptools boottool="$rootdir/tools/scramble -gigabeat" bootoutput="FWIMG01.DAT" @@ -1077,7 +1077,7 @@ archosrom="" flash="" plugins="yes" - codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex" + codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex libdemac" bootoutput="bootloader-$archos.ipod" # toolset is the tools within the tools directory that we build for # this particular target. @@ -1102,7 +1102,7 @@ archosrom="" flash="" plugins="yes" - codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex" + codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex libdemac" boottool="$rootdir/tools/scramble -mi4v3 -model=h10 -type=RBBL" bootoutput="H10_20GC.mi4" # toolset is the tools within the tools directory that we build for @@ -1128,7 +1128,7 @@ archosrom="" flash="" plugins="yes" - codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex" + codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex libdemac" boottool="$rootdir/tools/scramble -mi4v2 -model=h105 -type=RBBL" bootoutput="H10.mi4" # toolset is the tools within the tools directory that we build for @@ -1154,7 +1154,7 @@ archosrom="" flash="" plugins="yes" - codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex" + codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex libdemac" boottool="$rootdir/tools/scramble -mi4v3 -model=e200 -type=RBBL" bootoutput="PP5022.mi4" # toolset is the tools within the tools directory that we build for @@ -1183,7 +1183,7 @@ archosrom="" flash="" plugins="yes" - codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex" + codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex libdemac" boottool="$rootdir/tools/scramble -mi4r -model=e20r -type=RBBL" bootoutput="pp5022.mi4" # toolset is the tools within the tools directory that we build for @@ -1209,7 +1209,7 @@ archosrom="" flash="" plugins="yes" - codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex" + codecs="libmad liba52 libffmpegFLAC libTremor libwavpack libmusepack libalac libfaad libm4a libspeex libdemac" boottool="$rootdir/tools/scramble -mi4v2" bootoutput="pp5020.mi4" # toolset is the tools within the tools directory that we build for Index: firmware/export/id3.h =================================================================== --- firmware/export/id3.h (revision 13537) +++ firmware/export/id3.h (working copy) @@ -53,6 +53,7 @@ AFMT_NSF, /* NESM (NES Sound Format) */ AFMT_SPEEX, /* Ogg Speex speech */ AFMT_SPC, /* SPC700 save state */ + AFMT_APE, /* Monkey's Audio (APE) */ #endif /* add new formats at any index above this line to have a sensible order - Index: firmware/id3.c =================================================================== --- firmware/id3.c (revision 13537) +++ firmware/id3.c (working copy) @@ -107,6 +107,9 @@ /* SPC700 Save State */ [AFMT_SPC] = AFMT_ENTRY("SPC", "spc", NULL, "spc\0" ), + /* APE (Monkey's Audio) */ + [AFMT_APE] = + AFMT_ENTRY("APE", "ape", NULL, "ape\0mac\0" ), #endif };