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