Add per-user preferences support.
[chromium-blink-merge.git] / third_party / speex / libspeex / os_support.h
blob6b74b0c22f1384eaa935bf64c2af7b46053c87c1
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 <string.h>
38 #include <stdio.h>
39 #include <stdlib.h>
41 #ifdef HAVE_CONFIG_H
42 #include "config.h"
43 #endif
44 #ifdef OS_SUPPORT_CUSTOM
45 #include "os_support_custom.h"
46 #endif
48 /** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, speex_realloc and speex_free
49 NOTE: speex_alloc needs to CLEAR THE MEMORY */
50 #ifndef OVERRIDE_SPEEX_ALLOC
51 static inline void *speex_alloc (int size)
53 /* WARNING: this is not equivalent to malloc(). If you want to use malloc()
54 or your own allocator, YOU NEED TO CLEAR THE MEMORY ALLOCATED. Otherwise
55 you will experience strange bugs */
56 return calloc(size,1);
58 #endif
60 /** Same as speex_alloc, except that the area is only needed inside a Speex call (might cause problem with wideband though) */
61 #ifndef OVERRIDE_SPEEX_ALLOC_SCRATCH
62 static inline void *speex_alloc_scratch (int size)
64 /* Scratch space doesn't need to be cleared */
65 return calloc(size,1);
67 #endif
69 /** Speex wrapper for realloc. To do your own dynamic allocation, all you need to do is replace this function, speex_alloc and speex_free */
70 #ifndef OVERRIDE_SPEEX_REALLOC
71 static inline void *speex_realloc (void *ptr, int size)
73 return realloc(ptr, size);
75 #endif
77 /** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, speex_realloc and speex_alloc */
78 #ifndef OVERRIDE_SPEEX_FREE
79 static inline void speex_free (void *ptr)
81 free(ptr);
83 #endif
85 /** Same as speex_free, except that the area is only needed inside a Speex call (might cause problem with wideband though) */
86 #ifndef OVERRIDE_SPEEX_FREE_SCRATCH
87 static inline void speex_free_scratch (void *ptr)
89 free(ptr);
91 #endif
93 /** Copy n bytes of memory from src to dst. The 0* term provides compile-time type checking */
94 #ifndef OVERRIDE_SPEEX_COPY
95 #define SPEEX_COPY(dst, src, n) (memcpy((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) ))
96 #endif
98 /** Copy n bytes of memory from src to dst, allowing overlapping regions. The 0* term
99 provides compile-time type checking */
100 #ifndef OVERRIDE_SPEEX_MOVE
101 #define SPEEX_MOVE(dst, src, n) (memmove((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) ))
102 #endif
104 /** Set n bytes of memory to value of c, starting at address s */
105 #ifndef OVERRIDE_SPEEX_MEMSET
106 #define SPEEX_MEMSET(dst, c, n) (memset((dst), (c), (n)*sizeof(*(dst))))
107 #endif
110 #ifndef OVERRIDE_SPEEX_FATAL
111 static inline void _speex_fatal(const char *str, const char *file, int line)
113 fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str);
114 exit(1);
116 #endif
118 #ifndef OVERRIDE_SPEEX_WARNING
119 static inline void speex_warning(const char *str)
121 #ifndef DISABLE_WARNINGS
122 fprintf (stderr, "warning: %s\n", str);
123 #endif
125 #endif
127 #ifndef OVERRIDE_SPEEX_WARNING_INT
128 static inline void speex_warning_int(const char *str, int val)
130 #ifndef DISABLE_WARNINGS
131 fprintf (stderr, "warning: %s %d\n", str, val);
132 #endif
134 #endif
136 #ifndef OVERRIDE_SPEEX_NOTIFY
137 static inline void speex_notify(const char *str)
139 #ifndef DISABLE_NOTIFICATIONS
140 fprintf (stderr, "notification: %s\n", str);
141 #endif
143 #endif
145 #ifndef OVERRIDE_SPEEX_PUTC
146 /** Speex wrapper for putc */
147 static inline void _speex_putc(int ch, void *file)
149 FILE *f = (FILE *)file;
150 fprintf(f, "%c", ch);
152 #endif
154 #define speex_fatal(str) _speex_fatal(str, __FILE__, __LINE__);
155 #define speex_assert(cond) {if (!(cond)) {speex_fatal("assertion failed: " #cond);}}
157 #ifndef RELEASE
158 static inline void print_vec(float *vec, int len, char *name)
160 int i;
161 printf ("%s ", name);
162 for (i=0;i<len;i++)
163 printf (" %f", vec[i]);
164 printf ("\n");
166 #endif
168 #endif