Updated our source code header to explicitly mention that we are GPL v2 or
[Rockbox.git] / apps / codecs / lib / codeclib.c
blob342e6b7799ee470495a8e8460accba1fb514ea7e
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 "id3.h"
30 long mem_ptr;
31 long 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->get_codec_memory((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 #ifdef RB_PROFILE
142 void __cyg_profile_func_enter(void *this_fn, void *call_site) {
143 #ifdef CPU_COLDFIRE
144 (void)call_site;
145 ci->profile_func_enter(this_fn, __builtin_return_address(1));
146 #else
147 ci->profile_func_enter(this_fn, call_site);
148 #endif
151 void __cyg_profile_func_exit(void *this_fn, void *call_site) {
152 ci->profile_func_exit(this_fn,call_site);
154 #endif