summaryrefslogtreecommitdiff
path: root/apps/codecs/lib
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2005-06-22 19:41:30 +0000
committerDaniel Stenberg <daniel@haxx.se>2005-06-22 19:41:30 +0000
commit1dd672fe3226fa77113f35e4d72f50b863484c63 (patch)
tree67b424ab990f160dbc8fb238b9fa3390ceba10ed /apps/codecs/lib
parentb7aaa641b864628d76103b8c9d57c15747560ca7 (diff)
downloadrockbox-1dd672fe3226fa77113f35e4d72f50b863484c63.zip
rockbox-1dd672fe3226fa77113f35e4d72f50b863484c63.tar.gz
rockbox-1dd672fe3226fa77113f35e4d72f50b863484c63.tar.bz2
rockbox-1dd672fe3226fa77113f35e4d72f50b863484c63.tar.xz
moved and renamed the codecs, gave the codecs a new extension (.codec),
unified to a single codec-only API, made a new codeclib, disabled the building of the *2wav plugins git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6812 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/codecs/lib')
-rw-r--r--apps/codecs/lib/Makefile46
-rw-r--r--apps/codecs/lib/codeclib.c38
-rw-r--r--apps/codecs/lib/codeclib.h49
-rw-r--r--apps/codecs/lib/xxx2wav.c270
-rw-r--r--apps/codecs/lib/xxx2wav.h69
5 files changed, 472 insertions, 0 deletions
diff --git a/apps/codecs/lib/Makefile b/apps/codecs/lib/Makefile
new file mode 100644
index 0000000..08dcd2a
--- /dev/null
+++ b/apps/codecs/lib/Makefile
@@ -0,0 +1,46 @@
+# __________ __ ___.
+# Open \______ \ ____ ____ | | _\_ |__ _______ ___
+# Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+# Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+# Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+# \/ \/ \/ \/ \/
+# $Id$
+#
+
+# ../.. for the codec.h in the apps dir
+# .. for stuff in the codecs dir
+# . for stuff in the codeclib dir
+INCLUDES=-I$(APPSDIR) -I.. -I. -I$(FIRMDIR)/include -I$(FIRMDIR)/export \
+ -I$(FIRMDIR)/common -I$(BUILDDIR)
+
+ifdef APPEXTRA
+INCLUDES += -I$(APPSDIR)/$(APPEXTRA)
+endif
+
+CFLAGS = $(GCCOPTS) \
+$(INCLUDES) $(TARGET) $(EXTRA_DEFINES) -DMEM=${MEMORYSIZE} -DCODEC
+
+# This sets up 'SRC' based on the files mentioned in SOURCES
+include $(TOOLSDIR)/makesrc.inc
+
+SOURCES = $(SRC)
+OBJS := $(SRC:%.c=$(OBJDIR)/%.o)
+DEPFILE = $(OBJDIR)/dep-codeclib
+DIRS = .
+
+OUTPUT = $(BUILDDIR)/libcodec.a
+
+all: $(OUTPUT)
+
+$(OUTPUT): $(OBJS)
+ @echo "AR+RANLIB $@"
+ @$(AR) ruv $@ $+ >/dev/null 2>&1
+ @$(RANLIB) $@
+
+include $(TOOLSDIR)/make.inc
+
+clean:
+ @echo "cleaning lib"
+ @rm -f $(OBJS) $(OUTPUT) $(DEPFILE)
+
+-include $(DEPFILE)
diff --git a/apps/codecs/lib/codeclib.c b/apps/codecs/lib/codeclib.c
new file mode 100644
index 0000000..3aa6216
--- /dev/null
+++ b/apps/codecs/lib/codeclib.c
@@ -0,0 +1,38 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2005 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.
+ *
+ ****************************************************************************/
+
+/* "helper functions" common to all codecs */
+
+#include "plugin.h"
+#include "playback.h"
+#include "codeclib.h"
+#include "xxx2wav.h"
+
+struct codec_api *local_rb;
+
+int codec_init(struct codec_api* rb)
+{
+ local_rb = rb;
+
+ xxx2wav_set_api(rb);
+ mem_ptr = 0;
+ mallocbuf = (unsigned char *)rb->get_codec_memory((size_t *)&bufsize);
+
+ return 0;
+}
diff --git a/apps/codecs/lib/codeclib.h b/apps/codecs/lib/codeclib.h
new file mode 100644
index 0000000..116f210
--- /dev/null
+++ b/apps/codecs/lib/codeclib.h
@@ -0,0 +1,49 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2005 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 "config.h"
+#include "codecs.h"
+
+/* Various codec "helper functions" */
+
+#if CONFIG_CPU == MCF5249 && !defined(SIMULATOR)
+#define ICODE_ATTR __attribute__ ((section(".icode")))
+#define IDATA_ATTR __attribute__ ((section(".idata")))
+#define USE_IRAM 1
+#else
+#define ICODE_ATTR
+#define IDATA_ATTR
+#endif
+
+extern int mem_ptr;
+extern int bufsize;
+extern unsigned char* mallocbuf; // 512K from the start of MP3 buffer
+
+void* codec_malloc(size_t size);
+void* codec_calloc(size_t nmemb, size_t size);
+void* codec_alloca(size_t size);
+void* codec_realloc(void* ptr, size_t size);
+void codec_free(void* ptr);
+void *memcpy(void *dest, const void *src, size_t n);
+void *memset(void *s, int c, size_t n);
+int memcmp(const void *s1, const void *s2, size_t n);
+void* memmove(const void *s1, const void *s2, size_t n);
+
+int codec_init(struct codec_api* rb);
+
diff --git a/apps/codecs/lib/xxx2wav.c b/apps/codecs/lib/xxx2wav.c
new file mode 100644
index 0000000..1bc1837
--- /dev/null
+++ b/apps/codecs/lib/xxx2wav.c
@@ -0,0 +1,270 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2005 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.
+ *
+ ****************************************************************************/
+
+/* Various "helper functions" common to all the xxx2wav decoder plugins */
+
+#if (CONFIG_HWCODEC == MASNONE)
+/* software codec platforms, not for simulator */
+
+#include "codecs.h"
+#include "xxx2wav.h"
+
+static struct codec_api* local_rb;
+
+int mem_ptr;
+int bufsize;
+unsigned char* audiobuf; // The actual audio buffer from Rockbox
+unsigned char* mallocbuf; // 512K from the start of audio buffer
+unsigned char* filebuf; // The rest of the audio buffer
+
+void* codec_malloc(size_t size)
+{
+ void* x;
+
+ x=&mallocbuf[mem_ptr];
+ mem_ptr+=(size+3)&~3; // Keep memory 32-bit aligned (if it was already?)
+/*
+ if(TIME_AFTER(*(local_rb->current_tick), last_tick + HZ)) {
+ char s[32];
+ static long last_tick = 0;
+ local_rb->snprintf(s,30,"Memory used: %d",mem_ptr);
+ local_rb->lcd_putsxy(0,80,s);
+
+ last_tick = *(local_rb->current_tick);
+ local_rb->lcd_update();
+ }*/
+ return(x);
+}
+
+void* codec_calloc(size_t nmemb, size_t size)
+{
+ void* x;
+ x = codec_malloc(nmemb*size);
+ local_rb->memset(x,0,nmemb*size);
+ return(x);
+}
+
+void* codec_alloca(size_t size)
+{
+ void* x;
+ x = codec_malloc(size);
+ return(x);
+}
+
+void codec_free(void* ptr) {
+ (void)ptr;
+}
+
+void* codec_realloc(void* ptr, size_t size) {
+ void* x;
+ (void)ptr;
+ x = codec_malloc(size);
+ return(x);
+}
+
+void *memcpy(void *dest, const void *src, size_t n) {
+ return(local_rb->memcpy(dest,src,n));
+}
+
+void *memset(void *s, int c, size_t n) {
+ return(local_rb->memset(s,c,n));
+}
+
+int memcmp(const void *s1, const void *s2, size_t n) {
+ return(local_rb->memcmp(s1,s2,n));
+}
+
+void* memchr(const void *s, int c, size_t n) {
+ /* TO DO: Implement for Tremor */
+ (void)s;
+ (void)c;
+ (void)n;
+ return(NULL);
+}
+
+void* memmove(const void *s1, const void *s2, size_t n) {
+ char* dest=(char*)s1;
+ char* src=(char*)s2;
+ size_t i;
+
+ for (i=0;i<n;i++) { dest[i]=src[i]; }
+ // while(n>0) { *(dest++)=*(src++); n--; }
+ return(dest);
+}
+
+void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)) {
+ local_rb->qsort(base,nmemb,size,compar);
+}
+
+void display_status(file_info_struct* file_info) {
+ char s[32];
+ unsigned long ticks_taken;
+ unsigned long long speed;
+ unsigned long xspeed;
+ static long last_tick = 0;
+
+ if(TIME_AFTER(*(local_rb->current_tick), last_tick + HZ)) {
+ local_rb->snprintf(s,32,"Bytes read: %d",file_info->curpos);
+ local_rb->lcd_putsxy(0,0,s);
+ local_rb->snprintf(s,32,"Samples Decoded: %d",file_info->current_sample);
+ local_rb->lcd_putsxy(0,20,s);
+ local_rb->snprintf(s,32,"Frames Decoded: %d",file_info->frames_decoded);
+ local_rb->lcd_putsxy(0,40,s);
+
+ ticks_taken=*(local_rb->current_tick)-file_info->start_tick;
+
+ /* e.g.:
+ ticks_taken=500
+ sam_fmt.rate=44,100
+ samples_decoded=172,400
+ (samples_decoded/sam_fmt.rate)*100=400 (time it should have taken)
+ % Speed=(400/500)*100=80%
+ */
+
+ if (ticks_taken==0) { ticks_taken=1; } // Avoid fp exception.
+
+ speed=(100*file_info->current_sample)/file_info->samplerate;
+ xspeed=(speed*10000)/ticks_taken;
+ local_rb->snprintf(s,32,"Speed %ld.%02ld %% Secs: %d",(xspeed/100),(xspeed%100),ticks_taken/100);
+ local_rb->lcd_putsxy(0,60,s);
+
+ last_tick = *(local_rb->current_tick);
+ local_rb->lcd_update();
+ }
+}
+
+#if 0
+static unsigned char wav_header[44]={'R','I','F','F', // 0 - ChunkID
+ 0,0,0,0, // 4 - ChunkSize (filesize-8)
+ 'W','A','V','E', // 8 - Format
+ 'f','m','t',' ', // 12 - SubChunkID
+ 16,0,0,0, // 16 - SubChunk1ID // 16 for PCM
+ 1,0, // 20 - AudioFormat (1=16-bit)
+ 2,0, // 22 - NumChannels
+ 0,0,0,0, // 24 - SampleRate in Hz
+ 0,0,0,0, // 28 - Byte Rate (SampleRate*NumChannels*(BitsPerSample/8)
+ 4,0, // 32 - BlockAlign (== NumChannels * BitsPerSample/8)
+ 16,0, // 34 - BitsPerSample
+ 'd','a','t','a', // 36 - Subchunk2ID
+ 0,0,0,0 // 40 - Subchunk2Size
+ };
+#endif
+
+void xxx2wav_set_api(struct codec_api* rb)
+{
+ local_rb = rb;
+}
+
+#if 0
+int local_init(char* infilename, char* outfilename,
+ file_info_struct* file_info,
+ struct codec_api* rb)
+{
+ char s[32];
+ int i,n,bytesleft;
+
+ local_rb=rb;
+
+ mem_ptr=0;
+ audiobuf=local_rb->plugin_get_audio_buffer(&bufsize);
+ mallocbuf=audiobuf;
+ filebuf=&audiobuf[MALLOC_BUFSIZE];
+
+ local_rb->snprintf(s,32,"audio bufsize: %d",bufsize);
+ local_rb->lcd_putsxy(0,100,s);
+ local_rb->lcd_update();
+
+ file_info->infile=local_rb->open(infilename,O_RDONLY);
+ file_info->outfile=local_rb->creat(outfilename,O_WRONLY);
+ local_rb->write(file_info->outfile,wav_header,sizeof(wav_header));
+ file_info->curpos=0;
+ file_info->current_sample=0;
+ file_info->frames_decoded=0;
+ file_info->filesize=local_rb->filesize(file_info->infile);
+
+ local_rb->splash(HZ, true, "in: %d, size: %d", file_info->infile, file_info->filesize);
+
+ if (file_info->filesize > (bufsize-MALLOC_BUFSIZE)) {
+ local_rb->close(file_info->infile);
+ local_rb->splash(HZ*2, true, "File too large");
+ return(1);
+ }
+
+ local_rb->snprintf(s,32,"Loading file...");
+ local_rb->lcd_putsxy(0,0,s);
+ local_rb->lcd_update();
+
+ bytesleft=file_info->filesize;
+ i=0;
+ while (bytesleft > 0) {
+ n=local_rb->read(file_info->infile,&filebuf[i],bytesleft);
+ if (n < 0) {
+ local_rb->close(file_info->infile);
+ local_rb->splash(HZ*2, true, "ERROR READING FILE");
+ return(1);
+ }
+ i+=n; bytesleft-=n;
+ }
+ local_rb->close(file_info->infile);
+ local_rb->lcd_clear_display();
+ return(0);
+}
+
+void close_wav(file_info_struct* file_info)
+{
+ int x;
+ int filesize=local_rb->filesize(file_info->outfile);
+
+ /* We assume 16-bit, Stereo */
+
+ local_rb->lseek(file_info->outfile,0,SEEK_SET);
+
+ // ChunkSize
+ x=filesize-8;
+ wav_header[4]=(x&0xff);
+ wav_header[5]=(x&0xff00)>>8;
+ wav_header[6]=(x&0xff0000)>>16;
+ wav_header[7]=(x&0xff000000)>>24;
+
+ // Samplerate
+ wav_header[24]=file_info->samplerate&0xff;
+ wav_header[25]=(file_info->samplerate&0xff00)>>8;
+ wav_header[26]=(file_info->samplerate&0xff0000)>>16;
+ wav_header[27]=(file_info->samplerate&0xff000000)>>24;
+
+ // ByteRate
+ x=file_info->samplerate*4;
+ wav_header[28]=(x&0xff);
+ wav_header[29]=(x&0xff00)>>8;
+ wav_header[30]=(x&0xff0000)>>16;
+ wav_header[31]=(x&0xff000000)>>24;
+
+ // Subchunk2Size
+ x=filesize-44;
+ wav_header[40]=(x&0xff);
+ wav_header[41]=(x&0xff00)>>8;
+ wav_header[42]=(x&0xff0000)>>16;
+ wav_header[43]=(x&0xff000000)>>24;
+
+ local_rb->write(file_info->outfile,wav_header,sizeof(wav_header));
+ local_rb->close(file_info->outfile);
+}
+#endif /* 0 */
+
+#endif /* CONFIG_HWCODEC == MASNONE */
diff --git a/apps/codecs/lib/xxx2wav.h b/apps/codecs/lib/xxx2wav.h
new file mode 100644
index 0000000..1fa7dc9
--- /dev/null
+++ b/apps/codecs/lib/xxx2wav.h
@@ -0,0 +1,69 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2005 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.
+ *
+ ****************************************************************************/
+
+/* Various "helper functions" common to all the xxx2wav decoder plugins */
+
+#if CONFIG_CPU == MCF5249 && !defined(SIMULATOR)
+#define ICODE_ATTR __attribute__ ((section(".icode")))
+#define IDATA_ATTR __attribute__ ((section(".idata")))
+#define USE_IRAM 1
+#else
+#define ICODE_ATTR
+#define IDATA_ATTR
+#endif
+
+/* the main data structure of the program */
+typedef struct {
+ int infile;
+ int outfile;
+ off_t curpos;
+ off_t filesize;
+ int samplerate;
+ int bitspersample;
+ int channels;
+ int frames_decoded;
+ unsigned long total_samples;
+ unsigned long current_sample;
+ unsigned long start_tick;
+} file_info_struct;
+
+#define MALLOC_BUFSIZE (512*1024)
+
+extern int mem_ptr;
+extern int bufsize;
+extern unsigned char* mp3buf; // The actual MP3 buffer from Rockbox
+extern unsigned char* mallocbuf; // 512K from the start of MP3 buffer
+extern unsigned char* filebuf; // The rest of the MP3 buffer
+
+void* codec_malloc(size_t size);
+void* codec_calloc(size_t nmemb, size_t size);
+void* codec_alloca(size_t size);
+void* codec_realloc(void* ptr, size_t size);
+void codec_free(void* ptr);
+void *memcpy(void *dest, const void *src, size_t n);
+void *memset(void *s, int c, size_t n);
+int memcmp(const void *s1, const void *s2, size_t n);
+void* memmove(const void *s1, const void *s2, size_t n);
+
+void display_status(file_info_struct* file_info);
+int local_init(char* infilename, char* outfilename,
+ file_info_struct* file_info,
+ struct codec_api* rb);
+void close_wav(file_info_struct* file_info);
+void xxx2wav_set_api(struct codec_api* rb);