Index: apps/metadata/rm.c =================================================================== --- apps/metadata/rm.c (revision 0) +++ apps/metadata/rm.c (revision 0) @@ -0,0 +1,456 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id:$ + * + * Copyright (C) 2009 Mohamed Tarek + * + * 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ +#include +#include +#include +#include +#include + +#include +#include "system.h" +#include "metadata.h" +#include "metadata_common.h" +#include "metadata_parsers.h" +#define LOGF_ENABLE +#include "logf.h" + +#define MAX_STRING 92 /* Size of id3v1 buffers in metadata.h */ + +/* Metadata */ +char title[256]; +char author[256]; +char copyright[256]; +char comment[256]; + +int read_cook_extradata(int fd, RMContext *rmctx) { + read_uint32be(fd, &rmctx->cook_version); + read_uint16be(fd, &rmctx->samples_pf_pc); + read_uint16be(fd, &rmctx->nb_subbands); + if(rmctx->extradata_size == 16) { + read_uint32be(fd, &rmctx->unused); + read_uint16be(fd, &rmctx->js_subband_start); + read_uint16be(fd, &rmctx->js_vlc_bits); + } + return rmctx->extradata_size; /* for 'skipped' */ +} + +void print_cook_extradata(RMContext *rmctx) { + + //logf(" cook_version = 0x%08lx\n", rmctx->cook_version); + //logf(" samples_per_frame_per_channel = %d\n", rmctx->samples_pf_pc); + //logf(" number_of_subbands_in_freq_domain = %d\n", rmctx->nb_subbands); + if(rmctx->extradata_size == 16) { + //logf(" joint_stereo_subband_start = %d\n",rmctx->js_subband_start); + //logf(" joint_stereo_vlc_bits = %d\n", rmctx->js_vlc_bits); + } +} + + +struct real_object_t +{ + uint32_t fourcc; + uint32_t size; + uint16_t version; +}; + +#define FOURCC(a,b,c,d) (((a)<<24) | ((b) << 16) | ((c) << 8) | (d)) + +static int real_read_object_header(int fd, struct real_object_t* obj) +{ + int n; + + if ((n = read_uint32be(fd, &obj->fourcc)) <= 0) return n; + if ((n = read_uint32be(fd, &obj->size)) <= 0) return n; + if ((n = read_uint16be(fd, &obj->version)) <= 0) return n; + + return 1; +} + +static char* fourcc2str(uint32_t f) +{ + static char res[5]; + + res[0] = (f & 0xff000000) >> 24; + res[1] = (f & 0xff0000) >> 16; + res[2] = (f & 0xff00) >> 8; + res[3] = (f & 0xff); + res[4] = 0; + + return res; +} + +static int real_read_audio_stream_info(int fd, RMContext *rmctx) +{ + int skipped = 0; + uint32_t version; + struct real_object_t obj; + memset(&obj,0,sizeof(obj)); + uint32_t header_size; + uint16_t flavor; + uint32_t coded_framesize; + uint32_t unknown1; + uint32_t unknown2; + uint32_t unknown3; + uint16_t unknown4; + uint16_t unknown5; + uint16_t unknown6; + uint16_t unknown7; + uint32_t unknown8; + uint8_t interleaver_id_length; + uint32_t interleaver_id; + uint8_t fourcc_length; + uint32_t fourcc = 0; + uint8_t unknown9; + uint16_t unknown10; + uint8_t unknown11; + + read_uint32be(fd, &version); + skipped += 4; + + //logf(" version=0x%04lx\n",((version >> 16) & 0xff)); + if (((version >> 16) & 0xff) == 3) { + /* Very old version */ + } else { + real_read_object_header(fd, &obj); + skipped += 10; + read_uint32be(fd, &header_size); + skipped += 4; + /* obj.size will be filled with an unknown value, replaced with header_size */ + //logf(" Object: %s, size: %ld bytes, version: 0x%04x\n",fourcc2str(obj.fourcc),header_size,obj.version); + + read_uint16be(fd, &flavor); + read_uint32be(fd, &coded_framesize); + read_uint32be(fd, &unknown1); + read_uint32be(fd, &unknown2); + read_uint32be(fd, &unknown3); + read_uint16be(fd, &rmctx->sub_packet_h); + read_uint16be(fd, &rmctx->block_align); + read_uint16be(fd, &rmctx->sub_packet_size); + read_uint16be(fd, &unknown4); + skipped += 26; + if (((version >> 16) & 0xff) == 5) + { + read_uint16be(fd, &unknown5); + read_uint16be(fd, &unknown6); + read_uint16be(fd, &unknown7); + skipped += 6; + } + read_uint16be(fd, &rmctx->sample_rate); + read_uint32be(fd, &unknown8); + read_uint16be(fd, &rmctx->nb_channels); + skipped += 8; + if (((version >> 16) & 0xff) == 4) + { + read_uint8(fd, &interleaver_id_length); + read_uint32be(fd, &interleaver_id); + read_uint8(fd, &fourcc_length); + read_uint32be(fd, &fourcc); + skipped += 10; + } + if (((version >> 16) & 0xff) == 5) + { + read_uint32be(fd, &interleaver_id); + read_uint32be(fd, &fourcc); + skipped += 8; + } + read_uint8(fd,&unknown9); + read_uint16be(fd,&unknown10); + skipped += 3; + if (((version >> 16) & 0xff) == 5) + { + read_uint8(fd, &unknown11); + skipped += 1; + } + + read_uint32be(fd, &rmctx->extradata_size); + skipped += 4; + if(!strncmp(fourcc2str(fourcc),"cook",4)){ + skipped += read_cook_extradata(fd, rmctx); + rmctx->codec_type = cook; + } + + + //logf(" flavor = %d\n",flavor); + //logf(" coded_frame_size = %ld\n",coded_framesize); + //logf(" sub_packet_h = %d\n",rmctx->sub_packet_h); + //logf(" frame_size = %d\n",rmctx->block_align); + //logf(" sub_packet_size = %d\n",rmctx->sub_packet_size); + //logf(" sample_rate= %d\n",rmctx->sample_rate); + //logf(" channels= %d\n",rmctx->nb_channels); + //logf(" fourcc = %s\n",fourcc2str(fourcc)); + //logf(" codec_extra_data_length = %ld\n",rmctx->extradata_size); + //logf(" codec_extradata :\n"); + print_cook_extradata(rmctx); + + } + + return skipped; +} + +int real_parse_header(int fd, RMContext *rmctx) +{ + struct real_object_t obj; + memset(&obj,0,sizeof(obj)); + int res; + int skipped; + off_t curpos; + uint8_t len; /* Holds a string_length, which is then passed to read_string() */ + + uint32_t unknown1; + uint32_t unknown2; + + uint32_t max_bitrate; + uint32_t avg_bitrate = 0; + uint32_t max_packet_size; + uint32_t avg_packet_size; + uint32_t packet_count; + uint32_t duration; + uint32_t preroll; + uint32_t index_offset; + uint16_t num_streams; + + uint16_t stream_id; + uint32_t start_time; + char desc[256]; + char mimetype[256]; + uint32_t codec_data_size; + uint32_t v; + + uint32_t next_data_off; + uint8_t header_end; + + curpos = lseek(fd, 0, SEEK_SET); + res = real_read_object_header(fd, &obj); + + if (obj.fourcc == FOURCC('.','r','a',0xfd)) + { + /* Very old .ra format - not yet supported */ + return -1; + } + else if (obj.fourcc != FOURCC('.','R','M','F')) + { + return -1; + } + + read_uint32be(fd, &unknown1); + read_uint32be(fd, &unknown2); + + //logf("Object: %s, size: %d bytes, version: 0x%04x, pos: %d\n",fourcc2str(obj.fourcc),(int)obj.size,obj.version,(int)curpos); + //logf(" unknown1=%ld (0x%08lx)\n",unknown1,unknown1); + //logf(" unknown2=%ld (0x%08lx)\n",unknown2,unknown2); + + res = real_read_object_header(fd, &obj); + header_end = 0; + while(res) + { + ////logf("%s : %d %d\n", fourcc2str(obj.fourcc), obj.fourcc, FOURCC('M','D','P','R')); +////logf("HELLO %c %c %c %c\n", (char)((obj.fourcc)>>24), (char)((obj.fourcc)>>16), (char)((obj.fourcc)>>8), (char)(obj.fourcc)); + // //logf("Object: %s, size: %d bytes, version: 0x%04x, pos: %d\n",fourcc2str(obj.fourcc),(int)obj.size,obj.version,(int)curpos); + skipped = 10; + if(obj.fourcc == FOURCC('I','N','D','X')) + break; + switch (obj.fourcc) + { + case FOURCC('P','R','O','P'): /* File properties */ + read_uint32be(fd, &max_bitrate); + read_uint32be(fd, &rmctx->bit_rate); /*avg bitrate*/ + read_uint32be(fd, &max_packet_size); + read_uint32be(fd, &avg_packet_size); + read_uint32be(fd, &packet_count); + read_uint32be(fd, &rmctx->duration); + read_uint32be(fd, &preroll); + read_uint32be(fd, &index_offset); + read_uint32be(fd, &rmctx->data_offset); + read_uint16be(fd, &num_streams); + read_uint16be(fd, &rmctx->flags); + skipped += 40; + + //logf(" max_bitrate = %ld\n",max_bitrate); + //logf(" avg_bitrate = %ld\n",avg_bitrate); + //logf(" max_packet_size = %ld\n",max_packet_size); + //logf(" avg_packet_size = %ld\n",avg_packet_size); + //logf(" packet_count = %ld\n",packet_count); + //logf(" duration = %ld\n",rmctx->duration); + //logf(" preroll = %ld\n",preroll); + //logf(" index_offset = %ld\n",index_offset); + //logf(" data_offset = %ld\n",rmctx->data_offset); + //logf(" num_streams = %d\n",num_streams); + //logf(" flags=0x%04x\n",rmctx->flags); + break; + + case FOURCC('C','O','N','T'): + /* Four strings - Title, Author, Copyright, Comment */ + read_uint8(fd,&len); + skipped += (int)read_string(fd, title, MAX_STRING, '\0', len); + read_uint8(fd,&len); + skipped += (int)read_string(fd, author, MAX_STRING, '\0', len); + read_uint8(fd,&len); + skipped += (int)read_string(fd, copyright, MAX_STRING, '\0', len); + read_uint8(fd,&len); + skipped += (int)read_string(fd, comment, MAX_STRING, '\0', len); + skipped += 4; + + //logf(" title=\"%s\"\n",title); + //logf(" author=\"%s\"\n",author); + //logf(" copyright=\"%s\"\n",copyright); + //logf(" comment=\"%s\"\n",comment); + break; + + case FOURCC('M','D','P','R'): /* Media properties */ +logf("MDPR\n"); + read_uint16be(fd,&stream_id); + skipped += 2; + read_uint32be(fd,&max_bitrate); + skipped += 4; + read_uint32be(fd,&avg_bitrate); + skipped += 4; + read_uint32be(fd,&max_packet_size); + skipped += 4; + read_uint32be(fd,&avg_packet_size); + skipped += 4; + read_uint32be(fd,&start_time); + skipped += 4; + read_uint32be(fd,&preroll); + skipped += 4; + read_uint32be(fd,&duration); + skipped += 4; + read_uint8(fd,&len); + skipped += 1; + skipped += (int)read_string(fd, desc, 256, '\0', len); + read_uint8(fd,&len); + skipped += 1; + skipped += (int)read_string(fd, mimetype, 256, '\0', len); + read_uint32be(fd,&codec_data_size); + skipped += 4; + //From ffmpeg: codec_pos = url_ftell(pb); + read_uint32be(fd,&v); + skipped += 4; + + //logf(" stream_id = 0x%04x\n",stream_id); + //logf(" max_bitrate = %ld\n",max_bitrate); + //logf(" avg_bitrate = %ld\n",avg_bitrate); + //logf(" max_packet_size = %ld\n",max_packet_size); + //logf(" avg_packet_size = %ld\n",avg_packet_size); + //logf(" start_time = %ld\n",start_time); + //logf(" preroll = %ld\n",preroll); + //logf(" duration = %ld\n",duration); + //logf(" desc=\"%s\"\n",desc); + //logf(" mimetype=\"%s\"\n",mimetype); + //logf(" codec_data_size = %ld\n",codec_data_size); + //logf(" v=\"%s\"\n", fourcc2str(v)); + + if (v == FOURCC('.','r','a',0xfd)) + { + skipped += real_read_audio_stream_info(fd, rmctx); + } + + break; + + case FOURCC('D','A','T','A'): + logf("DATA\n"); + read_uint32be(fd,&rmctx->nb_packets); + skipped += 4; + read_uint32be(fd,&next_data_off); + skipped += 4; + if (!rmctx->nb_packets && (rmctx->flags & 4)) + rmctx->nb_packets = 3600 * 25; + + /*** + * nb_packets correction : + * in some samples, number of packets may not exactly form + * an integer number of scrambling units. This is corrected + * by constructing a partially filled unit out of the few + * remaining samples at the end of decoding. + ***/ + if(rmctx->nb_packets % rmctx->sub_packet_h) + rmctx->nb_packets += rmctx->sub_packet_h - (rmctx->nb_packets % rmctx->sub_packet_h); + + //logf(" data_nb_packets = %ld\n",rmctx->nb_packets); + //logf(" next DATA offset = %ld\n",next_data_off); + header_end = 1; + break; + } + if(header_end) break; + curpos = lseek(fd, obj.size - skipped, SEEK_CUR); +//logf("curpos = %d\n", (int)curpos); + res = real_read_object_header(fd, &obj); + } + + + return 0; +} + +void copy_metadata(struct mp3entry *id3, RMContext *rmctx) +{ + /* Copy tags */ + strncpy(id3->id3v1buf[0], title, MAX_STRING); +logf("H1N1\n"); + strncpy(id3->id3v1buf[1], author, MAX_STRING); +logf("H1N1\n"); + strncpy(id3->id3v1buf[2], comment, MAX_STRING); +logf("H1N1\n"); + + id3->title = id3->id3v1buf[0]; +logf("H1N1\n"); + id3->artist = id3->id3v1buf[1]; +logf("H1N1\n"); + id3->comment = id3->id3v1buf[2]; +logf("H1N1\n"); + + //logf("METADATA : 1-%s 2-%s 3-%s\n", title, author, comment); + //logf("METADATA : 1-%s 2-%s 3-%s\n", id3->title, id3->artist, id3->comment); + + /* Copy stream parameters */ + id3->bitrate = rmctx->bit_rate / 1000; +logf("H1N1\n"); + id3->frequency = rmctx->sample_rate; +logf("H1N1\n"); + id3->length = rmctx->duration; +logf("H1N1\n"); + switch(rmctx->codec_type) + { + case cook: + id3->codectype = AFMT_COOK; +logf("AFMT_COOK\n"); + break; + } + memcpy(id3->id3v2buf, rmctx, sizeof(RMContext)); +logf("H1N1\n"); + //logf("RMCONTEXT = %ld\n", sizeof(RMContext)); + //logf("METADATA : 1-%s 2-%s 3-%s\n", id3->title, id3->artist, id3->comment); + +} + +bool get_rm_metadata(int fd, struct mp3entry* id3) +{ + //logf("Metadata\n"); + RMContext rmctx; + memset(&rmctx,0,sizeof(RMContext)); + //logf("memset\n"); + real_parse_header(fd, &rmctx); + logf("Parsed\n"); + copy_metadata(id3, &rmctx); + logf("Metadata copied\n"); + id3->filesize = filesize(fd); + logf("Finished parsing\n"); + return true; +} + Property changes on: apps/metadata/rm.c ___________________________________________________________________ Added: svn:executable + * Index: apps/metadata.c =================================================================== --- apps/metadata.c (revision 21632) +++ apps/metadata.c (working copy) @@ -115,6 +115,9 @@ /* Amiga SAP File */ [AFMT_SAP] = AFMT_ENTRY("SAP", "asap", NULL, "sap\0" ), + /* Cook in RM/RA */ + [AFMT_COOK] = + AFMT_ENTRY("Cook", "cook", NULL, "rm\0ra\0" ), #endif }; @@ -372,6 +375,14 @@ id3->filesize = filesize(fd); id3->genre_string = id3_get_num_genre(36); break; + + case AFMT_COOK: + if (!get_rm_metadata(fd, id3)) + { + DEBUGF("get_rm_metadata error\n"); + return false; + } + break; #endif /* CONFIG_CODEC == SWCODEC */ Index: apps/metadata.h =================================================================== --- apps/metadata.h (revision 21632) +++ apps/metadata.h (working copy) @@ -61,6 +61,7 @@ AFMT_WMA, /* WMAV1/V2 in ASF */ AFMT_MOD, /* Amiga MOD File Format */ AFMT_SAP, /* Amiga 8Bit SAP Format */ + AFMT_COOK, /* Cook in RM/RA */ #endif /* add new formats at any index above this line to have a sensible order - Index: apps/SOURCES =================================================================== --- apps/SOURCES (revision 21632) +++ apps/SOURCES (working copy) @@ -166,6 +166,7 @@ metadata/wavpack.c metadata/a52.c metadata/asap.c +metadata/rm.c #endif #ifdef HAVE_TAGCACHE tagcache.c Index: apps/filetypes.c =================================================================== --- apps/filetypes.c (revision 21632) +++ apps/filetypes.c (working copy) @@ -83,6 +83,8 @@ { "ape", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, { "mac", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, { "sap" ,FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, + { "rm", FILE_ATTR_AUDIO, Icon_Audio, VOICE_EXT_MPA }, + { "ra", 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/libcook/bitstream.h =================================================================== --- apps/codecs/libcook/bitstream.h (revision 21632) +++ apps/codecs/libcook/bitstream.h (working copy) @@ -26,7 +26,7 @@ #ifndef AVCODEC_BITSTREAM_H #define AVCODEC_BITSTREAM_H -#include +#include #include #include #include @@ -51,7 +51,7 @@ //#define ALT_BITSTREAM_WRITER //#define ALIGNED_BITSTREAM_WRITER #if !defined(LIBMPEG2_BITSTREAM_READER) && !defined(A32_BITSTREAM_READER) && !defined(ALT_BITSTREAM_READER) -# if ARCH_ARM +# if defined(ARCH_ARM) # define A32_BITSTREAM_READER # else # define ALT_BITSTREAM_READER @@ -62,7 +62,7 @@ extern const uint8_t ff_reverse[256]; -#if ARCH_X86 +#if defined(ARCH_X86) // avoid +32 for shift optimization (gcc should do that ...) static inline int32_t NEG_SSR32( int32_t a, int8_t s){ __asm__ ("sarl %1, %0\n\t" @@ -226,7 +226,7 @@ } else { bit_buf<<=bit_left; bit_buf |= value >> (n - bit_left); -#if !HAVE_FAST_UNALIGNED +#if !defined(HAVE_FAST_UNALIGNED) if (3 & (intptr_t) s->buf_ptr) { AV_WB32(s->buf_ptr, bit_buf); } else @@ -736,6 +736,7 @@ } } +#if 0 static inline int check_marker(GetBitContext *s, const char *msg) { int bit= get_bits1(s); @@ -744,6 +745,7 @@ return bit; } +#endif /** * init GetBitContext. Index: apps/codecs/libcook/cook.h =================================================================== --- apps/codecs/libcook/cook.h (revision 21632) +++ apps/codecs/libcook/cook.h (working copy) @@ -22,7 +22,7 @@ #ifndef _COOK_H #define _COOK_H -#include +#include #include "bitstream.h" #include "../librm/rm.h" #include "cookdata_fixpoint.h" @@ -99,4 +99,4 @@ int cook_decode_frame(RMContext *rmctx,COOKContext *q, int16_t *outbuffer, int *data_size, const uint8_t *inbuffer, int buf_size); -#endif +#endif /*_COOK_H */ Index: apps/codecs/libcook/SOURCES =================================================================== --- apps/codecs/libcook/SOURCES (revision 0) +++ apps/codecs/libcook/SOURCES (revision 0) @@ -0,0 +1,3 @@ +cook.c +bitstream.c +../librm/rm.c Property changes on: apps/codecs/libcook/SOURCES ___________________________________________________________________ Added: svn:executable + * Index: apps/codecs/libcook/Makefile.test =================================================================== --- apps/codecs/libcook/Makefile.test (revision 21632) +++ apps/codecs/libcook/Makefile.test (working copy) @@ -1,4 +1,4 @@ -CFLAGS = -Wall -O3 +CFLAGS = -Wall -O3 -DTEST -D"DEBUGF=printf" OBJS = main.o bitstream.o cook.o ../librm/rm.o cooktest: $(OBJS) gcc -o cooktest $(OBJS) @@ -7,4 +7,4 @@ $(CC) $(CFLAGS) -c -o $@ $< clean: - rm -f cooktest $(OBJS) *~ + rm -f cooktest $(OBJS) *~ output.wav Index: apps/codecs/libcook/cookdata_fixpoint.h =================================================================== --- apps/codecs/libcook/cookdata_fixpoint.h (revision 21632) +++ apps/codecs/libcook/cookdata_fixpoint.h (working copy) @@ -26,7 +26,7 @@ * fixed point data types and constants */ -#include +#include typedef int32_t FIXP; /* Fixed point variable type */ typedef uint16_t FIXPU; /* Fixed point fraction 0<=x<1 */ @@ -39,11 +39,11 @@ typedef struct { } realvars_t; - +#ifdef TEST #define cPI1_8 0xec83 /* 1pi/8 2^16 */ #define cPI2_8 0xb505 /* 2pi/8 2^16 */ #define cPI3_8 0x61f8 /* 3pi/8 2^16 */ - +#endif static const FIXPU sincos_lookup[2050] = { /* x_i = 2^16 sin(i 2pi/8192), 2^16 cos(i 2pi/8192); i=0..1024 */ 0x0000, 0xffff, 0x0032, 0xffff, 0x0065, 0xffff, 0x0097, 0xffff, Index: apps/codecs/libcook/libcook.make =================================================================== --- apps/codecs/libcook/libcook.make (revision 0) +++ apps/codecs/libcook/libcook.make (revision 0) @@ -0,0 +1,18 @@ +# __________ __ ___. +# Open \______ \ ____ ____ | | _\_ |__ _______ ___ +# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / +# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < +# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ +# \/ \/ \/ \/ \/ +# $Id:$ +# + +# libcook +COOKLIB := $(CODECDIR)/libcook.a +COOKLIB_SRC := $(call preprocess, $(APPSDIR)/codecs/libcook/SOURCES) +COOKLIB_OBJ := $(call c2obj, $(COOKLIB_SRC)) +OTHER_SRC += $(COOKLIB_SRC) + +$(COOKLIB): $(COOKLIB_OBJ) + $(SILENT)$(shell rm -f $@) + $(call PRINTS,AR $(@F))$(AR) rcs $@ $^ >/dev/null Property changes on: apps/codecs/libcook/libcook.make ___________________________________________________________________ Added: svn:executable + * Index: apps/codecs/libcook/cook_fixpoint.h =================================================================== --- apps/codecs/libcook/cook_fixpoint.h (revision 21632) +++ apps/codecs/libcook/cook_fixpoint.h (working copy) @@ -54,29 +54,6 @@ }; /** - * Initialise fixed point implementation. - * Nothing to do for fixed point. - * - * @param q pointer to the COOKContext - */ -static inline int init_cook_math(COOKContext *q) -{ - return 0; -} - -/** - * Free resources used by floating point implementation. - * Nothing to do for fixed point. - * - * @param q pointer to the COOKContext - */ -static inline void free_cook_math(COOKContext *q) -{ - return; -} - - -/** * Fixed point multiply by power of two. * * @param x fix point value @@ -167,7 +144,7 @@ } } - +#ifdef TEST /** * The modulated lapped transform, this takes transform coefficients * and transforms them into timedomain samples. @@ -205,8 +182,36 @@ q->mono_mdct_output[n + i] = fixp_mult_su(tmp, sincos_lookup[j]); } while (++i < n); } +#else +#include +static inline void imlt_math(COOKContext *q, FIXP *in) +{ + const int n = q->samples_per_channel; + const int step = 4 << (10 - av_log2(n)); + int i = 0, j = step>>1; + mdct_backward(2 * n, in, q->mono_mdct_output); + + do { + FIXP tmp = q->mono_mdct_output[i]; + + q->mono_mdct_output[i] = + fixp_mult_su(-q->mono_mdct_output[n + i], sincos_lookup[j]); + q->mono_mdct_output[n + i] = fixp_mult_su(tmp, sincos_lookup[j+1]); + j += step; + } while (++i < n/2); + do { + FIXP tmp = q->mono_mdct_output[i]; + + j -= step; + q->mono_mdct_output[i] = + fixp_mult_su(-q->mono_mdct_output[n + i], sincos_lookup[j+1]); + q->mono_mdct_output[n + i] = fixp_mult_su(tmp, sincos_lookup[j]); + } while (++i < n); +} +#endif + /** * Perform buffer overlapping. * Index: apps/codecs/libcook/bswap.h =================================================================== --- apps/codecs/libcook/bswap.h (revision 21632) +++ apps/codecs/libcook/bswap.h (working copy) @@ -26,20 +26,10 @@ #ifndef AVUTIL_BSWAP_H #define AVUTIL_BSWAP_H -#include +#include //#include "ffmpeg_config.h" //#include "common.h" -#if ARCH_ARM -# include "arm/bswap.h" -#elif ARCH_BFIN -# include "bfin/bswap.h" -#elif ARCH_SH4 -# include "sh4/bswap.h" -#elif ARCH_X86 -# include "x86/bswap.h" -#endif - #ifndef bswap_16 static inline uint16_t bswap_16(uint16_t x) { Index: apps/codecs/libcook/main.c =================================================================== --- apps/codecs/libcook/main.c (revision 21632) +++ apps/codecs/libcook/main.c (working copy) @@ -29,13 +29,6 @@ #include "cook.h" //#define DUMP_RAW_FRAMES -#ifndef DEBUGF -# if 0 -# define DEBUGF(message,args ...) printf -# else -# define DEBUGF(...) -# endif -#endif #define DATA_HEADER_SIZE 18 /* size of DATA chunk header in a rm file */ static unsigned char wav_header[44]={ @@ -151,8 +144,8 @@ /* copy the input rm file to a memory buffer */ uint8_t * filebuf = (uint8_t *)calloc((int)filesize(fd),sizeof(uint8_t)); - read(fd,filebuf,filesize(fd)); - + res = read(fd,filebuf,filesize(fd)); + fd_dec = open_wav("output.wav"); if (fd_dec < 0) { DEBUGF("Error creating output file\n"); @@ -166,14 +159,13 @@ sps= rmctx.block_align; h = rmctx.sub_packet_h; cook_decode_init(&rmctx,&q); - DEBUGF("nb_frames = %d\n",nb_frames); - + /* change the buffer pointer to point at the first audio frame */ advance_buffer(&filebuf, rmctx.data_offset+ DATA_HEADER_SIZE); while(packet_count) { rm_get_packet_membuf(&filebuf, &rmctx, &pkt); - DEBUGF("total frames = %d packet count = %d output counter = %d \n",rmctx.audio_pkt_cnt*(fs/sps), packet_count,rmctx.audio_pkt_cnt); + //DEBUGF("total frames = %d packet count = %d output counter = %d \n",rmctx.audio_pkt_cnt*(fs/sps), packet_count,rmctx.audio_pkt_cnt); for(i = 0; i < rmctx.audio_pkt_cnt*(fs/sps) ; i++) { /* output raw audio frames that are sent to the decoder into separate files */ @@ -183,10 +175,9 @@ write(fd_out,pkt.frames[i],sps); close(fd_out); #endif - nb_frames = cook_decode_frame(&rmctx,&q, outbuf, &datasize, pkt.frames[i] , rmctx.block_align); rmctx.frame_number++; - write(fd_dec,outbuf,datasize); + res = write(fd_dec,outbuf,datasize); } packet_count -= rmctx.audio_pkt_cnt; rmctx.audio_pkt_cnt = 0; Index: apps/codecs/libcook/bitstream.c =================================================================== --- apps/codecs/libcook/bitstream.c (revision 21632) +++ apps/codecs/libcook/bitstream.c (working copy) @@ -29,6 +29,10 @@ #include "bitstream.h" +#ifdef ROCKBOX +#define DEBUGF(...) +#endif + const uint8_t ff_log2_run[32]={ 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, @@ -127,8 +131,7 @@ vlc->table_size += size; if (vlc->table_size > vlc->table_allocated) { if(use_static>1){ - printf("init_vlc() used with too little memory : table_size > allocated_memory\n"); - abort(); //cant do anything, init_vlc() is used with too little memory + DEBUGF("init_vlc() used with too little memory : table_size > allocated_memory\n"); } if (!vlc->table) @@ -151,7 +154,7 @@ table_size = 1 << table_nb_bits; table_index = alloc_table(vlc, table_size, flags & (INIT_VLC_USE_STATIC|INIT_VLC_USE_NEW_STATIC)); #ifdef DEBUG_VLC - printf("new table index=%d size=%d code_prefix=%x n=%d\n", + DEBUGF("new table index=%d size=%d code_prefix=%x n=%d\n", table_index, table_size, code_prefix, n_prefix); #endif if (table_index < 0) @@ -175,7 +178,7 @@ else GET_DATA(symbol, symbols, i, symbols_wrap, symbols_size); #if defined(DEBUG_VLC) && 0 - printf("i=%d n=%d code=0x%x\n", i, n, code); + DEBUGF("i=%d n=%d code=0x%x\n", i, n, code); #endif /* if code matches the prefix, it is in the table */ n -= n_prefix; @@ -192,11 +195,11 @@ if(flags & INIT_VLC_LE) j = (code >> n_prefix) + (k<> ((flags & INIT_VLC_LE) ? n_prefix : n)) & ((1 << table_nb_bits) - 1); #ifdef DEBUG_VLC - printf("%4x: n=%d (subtable)\n", + DEBUGF("%4x: n=%d (subtable)\n", j, n); #endif /* compute table size */ @@ -282,7 +285,7 @@ if(vlc->table_size && vlc->table_size == vlc->table_allocated){ return 0; }else if(vlc->table_size){ - abort(); // fatal error, we are called on a partially initialized table + return -1; // fatal error, we are called on a partially initialized table } }else if(!(flags & INIT_VLC_USE_STATIC)) { vlc->table = NULL; @@ -296,7 +299,7 @@ } #ifdef DEBUG_VLC - printf("build table nb_codes=%d\n", nb_codes); + DEBUGF("build table nb_codes=%d\n", nb_codes); #endif if (build_table(vlc, nb_bits, nb_codes, @@ -304,20 +307,16 @@ codes, codes_wrap, codes_size, symbols, symbols_wrap, symbols_size, 0, 0, flags) < 0) { - free(&vlc->table); + //free(&vlc->table); return -1; } /* Changed the following condition to be true if table_size > table_allocated. * * This would be more sensible for static tables since we want warnings for * * memory shortages only. */ + #ifdef TEST if((flags & INIT_VLC_USE_NEW_STATIC) && vlc->table_size > vlc->table_allocated) - printf("needed %d had %d\n", vlc->table_size, vlc->table_allocated); + DEBUGF("needed %d had %d\n", vlc->table_size, vlc->table_allocated); + #endif return 0; } - -void free_vlc(VLC *vlc) -{ - free(&vlc->table); -} - Index: apps/codecs/libcook/cook.c =================================================================== --- apps/codecs/libcook/cook.c (revision 21632) +++ apps/codecs/libcook/cook.c (working copy) @@ -60,16 +60,11 @@ #define SUBBAND_SIZE 20 #define MAX_SUBPACKETS 5 //#define COOKDEBUG -#if 0 -#define DEBUGF(message,args ...) printf -#else -#define DEBUGF(...) -#endif /** * Random bit stream generator. */ -static int inline cook_random(COOKContext *q) +static inline int cook_random(COOKContext *q) { q->random_state = q->random_state * 214013 + 2531011; /* typical RNG numbers */ @@ -200,7 +195,7 @@ i = 0; while (n--) { int index = get_bits(gb, 3); - int gain = get_bits1(gb) ? get_bits(gb, 4) - 7 : -1; + int gain = get_bits1(gb) ? (int)get_bits(gb, 4) - 7 : -1; while (i <= index) gaininfo[i++] = gain; } @@ -789,7 +784,7 @@ return -1; - if(q->block_align >= UINT_MAX/2) + if(rmctx->block_align >= UINT16_MAX/2) return -1; q->gains1.now = q->gain_1; Index: apps/codecs/codecs.make =================================================================== --- apps/codecs/codecs.make (revision 21632) +++ apps/codecs/codecs.make (working copy) @@ -33,6 +33,7 @@ include $(APPSDIR)/codecs/libtremor/libtremor.make include $(APPSDIR)/codecs/libwavpack/libwavpack.make include $(APPSDIR)/codecs/libwma/libwma.make +include $(APPSDIR)/codecs/libcook/libcook.make # compile flags for codecs CODECFLAGS = $(CFLAGS) -I$(APPSDIR)/codecs -I$(APPSDIR)/codecs/lib \ @@ -47,7 +48,7 @@ CODECLIBS := $(DEMACLIB) $(A52LIB) $(ALACLIB) $(ASAPLIB) \ $(FAADLIB) $(FFMPEGFLACLIB) $(M4ALIB) $(MADLIB) $(MUSEPACKLIB) \ - $(SPCLIB) $(SPEEXLIB) $(TREMORLIB) $(WAVPACKLIB) $(WMALIB) \ + $(SPCLIB) $(SPEEXLIB) $(TREMORLIB) $(WAVPACKLIB) $(WMALIB) $(COOKLIB) \ $(CODECLIB) $(CODECS): $(CODEC_CRT0) $(CODECLINK_LDS) @@ -73,6 +74,7 @@ $(CODECDIR)/wma.codec : $(CODECDIR)/libwma.a $(CODECDIR)/wavpack_enc.codec: $(CODECDIR)/libwavpack.a $(CODECDIR)/asap.codec : $(CODECDIR)/libasap.a +$(CODECDIR)/cook.codec : $(CODECDIR)/libcook.a $(CODECS): $(CODECLIB) # this must be last in codec dependency list Index: apps/codecs/SOURCES =================================================================== --- apps/codecs/SOURCES (revision 21632) +++ apps/codecs/SOURCES (working copy) @@ -9,6 +9,7 @@ #ifndef RB_PROFILE alac.c #endif +cook.c mpc.c wma.c sid.c Index: apps/codecs/librm/rm.c =================================================================== --- apps/codecs/librm/rm.c (revision 21632) +++ apps/codecs/librm/rm.c (working copy) @@ -21,23 +21,9 @@ ****************************************************************************/ #include #include -#include -#include -#include -#include -#include #include "rm.h" - - -#if 0 -#define DEBUG -#define DEBUGF printf -#else -#define DEBUGF(...) -#endif -/* Some Rockbox-like functions (these should be implemented in metadata_common.[ch] */ static uint8_t get_uint8(uint8_t *buf) { return (uint8_t)buf[0]; @@ -52,7 +38,27 @@ { return (uint32_t)((buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]); } +void advance_buffer(uint8_t **buf, int val) +{ + *buf += val; +} +#ifdef TEST +#include +#include +#include +#include +int filesize(int fd) +{ + struct stat buf; + + if (fstat(fd,&buf) == -1) { + return -1; + } else { + return (int)buf.st_size; + } +} + static int read_uint8(int fd, uint8_t* buf) { unsigned char tmp[1]; @@ -83,22 +89,8 @@ return res; } -off_t filesize(int fd) -{ - struct stat buf; - if (fstat(fd,&buf) == -1) { - return -1; - } else { - return buf.st_size; - } -} -void advance_buffer(uint8_t **buf, int val) -{ - *buf += val; -} - int read_cook_extradata(int fd, RMContext *rmctx) { read_uint32be(fd, &rmctx->cook_version); read_uint16be(fd, &rmctx->samples_pf_pc); @@ -113,12 +105,12 @@ void print_cook_extradata(RMContext *rmctx) { - printf(" cook_version = 0x%08x\n", rmctx->cook_version); - printf(" samples_per_frame_per_channel = %d\n", rmctx->samples_pf_pc); - printf(" number_of_subbands_in_freq_domain = %d\n", rmctx->nb_subbands); + DEBUGF(" cook_version = 0x%08x\n", rmctx->cook_version); + DEBUGF(" samples_per_frame_per_channel = %d\n", rmctx->samples_pf_pc); + DEBUGF(" number_of_subbands_in_freq_domain = %d\n", rmctx->nb_subbands); if(rmctx->extradata_size == 16) { - printf(" joint_stereo_subband_start = %d\n",rmctx->js_subband_start); - printf(" joint_stereo_vlc_bits = %d\n", rmctx->js_vlc_bits); + DEBUGF(" joint_stereo_subband_start = %d\n",rmctx->js_subband_start); + DEBUGF(" joint_stereo_vlc_bits = %d\n", rmctx->js_vlc_bits); } } @@ -196,7 +188,7 @@ read_uint32be(fd, &version); skipped += 4; - printf(" version=0x%04x\n",((version >> 16) & 0xff)); + DEBUGF(" version=0x%04x\n",((version >> 16) & 0xff)); if (((version >> 16) & 0xff) == 3) { /* Very old version */ } else { @@ -205,7 +197,7 @@ read_uint32be(fd, &header_size); skipped += 4; /* obj.size will be filled with an unknown value, replaced with header_size */ - printf(" Object: %s, size: %d bytes, version: 0x%04x\n",fourcc2str(obj.fourcc),header_size,obj.version); + DEBUGF(" Object: %s, size: %d bytes, version: 0x%04x\n",fourcc2str(obj.fourcc),header_size,obj.version); read_uint16be(fd, &flavor); read_uint32be(fd, &coded_framesize); @@ -253,20 +245,22 @@ read_uint32be(fd, &rmctx->extradata_size); skipped += 4; - if(!strncmp(fourcc2str(fourcc),"cook",4)) + if(!strncmp(fourcc2str(fourcc),"cook",4)){ skipped += read_cook_extradata(fd, rmctx); + rmctx->codec_type = cook; + } - printf(" flavor = %d\n",flavor); - printf(" coded_frame_size = %d\n",coded_framesize); - printf(" sub_packet_h = %d\n",rmctx->sub_packet_h); - printf(" frame_size = %d\n",rmctx->block_align); - printf(" sub_packet_size = %d\n",rmctx->sub_packet_size); - printf(" sample_rate= %d\n",rmctx->sample_rate); - printf(" channels= %d\n",rmctx->nb_channels); - printf(" fourcc = %s\n",fourcc2str(fourcc)); - printf(" codec_extra_data_length = %d\n",rmctx->extradata_size); - printf(" codec_extradata :\n"); + DEBUGF(" flavor = %d\n",flavor); + DEBUGF(" coded_frame_size = %d\n",coded_framesize); + DEBUGF(" sub_packet_h = %d\n",rmctx->sub_packet_h); + DEBUGF(" frame_size = %d\n",rmctx->block_align); + DEBUGF(" sub_packet_size = %d\n",rmctx->sub_packet_size); + DEBUGF(" sample_rate= %d\n",rmctx->sample_rate); + DEBUGF(" channels= %d\n",rmctx->nb_channels); + DEBUGF(" fourcc = %s\n",fourcc2str(fourcc)); + DEBUGF(" codec_extra_data_length = %d\n",rmctx->extradata_size); + DEBUGF(" codec_extradata :\n"); print_cook_extradata(rmctx); } @@ -327,15 +321,15 @@ read_uint32be(fd, &unknown1); read_uint32be(fd, &unknown2); - printf("Object: %s, size: %d bytes, version: 0x%04x, pos: %d\n",fourcc2str(obj.fourcc),(int)obj.size,obj.version,(int)curpos); - printf(" unknown1=%d (0x%08x)\n",unknown1,unknown1); - printf(" unknown2=%d (0x%08x)\n",unknown2,unknown2); + DEBUGF("Object: %s, size: %d bytes, version: 0x%04x, pos: %d\n",fourcc2str(obj.fourcc),(int)obj.size,obj.version,(int)curpos); + DEBUGF(" unknown1=%d (0x%08x)\n",unknown1,unknown1); + DEBUGF(" unknown2=%d (0x%08x)\n",unknown2,unknown2); res = real_read_object_header(fd, &obj); header_end = 0; while(res) { - printf("Object: %s, size: %d bytes, version: 0x%04x, pos: %d\n",fourcc2str(obj.fourcc),(int)obj.size,obj.version,(int)curpos); + DEBUGF("Object: %s, size: %d bytes, version: 0x%04x, pos: %d\n",fourcc2str(obj.fourcc),(int)obj.size,obj.version,(int)curpos); skipped = 10; if(obj.fourcc == FOURCC('I','N','D','X')) break; @@ -347,7 +341,7 @@ read_uint32be(fd, &max_packet_size); read_uint32be(fd, &avg_packet_size); read_uint32be(fd, &packet_count); - read_uint32be(fd, &duration); + read_uint32be(fd, &rmctx->duration); read_uint32be(fd, &preroll); read_uint32be(fd, &index_offset); read_uint32be(fd, &rmctx->data_offset); @@ -355,17 +349,17 @@ read_uint16be(fd, &rmctx->flags); skipped += 40; - printf(" max_bitrate = %d\n",max_bitrate); - printf(" avg_bitrate = %d\n",avg_bitrate); - printf(" max_packet_size = %d\n",max_packet_size); - printf(" avg_packet_size = %d\n",avg_packet_size); - printf(" packet_count = %d\n",packet_count); - printf(" duration = %d\n",duration); - printf(" preroll = %d\n",preroll); - printf(" index_offset = %d\n",index_offset); - printf(" data_offset = %d\n",rmctx->data_offset); - printf(" num_streams = %d\n",num_streams); - printf(" flags=0x%04x\n",flags); + DEBUGF(" max_bitrate = %d\n",max_bitrate); + DEBUGF(" avg_bitrate = %d\n",avg_bitrate); + DEBUGF(" max_packet_size = %d\n",max_packet_size); + DEBUGF(" avg_packet_size = %d\n",avg_packet_size); + DEBUGF(" packet_count = %d\n",packet_count); + DEBUGF(" duration = %d\n",rmctx->duration); + DEBUGF(" preroll = %d\n",preroll); + DEBUGF(" index_offset = %d\n",index_offset); + DEBUGF(" data_offset = %d\n",rmctx->data_offset); + DEBUGF(" num_streams = %d\n",num_streams); + DEBUGF(" flags=0x%04x\n",flags); break; case FOURCC('C','O','N','T'): @@ -375,10 +369,10 @@ skipped += read_str(fd,copyright); skipped += read_str(fd,comment); - printf(" title=\"%s\"\n",title); - printf(" author=\"%s\"\n",author); - printf(" copyright=\"%s\"\n",copyright); - printf(" comment=\"%s\"\n",comment); + DEBUGF(" title=\"%s\"\n",title); + DEBUGF(" author=\"%s\"\n",author); + DEBUGF(" copyright=\"%s\"\n",copyright); + DEBUGF(" comment=\"%s\"\n",comment); break; case FOURCC('M','D','P','R'): /* Media properties */ @@ -406,18 +400,18 @@ read_uint32be(fd,&v); skipped += 4; - printf(" stream_id = 0x%04x\n",stream_id); - printf(" max_bitrate = %d\n",max_bitrate); - printf(" avg_bitrate = %d\n",avg_bitrate); - printf(" max_packet_size = %d\n",max_packet_size); - printf(" avg_packet_size = %d\n",avg_packet_size); - printf(" start_time = %d\n",start_time); - printf(" preroll = %d\n",preroll); - printf(" duration = %d\n",duration); - printf(" desc=\"%s\"\n",desc); - printf(" mimetype=\"%s\"\n",mimetype); - printf(" codec_data_size = %d\n",codec_data_size); - printf(" v=\"%s\"\n", fourcc2str(v)); + DEBUGF(" stream_id = 0x%04x\n",stream_id); + DEBUGF(" max_bitrate = %d\n",max_bitrate); + DEBUGF(" avg_bitrate = %d\n",avg_bitrate); + DEBUGF(" max_packet_size = %d\n",max_packet_size); + DEBUGF(" avg_packet_size = %d\n",avg_packet_size); + DEBUGF(" start_time = %d\n",start_time); + DEBUGF(" preroll = %d\n",preroll); + DEBUGF(" duration = %d\n",duration); + DEBUGF(" desc=\"%s\"\n",desc); + DEBUGF(" mimetype=\"%s\"\n",mimetype); + DEBUGF(" codec_data_size = %d\n",codec_data_size); + DEBUGF(" v=\"%s\"\n", fourcc2str(v)); if (v == FOURCC('.','r','a',0xfd)) { @@ -445,8 +439,8 @@ if(rmctx->nb_packets % rmctx->sub_packet_h) rmctx->nb_packets += rmctx->sub_packet_h - (rmctx->nb_packets % rmctx->sub_packet_h); - printf(" data_nb_packets = %d\n",rmctx->nb_packets); - printf(" next DATA offset = %d\n",next_data_off); + DEBUGF(" data_nb_packets = %d\n",rmctx->nb_packets); + DEBUGF(" next DATA offset = %d\n",next_data_off); header_end = 1; break; } @@ -467,6 +461,7 @@ uint16_t h = rmctx->sub_packet_h; uint16_t y = rmctx->sub_packet_cnt; uint16_t w = rmctx->audio_framesize; + int res; do { y = rmctx->sub_packet_cnt; @@ -496,7 +491,7 @@ for(x = 0 ; x < w/sps; x++) { place = sps*(h*x+((h+1)/2)*(y&1)+(y>>1)); - read(fd,pkt->data+place, sps); + res = read(fd,pkt->data+place, sps); //DEBUGF("place = %d data[place] = %d\n",place,pkt->data[place]); } rmctx->audio_pkt_cnt++; @@ -504,13 +499,15 @@ //return pkt->data; } +#endif /*TEST*/ /** * Another version of rm_get_packet which reads from a memory buffer - * instead of readind from a file descriptor. + * instead of reading from a file descriptor. **/ -void rm_get_packet_membuf(uint8_t **filebuf,RMContext *rmctx, RMPacket *pkt) +int rm_get_packet_membuf(uint8_t **filebuf,RMContext *rmctx, RMPacket *pkt) { + int consumed = 0; uint8_t unknown; uint16_t x, place; uint16_t sps = rmctx->sub_packet_size; @@ -524,11 +521,10 @@ pkt->length = get_uint16be(*filebuf+2); pkt->stream_number = get_uint16be(*filebuf+4); pkt->timestamp = get_uint32be(*filebuf+6); - DEBUGF(" version = %d\n" + /*DEBUGF(" version = %d\n" " length = %d\n" " stream = %d\n" - " timestamp= %d\n",pkt->version,pkt->length,pkt->stream_number,pkt->timestamp); - + " timestamp= %d\n\n",pkt->version,pkt->length,pkt->stream_number,pkt->timestamp);*/ unknown = get_uint8(*filebuf+10); pkt->flags = get_uint8(*filebuf+11); @@ -541,15 +537,19 @@ rmctx->audiotimestamp = pkt->timestamp; advance_buffer(filebuf,12); - + consumed += 12; for(x = 0 ; x < w/sps; x++) { place = sps*(h*x+((h+1)/2)*(y&1)+(y>>1)); + //DEBUGF(" Place = %p\n",place); pkt->frames[place/sps] = *filebuf; advance_buffer(filebuf,sps); + consumed += sps; } rmctx->audio_pkt_cnt++; }while(++(rmctx->sub_packet_cnt) < h); + +return consumed; } #ifdef DEBUG Index: apps/codecs/librm/rm.h =================================================================== --- apps/codecs/librm/rm.h (revision 21632) +++ apps/codecs/librm/rm.h (working copy) @@ -22,17 +22,21 @@ #define _RM_H #include -#include +#include +enum codecs{cook}; typedef struct rm_packet { - uint8_t data[30000]; /* Reordered data. No malloc, hence the size */ uint8_t *frames[100]; /* Pointers to ordered audio frames in buffer */ uint16_t version; uint16_t length; uint32_t timestamp; uint16_t stream_number; uint8_t flags; + + #ifdef TEST + uint8_t data[30000]; /* Reordered data. No malloc, hence the size */ + #endif }RMPacket; typedef struct rm_context @@ -46,6 +50,7 @@ /* Stream Variables */ uint32_t data_offset; + uint32_t duration; uint32_t audiotimestamp; /* Audio packet timestamp*/ uint16_t sub_packet_cnt; /* Subpacket counter, used while reading */ uint16_t sub_packet_size, sub_packet_h, coded_framesize; /* Descrambling parameters from container */ @@ -53,6 +58,7 @@ uint16_t sub_packet_lengths[16]; /* Length of each subpacket */ /* Codec Context */ + enum codecs codec_type; uint16_t block_align; uint32_t nb_packets; int frame_number; @@ -66,18 +72,20 @@ uint32_t cook_version; uint16_t samples_pf_pc; /* samples per frame per channel */ uint16_t nb_subbands; /* number of subbands in the frequency domain */ - /* extra 8 bytes for stereo data */ + /* extra 8 bytes for joint-stereo data */ uint32_t unused; uint16_t js_subband_start; /* joint stereo subband start */ uint16_t js_vlc_bits; } RMContext; -int open_wav(char* filename); -void close_wav(int fd, RMContext *rmctx); int real_parse_header(int fd, RMContext *rmctx); void rm_get_packet(int fd,RMContext *rmctx, RMPacket *pkt); -void rm_get_packet_membuf(uint8_t **filebuf,RMContext *rmctx, RMPacket *pkt); -off_t filesize(int fd); +int rm_get_packet_membuf(uint8_t **filebuf,RMContext *rmctx, RMPacket *pkt); + +#ifdef TEST +int filesize(int fd); void advance_buffer(uint8_t **buf, int val); #endif + +#endif /* _RM_H */ Index: apps/codecs/cook.c =================================================================== --- apps/codecs/cook.c (revision 0) +++ apps/codecs/cook.c (revision 0) @@ -0,0 +1,130 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * Copyright (C) 2009 Mohamed Tarek + * + * 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include + +#include "logf.h" +#include "codeclib.h" +#include "inttypes.h" +#include "libcook/cook.h" + +#define DATA_HEADER_SIZE 18 /* size of DATA chunk header in a rm file */ + +CODEC_HEADER + +RMContext rmctx; +RMPacket pkt; +COOKContext q; + +void init_rm(RMContext *rmctx) +{ + memcpy(rmctx, ci->id3->id3v2buf, sizeof(RMContext)); +} + +/* this is the codec entry point */ +enum codec_status codec_main(void) +{ + static size_t buff_size; + int datasize, nb_frames, consumed,i; + uint8_t *bit_buffer; + int16_t outbuf[2048] __attribute__((aligned(32))); + uint16_t fs,sps,h; + uint32_t packet_count; + int scrambling_unit_size; + +next_track: + if (codec_init()) { + DEBUGF("codec init failed\n"); + return CODEC_ERROR; + } + while (!*ci->taginfo_ready && !ci->stop_codec) + ci->sleep(1); + + + codec_set_replaygain(ci->id3); + ci->memset(&rmctx,0,sizeof(RMContext)); + ci->memset(&pkt,0,sizeof(RMPacket)); + ci->memset(&q,0,sizeof(COOKContext)); + + init_rm(&rmctx); + + ci->configure(DSP_SET_FREQUENCY, ci->id3->frequency); + ci->configure(DSP_SET_SAMPLE_DEPTH, 16); + ci->configure(DSP_SET_STEREO_MODE, rmctx.nb_channels == 1 ? + STEREO_MONO : STEREO_INTERLEAVED); + + packet_count = rmctx.nb_packets; + rmctx.audio_framesize = rmctx.block_align; + rmctx.block_align = rmctx.sub_packet_size; + fs = rmctx.audio_framesize; + sps= rmctx.block_align; + h = rmctx.sub_packet_h; + scrambling_unit_size = h*fs; + cook_decode_init(&rmctx, &q); + ci->set_elapsed(0); + ci->advance_buffer(rmctx.data_offset + DATA_HEADER_SIZE); + + /* The main decoder loop */ + while (1) + { + /*if (ci->seek_time) { + + ci->set_elapsed(ci->seek_time); + n = ci->seek_time/10; + memset(buf,0,BUF_SIZE); + ci->seek_complete(); + }*/ + + while(packet_count) + { + bit_buffer = (uint8_t *) ci->request_buffer(&buff_size, scrambling_unit_size); + consumed = rm_get_packet_membuf(&bit_buffer, &rmctx, &pkt); + /*DEBUGF(" version = %d\n" + " length = %d\n" + " stream = %d\n" + " timestamp= %d\n",pkt.version,pkt.length,pkt.stream_number,pkt.timestamp);*/ + + for(i = 0; i < rmctx.audio_pkt_cnt*(fs/sps) ; i++) + { + ci->yield(); + if (ci->stop_codec || ci->new_track) + goto done; + + nb_frames = cook_decode_frame(&rmctx,&q, outbuf, &datasize, pkt.frames[i], rmctx.block_align); + rmctx.frame_number++; + /* skip the first two frames; no valid audio */ + if(rmctx.frame_number < 3) continue; + + ci->pcmbuf_insert(outbuf, NULL, rmctx.samples_pf_pc / rmctx.nb_channels); + ci->set_elapsed(rmctx.audiotimestamp+(1000*8*sps/rmctx.bit_rate)*i); + } + packet_count -= rmctx.audio_pkt_cnt; + rmctx.audio_pkt_cnt = 0; + ci->advance_buffer(consumed); + } + goto done; + + } + done : + if (ci->request_next_track()) + goto next_track; + + return CODEC_OK; +} + Property changes on: apps/codecs/cook.c ___________________________________________________________________ Added: svn:executable + *