diff options
author | jm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800> | 2007-10-20 18:04:02 +0400 |
---|---|---|
committer | jm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800> | 2007-10-20 18:04:02 +0400 |
commit | bdcefb47d29cf25aa8baaa0a37bd1378adf18b27 (patch) | |
tree | 242ff7c50e8cfd3567aa0606a51115eb630f1c1c | |
parent | fef16861b8ffb56f99a99da28356d2e837cb4493 (diff) |
Put all the OS-dependent calls in os_support.h
git-svn-id: http://svn.xiph.org/trunk/speex@14021 0101bb08-14d6-0310-b084-bc0e0c8e3800
-rw-r--r-- | libspeex/Makefile.am | 14 | ||||
-rw-r--r-- | libspeex/bits.c | 1 | ||||
-rw-r--r-- | libspeex/cb_search.c | 2 | ||||
-rw-r--r-- | libspeex/fftwrap.c | 1 | ||||
-rw-r--r-- | libspeex/filterbank.c | 1 | ||||
-rw-r--r-- | libspeex/jitter.c | 1 | ||||
-rw-r--r-- | libspeex/kiss_fft.c | 1 | ||||
-rw-r--r-- | libspeex/kiss_fftr.c | 1 | ||||
-rw-r--r-- | libspeex/math_approx.h | 23 | ||||
-rw-r--r-- | libspeex/mdf.c | 1 | ||||
-rw-r--r-- | libspeex/misc.h | 136 | ||||
-rw-r--r-- | libspeex/nb_celp.c | 1 | ||||
-rw-r--r-- | libspeex/os_support.h | 151 | ||||
-rw-r--r-- | libspeex/preprocess.c | 1 | ||||
-rw-r--r-- | libspeex/resample.c | 1 | ||||
-rw-r--r-- | libspeex/sb_celp.c | 1 | ||||
-rw-r--r-- | libspeex/smallft.c | 1 | ||||
-rw-r--r-- | libspeex/speex.c | 1 | ||||
-rw-r--r-- | libspeex/speex_callbacks.c | 1 | ||||
-rw-r--r-- | libspeex/speex_header.c | 1 |
20 files changed, 199 insertions, 142 deletions
diff --git a/libspeex/Makefile.am b/libspeex/Makefile.am index e3d0968..a5156da 100644 --- a/libspeex/Makefile.am +++ b/libspeex/Makefile.am @@ -20,13 +20,13 @@ libspeexdsp_la_SOURCES = preprocess.c smallft.c lbr_48k_tables.c \ jitter.c mdf.c fftwrap.c kiss_fft.c _kiss_fft_guts.h kiss_fft.h \ kiss_fftr.c kiss_fftr.h filterbank.c resample.c -noinst_HEADERS = lsp.h nb_celp.h lpc.h lpc_bfin.h ltp.h quant_lsp.h \ - cb_search.h filters.h stack_alloc.h vq.h vq_sse.h vq_arm4.h vq_bfin.h \ - modes.h sb_celp.h vbr.h misc.h misc_bfin.h ltp_sse.h ltp_arm4.h \ - ltp_bfin.h filters_sse.h filters_arm4.h filters_bfin.h math_approx.h \ - smallft.h arch.h fixed_arm4.h fixed_arm5e.h fixed_bfin.h fixed_debug.h \ - fixed_generic.h cb_search_sse.h cb_search_arm4.h cb_search_bfin.h \ - fftwrap.h pseudofloat.h lsp_bfin.h quant_lsp_bfin.h filterbank.h +noinst_HEADERS = arch.h cb_search_arm4.h cb_search_bfin.h cb_search_sse.h \ + filters.h filters_arm4.h filters_bfin.h filters_sse.h fixed_arm4.h \ + fixed_arm5e.h fixed_bfin.h fixed_debug.h lpc.h lpc_bfin.h ltp.h ltp_arm4.h \ + ltp_sse.h math_approx.h misc.h misc_bfin.h nb_celp.h quant_lsp.h sb_celp.h \ + stack_alloc.h vbr.h vq.h vq_arm4.h vq_bfin.h vq_sse.h cb_search.h fftwrap.h \ + filterbank.h fixed_generic.h lsp.h lsp_bfin.h ltp_bfin.h modes.h os_support.h \ + pseudofloat.h quant_lsp_bfin.h smallft.h vorbis_psy.h libspeex_la_LDFLAGS = -no-undefined -version-info @SPEEX_LT_CURRENT@:@SPEEX_LT_REVISION@:@SPEEX_LT_AGE@ diff --git a/libspeex/bits.c b/libspeex/bits.c index 2245ec6..09432a3 100644 --- a/libspeex/bits.c +++ b/libspeex/bits.c @@ -38,6 +38,7 @@ #include <speex/speex_bits.h> #include "misc.h" +#include "os_support.h" /* Maximum size of the bit-stream (for fixed-size allocation) */ #ifndef MAX_CHARS_PER_FRAME diff --git a/libspeex/cb_search.c b/libspeex/cb_search.c index a0b668a..4c0a035 100644 --- a/libspeex/cb_search.c +++ b/libspeex/cb_search.c @@ -38,6 +38,8 @@ #include "stack_alloc.h" #include "vq.h" #include "misc.h" +#include "math_approx.h" +#include "os_support.h" #ifdef _USE_SSE #include "cb_search_sse.h" diff --git a/libspeex/fftwrap.c b/libspeex/fftwrap.c index 35e2d05..f9f33b2 100644 --- a/libspeex/fftwrap.c +++ b/libspeex/fftwrap.c @@ -41,6 +41,7 @@ #include "misc.h" +#include "os_support.h" #define MAX_FFT_SIZE 2048 diff --git a/libspeex/filterbank.c b/libspeex/filterbank.c index cb7a2bc..a79050d 100644 --- a/libspeex/filterbank.c +++ b/libspeex/filterbank.c @@ -39,6 +39,7 @@ #include "misc.h" #include <math.h> #include "math_approx.h" +#include "os_support.h" #ifdef FIXED_POINT diff --git a/libspeex/jitter.c b/libspeex/jitter.c index b778f15..b6bf687 100644 --- a/libspeex/jitter.c +++ b/libspeex/jitter.c @@ -41,6 +41,7 @@ #include <speex/speex.h> #include <speex/speex_bits.h> #include <speex/speex_jitter.h> +#include "os_support.h" #ifndef NULL #define NULL 0 diff --git a/libspeex/kiss_fft.c b/libspeex/kiss_fft.c index e0ae2a9..3c6bf89 100644 --- a/libspeex/kiss_fft.c +++ b/libspeex/kiss_fft.c @@ -20,6 +20,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #include "_kiss_fft_guts.h" #include "misc.h" +#include "os_support.h" /* The guts header contains all the multiplication and addition macros that are defined for fixed or floating point complex numbers. It also delares the kf_ internal functions. diff --git a/libspeex/kiss_fftr.c b/libspeex/kiss_fftr.c index 308b131..f6275b8 100644 --- a/libspeex/kiss_fftr.c +++ b/libspeex/kiss_fftr.c @@ -16,6 +16,7 @@ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND #include "config.h" #endif +#include "os_support.h" #include "kiss_fftr.h" #include "_kiss_fft_guts.h" diff --git a/libspeex/math_approx.h b/libspeex/math_approx.h index 8421d63..1b84943 100644 --- a/libspeex/math_approx.h +++ b/libspeex/math_approx.h @@ -45,8 +45,16 @@ #define spx_cos_norm(x) (cos((.5f*M_PI)*(x))) #define spx_atan atan -#endif +/** Generate a pseudo-random number */ +static inline spx_word16_t speex_rand(spx_word16_t std, spx_int32_t *seed) +{ + spx_word32_t res; + *seed = 1664525 * *seed + 1013904223; + res = MULT16_16(EXTRACT16(SHR32(*seed,16)),std); + return EXTRACT16(PSHR32(SUB32(res, SHR32(res, 3)),14)); +} +#endif static inline spx_int16_t spx_ilog2(spx_uint32_t x) @@ -106,6 +114,19 @@ static inline spx_int16_t spx_ilog4(spx_uint32_t x) #ifdef FIXED_POINT +/** Generate a pseudo-random number */ +static inline spx_word16_t speex_rand(spx_word16_t std, spx_int32_t *seed) +{ + const unsigned int jflone = 0x3f800000; + const unsigned int jflmsk = 0x007fffff; + union {int i; float f;} ran; + *seed = 1664525 * *seed + 1013904223; + ran.i = jflone | (jflmsk & *seed); + ran.f -= 1.5; + return 3.4642*std*ran.f; +} + + /* sqrt(x) ~= 0.22178 + 1.29227*x - 0.77070*x^2 + 0.25723*x^3 (for .25 < x < 1) */ /*#define C0 3634 #define C1 21173 diff --git a/libspeex/mdf.c b/libspeex/mdf.c index 5a6fa2f..ccf6860 100644 --- a/libspeex/mdf.c +++ b/libspeex/mdf.c @@ -74,6 +74,7 @@ #include "fftwrap.h" #include "pseudofloat.h" #include "math_approx.h" +#include "os_support.h" #ifndef M_PI #define M_PI 3.14159265358979323846 diff --git a/libspeex/misc.h b/libspeex/misc.h index 3846f49..30b3146 100644 --- a/libspeex/misc.h +++ b/libspeex/misc.h @@ -35,16 +35,12 @@ #ifndef MISC_H #define MISC_H -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - #ifndef SPEEX_VERSION #define SPEEX_MAJOR_VERSION 1 /**< Major Speex version. */ #define SPEEX_MINOR_VERSION 1 /**< Minor Speex version. */ -#define SPEEX_MICRO_VERSION 14 /**< Micro Speex version. */ +#define SPEEX_MICRO_VERSION 15 /**< Micro Speex version. */ #define SPEEX_EXTRA_VERSION "" /**< Extra Speex version. */ -#define SPEEX_VERSION "speex-1.2beta2" /**< Speex version string. */ +#define SPEEX_VERSION "speex-1.2beta3" /**< Speex version string. */ #endif /* A couple test to catch stupid option combinations */ @@ -90,138 +86,10 @@ static inline spx_int32_t le_int(spx_int32_t i) #endif } -#define speex_fatal(str) _speex_fatal(str, __FILE__, __LINE__); -#define speex_assert(cond) {if (!(cond)) {speex_fatal("assertion failed: " #cond);}} - -#ifndef RELEASE -static inline void print_vec(float *vec, int len, char *name) -{ - int i; - printf ("%s ", name); - for (i=0;i<len;i++) - printf (" %f", vec[i]); - printf ("\n"); -} -#endif #ifdef FIXED_DEBUG long long spx_mips=0; #endif -/** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, speex_realloc and speex_free */ -#ifndef OVERRIDE_SPEEX_ALLOC -static inline void *speex_alloc (int size) -{ - return calloc(size,1); -} -#endif - -/** Same as speex_alloc, except that the area is only needed inside a Speex call (might cause problem with wideband though) */ -#ifndef OVERRIDE_SPEEX_ALLOC_SCRATCH -static inline void *speex_alloc_scratch (int size) -{ - return calloc(size,1); -} -#endif - -/** Speex wrapper for realloc. To do your own dynamic allocation, all you need to do is replace this function, speex_alloc and speex_free */ -#ifndef OVERRIDE_SPEEX_REALLOC -static inline void *speex_realloc (void *ptr, int size) -{ - return realloc(ptr, size); -} -#endif - -/** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, speex_realloc and speex_alloc */ -#ifndef OVERRIDE_SPEEX_FREE -static inline void speex_free (void *ptr) -{ - free(ptr); -} -#endif - -/** Same as speex_free, except that the area is only needed inside a Speex call (might cause problem with wideband though) */ -#ifndef OVERRIDE_SPEEX_FREE_SCRATCH -static inline void speex_free_scratch (void *ptr) -{ - free(ptr); -} -#endif - -/** Print warning message with integer argument to stderr */ -#ifndef OVERRIDE_SPEEX_MOVE -static inline void *speex_move (void *dest, void *src, int n) -{ - return memmove(dest,src,n); -} -#endif - -#ifndef OVERRIDE_SPEEX_FATAL -static inline void _speex_fatal(const char *str, const char *file, int line) -{ - fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str); - exit(1); -} -#endif - -#ifndef OVERRIDE_SPEEX_WARNING -static inline void speex_warning(const char *str) -{ -#ifndef DISABLE_WARNINGS - fprintf (stderr, "warning: %s\n", str); -#endif -} -#endif - -#ifndef OVERRIDE_SPEEX_WARNING_INT -static inline void speex_warning_int(const char *str, int val) -{ -#ifndef DISABLE_WARNINGS - fprintf (stderr, "warning: %s %d\n", str, val); -#endif -} -#endif - -#ifndef OVERRIDE_SPEEX_NOTIFY -static inline void speex_notify(const char *str) -{ -#ifndef DISABLE_NOTIFICATIONS - fprintf (stderr, "notification: %s\n", str); -#endif -} -#endif - -#ifdef FIXED_POINT -/** Generate a pseudo-random number */ -static inline spx_word16_t speex_rand(spx_word16_t std, spx_int32_t *seed) -{ - spx_word32_t res; - *seed = 1664525 * *seed + 1013904223; - res = MULT16_16(EXTRACT16(SHR32(*seed,16)),std); - return EXTRACT16(PSHR32(SUB32(res, SHR32(res, 3)),14)); -} -#else -/** Generate a pseudo-random number */ -static inline spx_word16_t speex_rand(spx_word16_t std, spx_int32_t *seed) -{ - const unsigned int jflone = 0x3f800000; - const unsigned int jflmsk = 0x007fffff; - union {int i; float f;} ran; - *seed = 1664525 * *seed + 1013904223; - ran.i = jflone | (jflmsk & *seed); - ran.f -= 1.5; - return 3.4642*std*ran.f; -} -#endif - -#ifndef OVERRIDE_SPEEX_PUTC -/** Speex wrapper for putc */ -static inline void _speex_putc(int ch, void *file) -{ - FILE *f = (FILE *)file; - fprintf(f, "%c", ch); -} -#endif - #endif diff --git a/libspeex/nb_celp.c b/libspeex/nb_celp.c index bf7a641..e308477 100644 --- a/libspeex/nb_celp.c +++ b/libspeex/nb_celp.c @@ -47,6 +47,7 @@ #include "vbr.h" #include "misc.h" #include "math_approx.h" +#include "os_support.h" #include <speex/speex_callbacks.h> #ifdef VORBIS_PSYCHO diff --git a/libspeex/os_support.h b/libspeex/os_support.h new file mode 100644 index 0000000..8c89d4d --- /dev/null +++ b/libspeex/os_support.h @@ -0,0 +1,151 @@ +/* Copyright (C) 2007 Jean-Marc Valin + + File: os_support.h + This is the (tiny) OS abstraction layer. Aside from math.h, this is the + only place where system headers are allowed. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are + met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + 3. The name of the author may not be used to endorse or promote products + derived from this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + +#include <string.h> +#include <stdio.h> +#include <stdlib.h> + +/** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, speex_realloc and speex_free */ +#ifndef OVERRIDE_SPEEX_ALLOC +static inline void *speex_alloc (int size) +{ + return calloc(size,1); +} +#endif + +/** Same as speex_alloc, except that the area is only needed inside a Speex call (might cause problem with wideband though) */ +#ifndef OVERRIDE_SPEEX_ALLOC_SCRATCH +static inline void *speex_alloc_scratch (int size) +{ + return calloc(size,1); +} +#endif + +/** Speex wrapper for realloc. To do your own dynamic allocation, all you need to do is replace this function, speex_alloc and speex_free */ +#ifndef OVERRIDE_SPEEX_REALLOC +static inline void *speex_realloc (void *ptr, int size) +{ + return realloc(ptr, size); +} +#endif + +/** Speex wrapper for calloc. To do your own dynamic allocation, all you need to do is replace this function, speex_realloc and speex_alloc */ +#ifndef OVERRIDE_SPEEX_FREE +static inline void speex_free (void *ptr) +{ + free(ptr); +} +#endif + +/** Same as speex_free, except that the area is only needed inside a Speex call (might cause problem with wideband though) */ +#ifndef OVERRIDE_SPEEX_FREE_SCRATCH +static inline void speex_free_scratch (void *ptr) +{ + free(ptr); +} +#endif + +/** Print warning message with integer argument to stderr */ +#ifndef OVERRIDE_SPEEX_MOVE +static inline void *speex_move (void *dest, void *src, int n) +{ + return memmove(dest,src,n); +} +#endif + +/** Print warning message with integer argument to stderr */ +#ifndef OVERRIDE_SPEEX_MOVE +static inline void *speex_memset (void *s, int c, int n) +{ + return memset(s,c,n); +} +#endif + + +#ifndef OVERRIDE_SPEEX_FATAL +static inline void _speex_fatal(const char *str, const char *file, int line) +{ + fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str); + exit(1); +} +#endif + +#ifndef OVERRIDE_SPEEX_WARNING +static inline void speex_warning(const char *str) +{ +#ifndef DISABLE_WARNINGS + fprintf (stderr, "warning: %s\n", str); +#endif +} +#endif + +#ifndef OVERRIDE_SPEEX_WARNING_INT +static inline void speex_warning_int(const char *str, int val) +{ +#ifndef DISABLE_WARNINGS + fprintf (stderr, "warning: %s %d\n", str, val); +#endif +} +#endif + +#ifndef OVERRIDE_SPEEX_NOTIFY +static inline void speex_notify(const char *str) +{ +#ifndef DISABLE_NOTIFICATIONS + fprintf (stderr, "notification: %s\n", str); +#endif +} +#endif + +#ifndef OVERRIDE_SPEEX_PUTC +/** Speex wrapper for putc */ +static inline void _speex_putc(int ch, void *file) +{ + FILE *f = (FILE *)file; + fprintf(f, "%c", ch); +} +#endif + +#define speex_fatal(str) _speex_fatal(str, __FILE__, __LINE__); +#define speex_assert(cond) {if (!(cond)) {speex_fatal("assertion failed: " #cond);}} + +#ifndef RELEASE +static inline void print_vec(float *vec, int len, char *name) +{ + int i; + printf ("%s ", name); + for (i=0;i<len;i++) + printf (" %f", vec[i]); + printf ("\n"); +} +#endif diff --git a/libspeex/preprocess.c b/libspeex/preprocess.c index bbdb19f..01b1a9b 100644 --- a/libspeex/preprocess.c +++ b/libspeex/preprocess.c @@ -66,6 +66,7 @@ #include "fftwrap.h" #include "filterbank.h" #include "math_approx.h" +#include "os_support.h" #ifndef M_PI #define M_PI 3.14159263 diff --git a/libspeex/resample.c b/libspeex/resample.c index 88ebbcc..0a0120b 100644 --- a/libspeex/resample.c +++ b/libspeex/resample.c @@ -71,6 +71,7 @@ static void speex_free (void *ptr) {free(ptr);} #include "speex/speex_resampler.h" #include "misc.h" +#include "os_support.h" #endif /* OUTSIDE_SPEEX */ #include <math.h> diff --git a/libspeex/sb_celp.c b/libspeex/sb_celp.c index 7fa6dce..d6e1432 100644 --- a/libspeex/sb_celp.c +++ b/libspeex/sb_celp.c @@ -45,6 +45,7 @@ #include "ltp.h" #include "misc.h" #include "math_approx.h" +#include "os_support.h" #ifndef NULL #define NULL 0 diff --git a/libspeex/smallft.c b/libspeex/smallft.c index 269549d..369432d 100644 --- a/libspeex/smallft.c +++ b/libspeex/smallft.c @@ -35,6 +35,7 @@ #include <math.h> #include "smallft.h" #include "misc.h" +#include "os_support.h" static void drfti1(int n, float *wa, int *ifac){ static int ntryh[4] = { 4,2,3,5 }; diff --git a/libspeex/speex.c b/libspeex/speex.c index 846e021..3316b2f 100644 --- a/libspeex/speex.c +++ b/libspeex/speex.c @@ -38,6 +38,7 @@ #include "modes.h" #include <math.h> +#include "os_support.h" #ifndef NULL #define NULL 0 diff --git a/libspeex/speex_callbacks.c b/libspeex/speex_callbacks.c index 682322e..9b69dc5 100644 --- a/libspeex/speex_callbacks.c +++ b/libspeex/speex_callbacks.c @@ -38,6 +38,7 @@ #include <speex/speex_callbacks.h> #include "misc.h" +#include "os_support.h" int speex_inband_handler(SpeexBits *bits, SpeexCallback *callback_list, void *state) { diff --git a/libspeex/speex_header.c b/libspeex/speex_header.c index 8e10851..38dba4a 100644 --- a/libspeex/speex_header.c +++ b/libspeex/speex_header.c @@ -38,6 +38,7 @@ #include "misc.h" #include <speex/speex_header.h> #include <speex/speex.h> +#include "os_support.h" #ifndef NULL #define NULL 0 |