Another logf fix in voice_thread.c
[kugel-rb.git] / apps / codecs / lib / codeclib.c
blob329b0e2136f32173cd5e0a4ff9585c10f38ec352
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 Dave Chapman
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 /* "helper functions" common to all codecs */
24 #include <string.h>
25 #include "codecs.h"
26 #include "dsp.h"
27 #include "codeclib.h"
28 #include "metadata.h"
30 size_t mem_ptr;
31 size_t bufsize;
32 unsigned char* mp3buf; // The actual MP3 buffer from Rockbox
33 unsigned char* mallocbuf; // 512K from the start of MP3 buffer
34 unsigned char* filebuf; // The rest of the MP3 buffer
36 int codec_init(void)
38 mem_ptr = 0;
39 mallocbuf = (unsigned char *)ci->codec_get_buffer((size_t *)&bufsize);
41 return 0;
44 void codec_set_replaygain(struct mp3entry* id3)
46 ci->configure(DSP_SET_TRACK_GAIN, id3->track_gain);
47 ci->configure(DSP_SET_ALBUM_GAIN, id3->album_gain);
48 ci->configure(DSP_SET_TRACK_PEAK, id3->track_peak);
49 ci->configure(DSP_SET_ALBUM_PEAK, id3->album_peak);
52 /* Various "helper functions" common to all the xxx2wav decoder plugins */
55 void* codec_malloc(size_t size)
57 void* x;
59 if (mem_ptr + (long)size > bufsize)
60 return NULL;
62 x=&mallocbuf[mem_ptr];
63 mem_ptr+=(size+3)&~3; /* Keep memory 32-bit aligned */
65 return(x);
68 void* codec_calloc(size_t nmemb, size_t size)
70 void* x;
71 x = codec_malloc(nmemb*size);
72 if (x == NULL)
73 return NULL;
74 ci->memset(x,0,nmemb*size);
75 return(x);
78 void codec_free(void* ptr) {
79 (void)ptr;
82 void* codec_realloc(void* ptr, size_t size)
84 void* x;
85 (void)ptr;
86 x = codec_malloc(size);
87 return(x);
90 size_t strlen(const char *s)
92 return(ci->strlen(s));
95 char *strcpy(char *dest, const char *src)
97 return(ci->strcpy(dest,src));
100 char *strcat(char *dest, const char *src)
102 return(ci->strcat(dest,src));
105 int strcmp(const char *s1, const char *s2)
107 return(ci->strcmp(s1,s2));
110 void *memcpy(void *dest, const void *src, size_t n)
112 return(ci->memcpy(dest,src,n));
115 void *memset(void *s, int c, size_t n)
117 return(ci->memset(s,c,n));
120 int memcmp(const void *s1, const void *s2, size_t n)
122 return(ci->memcmp(s1,s2,n));
125 void* memchr(const void *s, int c, size_t n)
127 return(ci->memchr(s,c,n));
130 void *memmove(void *dest, const void *src, size_t n)
132 return(ci->memmove(dest,src,n));
135 void qsort(void *base, size_t nmemb, size_t size,
136 int(*compar)(const void *, const void *))
138 ci->qsort(base,nmemb,size,compar);
141 /* From ffmpeg - libavutil/common.h */
142 const uint8_t bs_log2_tab[256] ICONST_ATTR = {
143 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,
144 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
145 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
146 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
147 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
148 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
149 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
150 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7
153 const uint8_t bs_clz_tab[256] ICONST_ATTR = {
154 8,7,6,6,5,5,5,5,4,4,4,4,4,4,4,4,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
155 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
156 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,
157 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,
158 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
159 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
160 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
161 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
164 #ifdef RB_PROFILE
165 void __cyg_profile_func_enter(void *this_fn, void *call_site) {
166 #ifdef CPU_COLDFIRE
167 (void)call_site;
168 ci->profile_func_enter(this_fn, __builtin_return_address(1));
169 #else
170 ci->profile_func_enter(this_fn, call_site);
171 #endif
174 void __cyg_profile_func_exit(void *this_fn, void *call_site) {
175 ci->profile_func_exit(this_fn,call_site);
177 #endif