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 #ifndef __CODECLIB_H__
23 #define __CODECLIB_H__
27 #include <sys/types.h>
31 extern struct codec_api
*ci
;
32 extern size_t mem_ptr
;
33 extern size_t bufsize
;
34 extern unsigned char* mp3buf
; /* The actual MP3 buffer from Rockbox */
35 extern unsigned char* mallocbuf
; /* The free space after the codec in the codec buffer */
36 extern unsigned char* filebuf
; /* The rest of the MP3 buffer */
38 /* Standard library functions that are used by the codecs follow here */
40 /* Get these functions 'out of the way' of the standard functions. Not doing
41 * so confuses the cygwin linker, and maybe others. These functions need to
42 * be implemented elsewhere */
43 #define malloc(x) codec_malloc(x)
44 #define calloc(x,y) codec_calloc(x,y)
45 #define realloc(x,y) codec_realloc(x,y)
46 #define free(x) codec_free(x)
47 #define alloca(x) __builtin_alloca(x)
49 void* codec_malloc(size_t size
);
50 void* codec_calloc(size_t nmemb
, size_t size
);
51 void* codec_realloc(void* ptr
, size_t size
);
52 void codec_free(void* ptr
);
54 void *memcpy(void *dest
, const void *src
, size_t n
);
55 void *memset(void *s
, int c
, size_t n
);
56 int memcmp(const void *s1
, const void *s2
, size_t n
);
57 void *memmove(void *s1
, const void *s2
, size_t n
);
59 size_t strlen(const char *s
);
60 char *strcpy(char *dest
, const char *src
);
61 char *strcat(char *dest
, const char *src
);
62 int strcmp(const char *, const char *);
64 void qsort(void *base
, size_t nmemb
, size_t size
, int(*compar
)(const void *, const void *));
66 /*MDCT library functions*/
68 extern void mdct_backward(int n
, int32_t *in
, int32_t *out
);
69 /* -2- ffmpeg fft-based mdct */
70 extern void ff_imdct_half(unsigned int nbits
, int32_t *output
, const int32_t *input
);
71 extern void ff_imdct_calc(unsigned int nbits
, int32_t *output
, const int32_t *input
);
72 /*ffmpeg fft (can be used without mdct)*/
73 extern void ff_fft_calc_c(int nbits
, FFTComplex
*z
);
75 #if !defined(CPU_ARM) || ARM_ARCH < 5
76 /* From libavutil/common.h */
77 extern const uint8_t bs_log2_tab
[256] ICONST_ATTR
;
78 extern const uint8_t bs_clz_tab
[256] ICONST_ATTR
;
81 #define BS_LOG2 0 /* default personality, equivalent floor(log2(x)) */
82 #define BS_CLZ 1 /* alternate personality, Count Leading Zeros */
83 #define BS_SHORT 2 /* input guaranteed not to exceed 16 bits */
84 #define BS_0_0 4 /* guarantee mapping of 0 input to 0 output */
86 /* Generic bit-scanning function, used to wrap platform CLZ instruction or
87 scan-and-lookup code, and to provide control over output for 0 inputs. */
88 static inline unsigned int bs_generic(unsigned int v
, int mode
)
90 #if defined(CPU_ARM) && ARM_ARCH >= 5
91 unsigned int r
= __builtin_clz(v
);
98 /* If mode is constant, this is a single conditional instruction */
99 if (mode
& BS_0_0
&& (signed)r
< 0)
103 const uint8_t *bs_tab
;
107 /* Set up table, increment, and initial result value based on
115 bs_tab
= bs_log2_tab
;
119 if (!(mode
& BS_SHORT
) && n
>= 0x10000) {
128 /* The high 24 bits of n are guaranteed empty after the above, so a
129 superfluous ext.b instruction can be saved by loading the LUT value over
132 "move.b (%1,%0.l),%0"
140 if (mode
& BS_CLZ
&& mode
& BS_0_0
&& v
== 0)
146 /* TODO figure out if we really need to care about calculating
148 #define av_log2(v) bs_generic(v, BS_0_0)
150 /* Various codec helper functions */
152 int codec_init(void);
153 void codec_set_replaygain(struct mp3entry
* id3
);
156 void __cyg_profile_func_enter(void *this_fn
, void *call_site
)
157 NO_PROF_ATTR ICODE_ATTR
;
158 void __cyg_profile_func_exit(void *this_fn
, void *call_site
)
159 NO_PROF_ATTR ICODE_ATTR
;
162 #endif /* __CODECLIB_H__ */