Move av_log2 function and asociated table to the codec lib, remove 3 identical implem...
[kugel-rb.git] / apps / codecs / lib / codeclib.h
blobbf7b41775a63db0beaa3551c7d047a83c99729b1
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 #ifndef __CODECLIB_H__
23 #define __CODECLIB_H__
25 #include "config.h"
26 #include "codecs.h"
27 #include <sys/types.h>
29 extern struct codec_api *ci;
30 extern size_t mem_ptr;
31 extern size_t bufsize;
32 extern unsigned char* mp3buf; /* The actual MP3 buffer from Rockbox */
33 extern unsigned char* mallocbuf; /* The free space after the codec in the codec buffer */
34 extern unsigned char* filebuf; /* The rest of the MP3 buffer */
36 /* Standard library functions that are used by the codecs follow here */
38 /* Get these functions 'out of the way' of the standard functions. Not doing
39 * so confuses the cygwin linker, and maybe others. These functions need to
40 * be implemented elsewhere */
41 #define malloc(x) codec_malloc(x)
42 #define calloc(x,y) codec_calloc(x,y)
43 #define realloc(x,y) codec_realloc(x,y)
44 #define free(x) codec_free(x)
45 #define alloca(x) __builtin_alloca(x)
47 void* codec_malloc(size_t size);
48 void* codec_calloc(size_t nmemb, size_t size);
49 void* codec_realloc(void* ptr, size_t size);
50 void codec_free(void* ptr);
52 void *memcpy(void *dest, const void *src, size_t n);
53 void *memset(void *s, int c, size_t n);
54 int memcmp(const void *s1, const void *s2, size_t n);
55 void *memmove(void *s1, const void *s2, size_t n);
57 size_t strlen(const char *s);
58 char *strcpy(char *dest, const char *src);
59 char *strcat(char *dest, const char *src);
60 int strcmp(const char *, const char *);
62 void qsort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *));
64 /*MDCT library functions*/
66 extern void mdct_backward(int n, int32_t *in, int32_t *out);
68 #if defined(CPU_ARM) && (ARM_ARCH == 4)
69 /* optimised unsigned integer division for ARMv4, in IRAM */
70 unsigned udiv32_arm(unsigned a, unsigned b);
71 #define UDIV32(a, b) udiv32_arm(a, b)
72 #else
73 /* default */
74 #define UDIV32(a, b) (a / b)
75 #endif
77 /* TODO figure out if we really need to care about calculating
78 av_log2(0) */
79 #if (defined(CPU_ARM) && (ARM_ARCH > 4))
80 static inline unsigned int av_log2(uint32_t v)
82 unsigned int lz = __builtin_clz(v);
83 return 31 - lz + (lz >> 5); /* make sure av_log2(0) returns 0 */
85 #else
86 /* From libavutil/common.h */
87 extern const uint8_t ff_log2_tab[256] ICONST_ATTR;
89 static inline unsigned int av_log2(unsigned int v)
91 int n;
93 n = 0;
94 if (v & 0xffff0000) {
95 v >>= 16;
96 n += 16;
98 if (v & 0xff00) {
99 v >>= 8;
100 n += 8;
102 n += ff_log2_tab[v];
104 return n;
106 #endif
108 /* Various codec helper functions */
110 int codec_init(void);
111 void codec_set_replaygain(struct mp3entry* id3);
113 #ifdef RB_PROFILE
114 void __cyg_profile_func_enter(void *this_fn, void *call_site)
115 NO_PROF_ATTR ICODE_ATTR;
116 void __cyg_profile_func_exit(void *this_fn, void *call_site)
117 NO_PROF_ATTR ICODE_ATTR;
118 #endif
120 #endif /* __CODECLIB_H__ */