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