/src/speex/libspeex/os_support.h
Line | Count | Source |
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 <string.h> |
38 | | #include <stdio.h> |
39 | | #include <stdlib.h> |
40 | | |
41 | | #ifdef HAVE_CONFIG_H |
42 | | #include "config.h" |
43 | | #endif |
44 | | #ifdef OS_SUPPORT_CUSTOM |
45 | | #include "os_support_custom.h" |
46 | | #endif |
47 | | |
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) |
52 | 84.3k | { |
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 | 84.3k | return calloc(size,1); |
57 | 84.3k | } Unexecuted instantiation: speex.c:speex_alloc Unexecuted instantiation: stereo.c:speex_alloc Line | Count | Source | 52 | 8.91k | { | 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 | 8.91k | return calloc(size,1); | 57 | 8.91k | } |
Unexecuted instantiation: modes_wb.c:speex_alloc Line | Count | Source | 52 | 7.01k | { | 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 | 7.01k | return calloc(size,1); | 57 | 7.01k | } |
Unexecuted instantiation: quant_lsp.c:speex_alloc Line | Count | Source | 52 | 64.4k | { | 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 | 64.4k | return calloc(size,1); | 57 | 64.4k | } |
Unexecuted instantiation: speex_callbacks.c:speex_alloc speex_header.c:speex_alloc Line | Count | Source | 52 | 3.98k | { | 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 | 3.98k | return calloc(size,1); | 57 | 3.98k | } |
Unexecuted instantiation: cb_search.c:speex_alloc Unexecuted instantiation: ltp.c:speex_alloc |
58 | | #endif |
59 | | |
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) |
63 | 0 | { |
64 | 0 | /* Scratch space doesn't need to be cleared */ |
65 | 0 | return calloc(size,1); |
66 | 0 | } Unexecuted instantiation: speex.c:speex_alloc_scratch Unexecuted instantiation: stereo.c:speex_alloc_scratch Unexecuted instantiation: bits.c:speex_alloc_scratch Unexecuted instantiation: modes_wb.c:speex_alloc_scratch Unexecuted instantiation: nb_celp.c:speex_alloc_scratch Unexecuted instantiation: quant_lsp.c:speex_alloc_scratch Unexecuted instantiation: sb_celp.c:speex_alloc_scratch Unexecuted instantiation: speex_callbacks.c:speex_alloc_scratch Unexecuted instantiation: speex_header.c:speex_alloc_scratch Unexecuted instantiation: cb_search.c:speex_alloc_scratch Unexecuted instantiation: ltp.c:speex_alloc_scratch |
67 | | #endif |
68 | | |
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) |
72 | 31 | { |
73 | 31 | return realloc(ptr, size); |
74 | 31 | } Unexecuted instantiation: speex.c:speex_realloc Unexecuted instantiation: stereo.c:speex_realloc Line | Count | Source | 72 | 31 | { | 73 | 31 | return realloc(ptr, size); | 74 | 31 | } |
Unexecuted instantiation: modes_wb.c:speex_realloc Unexecuted instantiation: nb_celp.c:speex_realloc Unexecuted instantiation: quant_lsp.c:speex_realloc Unexecuted instantiation: sb_celp.c:speex_realloc Unexecuted instantiation: speex_callbacks.c:speex_realloc Unexecuted instantiation: speex_header.c:speex_realloc Unexecuted instantiation: cb_search.c:speex_realloc Unexecuted instantiation: ltp.c:speex_realloc |
75 | | #endif |
76 | | |
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) |
80 | 80.4k | { |
81 | 80.4k | free(ptr); |
82 | 80.4k | } Unexecuted instantiation: speex.c:speex_free Unexecuted instantiation: stereo.c:speex_free Line | Count | Source | 80 | 8.91k | { | 81 | 8.91k | free(ptr); | 82 | 8.91k | } |
Unexecuted instantiation: modes_wb.c:speex_free Line | Count | Source | 80 | 7.01k | { | 81 | 7.01k | free(ptr); | 82 | 7.01k | } |
Unexecuted instantiation: quant_lsp.c:speex_free Line | Count | Source | 80 | 64.4k | { | 81 | 64.4k | free(ptr); | 82 | 64.4k | } |
Unexecuted instantiation: speex_callbacks.c:speex_free speex_header.c:speex_free Line | Count | Source | 80 | 111 | { | 81 | 111 | free(ptr); | 82 | 111 | } |
Unexecuted instantiation: cb_search.c:speex_free Unexecuted instantiation: ltp.c:speex_free |
83 | | #endif |
84 | | |
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) |
88 | 0 | { |
89 | 0 | free(ptr); |
90 | 0 | } Unexecuted instantiation: speex.c:speex_free_scratch Unexecuted instantiation: stereo.c:speex_free_scratch Unexecuted instantiation: bits.c:speex_free_scratch Unexecuted instantiation: modes_wb.c:speex_free_scratch Unexecuted instantiation: nb_celp.c:speex_free_scratch Unexecuted instantiation: quant_lsp.c:speex_free_scratch Unexecuted instantiation: sb_celp.c:speex_free_scratch Unexecuted instantiation: speex_callbacks.c:speex_free_scratch Unexecuted instantiation: speex_header.c:speex_free_scratch Unexecuted instantiation: cb_search.c:speex_free_scratch Unexecuted instantiation: ltp.c:speex_free_scratch |
91 | | #endif |
92 | | |
93 | | /** Copy n elements from src to dst. The 0* term provides compile-time type checking */ |
94 | | #ifndef OVERRIDE_SPEEX_COPY |
95 | 496k | #define SPEEX_COPY(dst, src, n) (memcpy((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) )) |
96 | | #endif |
97 | | |
98 | | /** Copy n elements from src to dst, allowing overlapping regions. The 0* term |
99 | | provides compile-time type checking */ |
100 | | #ifndef OVERRIDE_SPEEX_MOVE |
101 | 90.3k | #define SPEEX_MOVE(dst, src, n) (memmove((dst), (src), (n)*sizeof(*(dst)) + 0*((dst)-(src)) )) |
102 | | #endif |
103 | | |
104 | | /** For n elements worth of memory, set every byte to the value of c, starting at address dst */ |
105 | | #ifndef OVERRIDE_SPEEX_MEMSET |
106 | 893k | #define SPEEX_MEMSET(dst, c, n) (memset((dst), (c), (n)*sizeof(*(dst)))) |
107 | | #endif |
108 | | |
109 | | |
110 | | #ifndef OVERRIDE_SPEEX_FATAL |
111 | | static inline void _speex_fatal(const char *str, const char *file, int line) |
112 | 0 | { |
113 | 0 | fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str); |
114 | 0 | exit(1); |
115 | 0 | } Unexecuted instantiation: speex.c:_speex_fatal Unexecuted instantiation: stereo.c:_speex_fatal Unexecuted instantiation: bits.c:_speex_fatal Unexecuted instantiation: modes_wb.c:_speex_fatal Unexecuted instantiation: nb_celp.c:_speex_fatal Unexecuted instantiation: quant_lsp.c:_speex_fatal Unexecuted instantiation: sb_celp.c:_speex_fatal Unexecuted instantiation: speex_callbacks.c:_speex_fatal Unexecuted instantiation: speex_header.c:_speex_fatal Unexecuted instantiation: cb_search.c:_speex_fatal Unexecuted instantiation: ltp.c:_speex_fatal |
116 | | #endif |
117 | | |
118 | | #ifndef OVERRIDE_SPEEX_WARNING |
119 | | static inline void speex_warning(const char *str) |
120 | 0 | { |
121 | | #ifndef DISABLE_WARNINGS |
122 | | fprintf (stderr, "warning: %s\n", str); |
123 | | #endif |
124 | 0 | } Unexecuted instantiation: speex.c:speex_warning Unexecuted instantiation: stereo.c:speex_warning Unexecuted instantiation: bits.c:speex_warning Unexecuted instantiation: modes_wb.c:speex_warning Unexecuted instantiation: nb_celp.c:speex_warning Unexecuted instantiation: quant_lsp.c:speex_warning Unexecuted instantiation: sb_celp.c:speex_warning Unexecuted instantiation: speex_callbacks.c:speex_warning Unexecuted instantiation: speex_header.c:speex_warning Unexecuted instantiation: cb_search.c:speex_warning Unexecuted instantiation: ltp.c:speex_warning |
125 | | #endif |
126 | | |
127 | | #ifndef OVERRIDE_SPEEX_WARNING_INT |
128 | | static inline void speex_warning_int(const char *str, int val) |
129 | 0 | { |
130 | | #ifndef DISABLE_WARNINGS |
131 | | fprintf (stderr, "warning: %s %d\n", str, val); |
132 | | #endif |
133 | 0 | } Unexecuted instantiation: speex.c:speex_warning_int Unexecuted instantiation: stereo.c:speex_warning_int Unexecuted instantiation: bits.c:speex_warning_int Unexecuted instantiation: modes_wb.c:speex_warning_int Unexecuted instantiation: nb_celp.c:speex_warning_int Unexecuted instantiation: quant_lsp.c:speex_warning_int Unexecuted instantiation: sb_celp.c:speex_warning_int Unexecuted instantiation: speex_callbacks.c:speex_warning_int Unexecuted instantiation: speex_header.c:speex_warning_int Unexecuted instantiation: cb_search.c:speex_warning_int Unexecuted instantiation: ltp.c:speex_warning_int |
134 | | #endif |
135 | | |
136 | | #ifndef OVERRIDE_SPEEX_NOTIFY |
137 | | static inline void speex_notify(const char *str) |
138 | 5.92k | { |
139 | | #ifndef DISABLE_NOTIFICATIONS |
140 | | fprintf (stderr, "notification: %s\n", str); |
141 | | #endif |
142 | 5.92k | } Unexecuted instantiation: speex.c:speex_notify Unexecuted instantiation: stereo.c:speex_notify Line | Count | Source | 138 | 31 | { | 139 | | #ifndef DISABLE_NOTIFICATIONS | 140 | | fprintf (stderr, "notification: %s\n", str); | 141 | | #endif | 142 | 31 | } |
Unexecuted instantiation: modes_wb.c:speex_notify Line | Count | Source | 138 | 4.84k | { | 139 | | #ifndef DISABLE_NOTIFICATIONS | 140 | | fprintf (stderr, "notification: %s\n", str); | 141 | | #endif | 142 | 4.84k | } |
Unexecuted instantiation: quant_lsp.c:speex_notify Line | Count | Source | 138 | 824 | { | 139 | | #ifndef DISABLE_NOTIFICATIONS | 140 | | fprintf (stderr, "notification: %s\n", str); | 141 | | #endif | 142 | 824 | } |
Unexecuted instantiation: speex_callbacks.c:speex_notify speex_header.c:speex_notify Line | Count | Source | 138 | 227 | { | 139 | | #ifndef DISABLE_NOTIFICATIONS | 140 | | fprintf (stderr, "notification: %s\n", str); | 141 | | #endif | 142 | 227 | } |
Unexecuted instantiation: cb_search.c:speex_notify Unexecuted instantiation: ltp.c:speex_notify |
143 | | #endif |
144 | | |
145 | | #ifndef OVERRIDE_SPEEX_PUTC |
146 | | /** Speex wrapper for putc */ |
147 | | static inline void _speex_putc(int ch, void *file) |
148 | 0 | { |
149 | 0 | FILE *f = (FILE *)file; |
150 | 0 | fprintf(f, "%c", ch); |
151 | 0 | } Unexecuted instantiation: speex.c:_speex_putc Unexecuted instantiation: stereo.c:_speex_putc Unexecuted instantiation: bits.c:_speex_putc Unexecuted instantiation: modes_wb.c:_speex_putc Unexecuted instantiation: nb_celp.c:_speex_putc Unexecuted instantiation: quant_lsp.c:_speex_putc Unexecuted instantiation: sb_celp.c:_speex_putc Unexecuted instantiation: speex_callbacks.c:_speex_putc Unexecuted instantiation: speex_header.c:_speex_putc Unexecuted instantiation: cb_search.c:_speex_putc Unexecuted instantiation: ltp.c:_speex_putc |
152 | | #endif |
153 | | |
154 | 0 | #define speex_fatal(str) _speex_fatal(str, __FILE__, __LINE__); |
155 | 443k | #define speex_assert(cond) {if (!(cond)) {speex_fatal("assertion failed: " #cond);}} |
156 | | |
157 | | #ifndef RELEASE |
158 | | static inline void print_vec(float *vec, int len, char *name) |
159 | 0 | { |
160 | 0 | int i; |
161 | 0 | printf ("%s ", name); |
162 | 0 | for (i=0;i<len;i++) |
163 | 0 | printf (" %f", vec[i]); |
164 | 0 | printf ("\n"); |
165 | 0 | } Unexecuted instantiation: speex.c:print_vec Unexecuted instantiation: stereo.c:print_vec Unexecuted instantiation: bits.c:print_vec Unexecuted instantiation: modes_wb.c:print_vec Unexecuted instantiation: nb_celp.c:print_vec Unexecuted instantiation: quant_lsp.c:print_vec Unexecuted instantiation: sb_celp.c:print_vec Unexecuted instantiation: speex_callbacks.c:print_vec Unexecuted instantiation: speex_header.c:print_vec Unexecuted instantiation: cb_search.c:print_vec Unexecuted instantiation: ltp.c:print_vec |
166 | | #endif |
167 | | |
168 | | #endif |
169 | | |