1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 */
30 /* The following variables are used by codec_malloc() to make use of free RAM
31 * within the statically allocated codec buffer. */
32 static size_t mem_ptr
;
33 static size_t bufsize
;
34 static unsigned char* mallocbuf
;
38 /* codec_get_buffer() aligns the resulting point to CACHEALIGN_SIZE. */
40 mallocbuf
= (unsigned char *)ci
->codec_get_buffer((size_t *)&bufsize
);
45 void codec_set_replaygain(const struct mp3entry
*id3
)
47 ci
->configure(DSP_SET_TRACK_GAIN
, id3
->track_gain
);
48 ci
->configure(DSP_SET_ALBUM_GAIN
, id3
->album_gain
);
49 ci
->configure(DSP_SET_TRACK_PEAK
, id3
->track_peak
);
50 ci
->configure(DSP_SET_ALBUM_PEAK
, id3
->album_peak
);
53 /* Various "helper functions" common to all the xxx2wav decoder plugins */
56 void* codec_malloc(size_t size
)
60 if (mem_ptr
+ (long)size
> bufsize
)
63 x
=&mallocbuf
[mem_ptr
];
65 /* Keep memory aligned to CACHEALIGN_SIZE. */
66 mem_ptr
+= (size
+ (CACHEALIGN_SIZE
-1)) & ~(CACHEALIGN_SIZE
-1);
71 void* codec_calloc(size_t nmemb
, size_t size
)
74 x
= codec_malloc(nmemb
*size
);
77 ci
->memset(x
,0,nmemb
*size
);
81 void codec_free(void* ptr
) {
85 void* codec_realloc(void* ptr
, size_t size
)
89 x
= codec_malloc(size
);
93 size_t strlen(const char *s
)
95 return(ci
->strlen(s
));
98 char *strcpy(char *dest
, const char *src
)
100 return(ci
->strcpy(dest
,src
));
103 char *strcat(char *dest
, const char *src
)
105 return(ci
->strcat(dest
,src
));
108 int strcmp(const char *s1
, const char *s2
)
110 return(ci
->strcmp(s1
,s2
));
113 void *memcpy(void *dest
, const void *src
, size_t n
)
115 return(ci
->memcpy(dest
,src
,n
));
118 void *memset(void *s
, int c
, size_t n
)
120 return(ci
->memset(s
,c
,n
));
123 int memcmp(const void *s1
, const void *s2
, size_t n
)
125 return(ci
->memcmp(s1
,s2
,n
));
128 void* memchr(const void *s
, int c
, size_t n
)
130 return(ci
->memchr(s
,c
,n
));
133 void *memmove(void *dest
, const void *src
, size_t n
)
135 return(ci
->memmove(dest
,src
,n
));
138 void qsort(void *base
, size_t nmemb
, size_t size
,
139 int(*compar
)(const void *, const void *))
141 ci
->qsort(base
,nmemb
,size
,compar
);
144 /* From ffmpeg - libavutil/common.h */
145 const uint8_t bs_log2_tab
[256] ICONST_ATTR
= {
146 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,
147 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,
148 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,
149 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,
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,
151 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,
152 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 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
156 const uint8_t bs_clz_tab
[256] ICONST_ATTR
= {
157 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,
158 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,
159 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,
160 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,
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,
162 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,
163 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 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
168 void __cyg_profile_func_enter(void *this_fn
, void *call_site
) {
169 /* This workaround is required for coldfire gcc 3.4 but is broken for 4.4
170 and 4.5, but for those the other way works. */
171 #if defined(CPU_COLDFIRE) && defined(__GNUC__) && __GNUC__ < 4
173 ci
->profile_func_enter(this_fn
, __builtin_return_address(1));
175 ci
->profile_func_enter(this_fn
, call_site
);
179 void __cyg_profile_func_exit(void *this_fn
, void *call_site
) {
180 ci
->profile_func_exit(this_fn
,call_site
);