add SMAF codec (.mmf extension)(FS#10432)
[kugel-rb.git] / apps / codecs / libspeex / os_support.h
blob71d24753c114efb410fc28b4a090cddc3d85e4d9
1 /* Copyright (C) 2007 Jean-Marc Valin
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.
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are
9 met:
11 1. Redistributions of source code must retain the above copyright notice,
12 this list of conditions and the following disclaimer.
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.
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.
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.
34 #ifndef OS_SUPPORT_H
35 #define OS_SUPPORT_H
37 #include "config-speex.h"
38 #include "rockbox.h"
40 #include <string.h>
41 #include <stdio.h>
42 #include <stdlib.h>
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)
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);
54 #endif
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)
60 /* Scratch space doesn't need to be cleared */
61 return calloc(size,1);
63 #endif
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)
69 return realloc(ptr, size);
71 #endif
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)
77 free(ptr);
79 #endif
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)
85 free(ptr);
87 #endif
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
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
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
106 #ifndef OVERRIDE_SPEEX_FATAL
107 static inline void _speex_fatal(const char *str, const char *file, int line)
109 fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str);
110 exit(1);
112 #endif
114 #ifndef OVERRIDE_SPEEX_WARNING
115 static inline void speex_warning(const char *str)
117 #ifndef DISABLE_WARNINGS
118 fprintf (stderr, "warning: %s\n", str);
119 #endif
121 #endif
123 #ifndef OVERRIDE_SPEEX_WARNING_INT
124 static inline void speex_warning_int(const char *str, int val)
126 #ifndef DISABLE_WARNINGS
127 fprintf (stderr, "warning: %s %d\n", str, val);
128 #endif
130 #endif
132 #ifndef OVERRIDE_SPEEX_NOTIFY
133 static inline void speex_notify(const char *str)
135 #ifndef DISABLE_NOTIFICATIONS
136 fprintf (stderr, "notification: %s\n", str);
137 #endif
139 #endif
141 #ifndef OVERRIDE_SPEEX_PUTC
142 /** Speex wrapper for putc */
143 static inline void _speex_putc(int ch, void *file)
145 FILE *f = (FILE *)file;
146 fprintf(f, "%c", ch);
148 #endif
150 #define speex_fatal(str) _speex_fatal(str, __FILE__, __LINE__);
151 #define speex_assert(cond) {if (!(cond)) {speex_fatal("assertion failed: " #cond);}}
153 #ifndef RELEASE
154 static inline void print_vec(float *vec, int len, char *name)
156 int i;
157 printf ("%s ", name);
158 for (i=0;i<len;i++)
159 printf (" %f", vec[i]);
160 printf ("\n");
162 #endif
164 #endif