diff options
Diffstat (limited to 'lib/rbcodec/codecs/libspeex/os_support.h')
-rw-r--r-- | lib/rbcodec/codecs/libspeex/os_support.h | 165 |
1 files changed, 165 insertions, 0 deletions
diff --git a/lib/rbcodec/codecs/libspeex/os_support.h b/lib/rbcodec/codecs/libspeex/os_support.h new file mode 100644 index 0000000000..71d24753c1 --- /dev/null +++ b/lib/rbcodec/codecs/libspeex/os_support.h | |||
@@ -0,0 +1,165 @@ | |||
1 | /* Copyright (C) 2007 Jean-Marc Valin | ||
2 | |||
3 | File: os_support.h | ||
4 | This is the (tiny) OS abstraction layer. Aside from math.h, this is the | ||
5 | only place where system headers are allowed. | ||
6 | |||
7 | Redistribution and use in source and binary forms, with or without | ||
8 | modification, are permitted provided that the following conditions are | ||
9 | met: | ||
10 | |||
11 | 1. Redistributions of source code must retain the above copyright notice, | ||
12 | this list of conditions and the following disclaimer. | ||
13 | |||
14 | 2. Redistributions in binary form must reproduce the above copyright | ||
15 | notice, this list of conditions and the following disclaimer in the | ||
16 | documentation and/or other materials provided with the distribution. | ||
17 | |||
18 | 3. The name of the author may not be used to endorse or promote products | ||
19 | derived from this software without specific prior written permission. | ||
20 | |||
21 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
22 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
23 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
24 | DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, | ||
25 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | ||
26 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
27 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
28 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
29 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
30 | ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
31 | POSSIBILITY OF SUCH DAMAGE. | ||
32 | */ | ||
33 | |||
34 | #ifndef OS_SUPPORT_H | ||
35 | #define OS_SUPPORT_H | ||
36 | |||
37 | #include "config-speex.h" | ||
38 | #include "rockbox.h" | ||
39 | |||
40 | #include <string.h> | ||
41 | #include <stdio.h> | ||
42 | #include <stdlib.h> | ||
43 | |||
44 | /** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, speex_realloc and speex_free | ||
45 | NOTE: speex_alloc needs to CLEAR THE MEMORY */ | ||
46 | #ifndef OVERRIDE_SPEEX_ALLOC | ||
47 | static inline void *speex_alloc (int size) | ||
48 | { | ||
49 | /* WARNING: this is not equivalent to malloc(). If you want to use malloc() | ||
50 | or your own allocator, YOU NEED TO CLEAR THE MEMORY ALLOCATED. Otherwise | ||
51 | you will experience strange bugs */ | ||
52 | return calloc(size,1); | ||
53 | } | ||
54 | #endif | ||
55 | |||
56 | /** Same as speex_alloc, except that the area is only needed inside a Speex call (might cause problem with wideband though) */ | ||
57 | #ifndef OVERRIDE_SPEEX_ALLOC_SCRATCH | ||
58 | static inline void *speex_alloc_scratch (int size) | ||
59 | { | ||
60 | /* Scratch space doesn't need to be cleared */ | ||
61 | return calloc(size,1); | ||
62 | } | ||
63 | #endif | ||
64 | |||
65 | /** Speex wrapper for realloc. To do your own dynamic allocation, all you need to do is replace this function, speex_alloc and speex_free */ | ||
66 | #ifndef OVERRIDE_SPEEX_REALLOC | ||
67 | static inline void *speex_realloc (void *ptr, int size) | ||
68 | { | ||
69 | return realloc(ptr, size); | ||
70 | } | ||
71 | #endif | ||
72 | |||
73 | /** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, speex_realloc and speex_alloc */ | ||
74 | #ifndef OVERRIDE_SPEEX_FREE | ||
75 | static inline void speex_free (void *ptr) | ||
76 | { | ||
77 | free(ptr); | ||
78 | } | ||
79 | #endif | ||
80 | |||
81 | /** Same as speex_free, except that the area is only needed inside a Speex call (might cause problem with wideband though) */ | ||
82 | #ifndef OVERRIDE_SPEEX_FREE_SCRATCH | ||
83 | static inline void speex_free_scratch (void *ptr) | ||
84 | { | ||
85 | free(ptr); | ||
86 | } | ||
87 | #endif | ||
88 | |||
89 | /** Copy n bytes of memory from src to dst. The 0* term provides compile-time type checking */ | ||
90 | #ifndef OVERRIDE_SPEEX_COPY | ||
91 | #define SPEEX_COPY(dst, src, n) (memcpy((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) )) | ||
92 | #endif | ||
93 | |||
94 | /** Copy n bytes of memory from src to dst, allowing overlapping regions. The 0* term | ||
95 | provides compile-time type checking */ | ||
96 | #ifndef OVERRIDE_SPEEX_MOVE | ||
97 | #define SPEEX_MOVE(dst, src, n) (memmove((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) )) | ||
98 | #endif | ||
99 | |||
100 | /** Set n bytes of memory to value of c, starting at address s */ | ||
101 | #ifndef OVERRIDE_SPEEX_MEMSET | ||
102 | #define SPEEX_MEMSET(dst, c, n) (memset((dst), (c), (n)*sizeof(*(dst)))) | ||
103 | #endif | ||
104 | |||
105 | |||
106 | #ifndef OVERRIDE_SPEEX_FATAL | ||
107 | static inline void _speex_fatal(const char *str, const char *file, int line) | ||
108 | { | ||
109 | fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str); | ||
110 | exit(1); | ||
111 | } | ||
112 | #endif | ||
113 | |||
114 | #ifndef OVERRIDE_SPEEX_WARNING | ||
115 | static inline void speex_warning(const char *str) | ||
116 | { | ||
117 | #ifndef DISABLE_WARNINGS | ||
118 | fprintf (stderr, "warning: %s\n", str); | ||
119 | #endif | ||
120 | } | ||
121 | #endif | ||
122 | |||
123 | #ifndef OVERRIDE_SPEEX_WARNING_INT | ||
124 | static inline void speex_warning_int(const char *str, int val) | ||
125 | { | ||
126 | #ifndef DISABLE_WARNINGS | ||
127 | fprintf (stderr, "warning: %s %d\n", str, val); | ||
128 | #endif | ||
129 | } | ||
130 | #endif | ||
131 | |||
132 | #ifndef OVERRIDE_SPEEX_NOTIFY | ||
133 | static inline void speex_notify(const char *str) | ||
134 | { | ||
135 | #ifndef DISABLE_NOTIFICATIONS | ||
136 | fprintf (stderr, "notification: %s\n", str); | ||
137 | #endif | ||
138 | } | ||
139 | #endif | ||
140 | |||
141 | #ifndef OVERRIDE_SPEEX_PUTC | ||
142 | /** Speex wrapper for putc */ | ||
143 | static inline void _speex_putc(int ch, void *file) | ||
144 | { | ||
145 | FILE *f = (FILE *)file; | ||
146 | fprintf(f, "%c", ch); | ||
147 | } | ||
148 | #endif | ||
149 | |||
150 | #define speex_fatal(str) _speex_fatal(str, __FILE__, __LINE__); | ||
151 | #define speex_assert(cond) {if (!(cond)) {speex_fatal("assertion failed: " #cond);}} | ||
152 | |||
153 | #ifndef RELEASE | ||
154 | static inline void print_vec(float *vec, int len, char *name) | ||
155 | { | ||
156 | int i; | ||
157 | printf ("%s ", name); | ||
158 | for (i=0;i<len;i++) | ||
159 | printf (" %f", vec[i]); | ||
160 | printf ("\n"); | ||
161 | } | ||
162 | #endif | ||
163 | |||
164 | #endif | ||
165 | |||