media/libspeex_resampler/src/fixed_generic.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libspeex_resampler/src/fixed_generic.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,106 @@
     1.4 +/* Copyright (C) 2003 Jean-Marc Valin */
     1.5 +/**
     1.6 +   @file fixed_generic.h
     1.7 +   @brief Generic fixed-point operations
     1.8 +*/
     1.9 +/*
    1.10 +   Redistribution and use in source and binary forms, with or without
    1.11 +   modification, are permitted provided that the following conditions
    1.12 +   are met:
    1.13 +   
    1.14 +   - Redistributions of source code must retain the above copyright
    1.15 +   notice, this list of conditions and the following disclaimer.
    1.16 +   
    1.17 +   - Redistributions in binary form must reproduce the above copyright
    1.18 +   notice, this list of conditions and the following disclaimer in the
    1.19 +   documentation and/or other materials provided with the distribution.
    1.20 +   
    1.21 +   - Neither the name of the Xiph.org Foundation nor the names of its
    1.22 +   contributors may be used to endorse or promote products derived from
    1.23 +   this software without specific prior written permission.
    1.24 +   
    1.25 +   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    1.26 +   ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    1.27 +   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    1.28 +   A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR
    1.29 +   CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    1.30 +   EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    1.31 +   PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    1.32 +   PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
    1.33 +   LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
    1.34 +   NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
    1.35 +   SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    1.36 +*/
    1.37 +
    1.38 +#ifndef FIXED_GENERIC_H
    1.39 +#define FIXED_GENERIC_H
    1.40 +
    1.41 +#define QCONST16(x,bits) ((spx_word16_t)(.5+(x)*(((spx_word32_t)1)<<(bits))))
    1.42 +#define QCONST32(x,bits) ((spx_word32_t)(.5+(x)*(((spx_word32_t)1)<<(bits))))
    1.43 +
    1.44 +#define NEG16(x) (-(x))
    1.45 +#define NEG32(x) (-(x))
    1.46 +#define EXTRACT16(x) ((spx_word16_t)(x))
    1.47 +#define EXTEND32(x) ((spx_word32_t)(x))
    1.48 +#define SHR16(a,shift) ((a) >> (shift))
    1.49 +#define SHL16(a,shift) ((a) << (shift))
    1.50 +#define SHR32(a,shift) ((a) >> (shift))
    1.51 +#define SHL32(a,shift) ((a) << (shift))
    1.52 +#define PSHR16(a,shift) (SHR16((a)+((1<<((shift))>>1)),shift))
    1.53 +#define PSHR32(a,shift) (SHR32((a)+((EXTEND32(1)<<((shift))>>1)),shift))
    1.54 +#define VSHR32(a, shift) (((shift)>0) ? SHR32(a, shift) : SHL32(a, -(shift)))
    1.55 +#define SATURATE16(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
    1.56 +#define SATURATE32(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
    1.57 +
    1.58 +#define SHR(a,shift) ((a) >> (shift))
    1.59 +#define SHL(a,shift) ((spx_word32_t)(a) << (shift))
    1.60 +#define PSHR(a,shift) (SHR((a)+((EXTEND32(1)<<((shift))>>1)),shift))
    1.61 +#define SATURATE(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
    1.62 +
    1.63 +
    1.64 +#define ADD16(a,b) ((spx_word16_t)((spx_word16_t)(a)+(spx_word16_t)(b)))
    1.65 +#define SUB16(a,b) ((spx_word16_t)(a)-(spx_word16_t)(b))
    1.66 +#define ADD32(a,b) ((spx_word32_t)(a)+(spx_word32_t)(b))
    1.67 +#define SUB32(a,b) ((spx_word32_t)(a)-(spx_word32_t)(b))
    1.68 +
    1.69 +
    1.70 +/* result fits in 16 bits */
    1.71 +#define MULT16_16_16(a,b)     ((((spx_word16_t)(a))*((spx_word16_t)(b))))
    1.72 +
    1.73 +/* (spx_word32_t)(spx_word16_t) gives TI compiler a hint that it's 16x16->32 multiply */
    1.74 +#define MULT16_16(a,b)     (((spx_word32_t)(spx_word16_t)(a))*((spx_word32_t)(spx_word16_t)(b)))
    1.75 +
    1.76 +#define MAC16_16(c,a,b) (ADD32((c),MULT16_16((a),(b))))
    1.77 +#define MULT16_32_Q12(a,b) ADD32(MULT16_16((a),SHR((b),12)), SHR(MULT16_16((a),((b)&0x00000fff)),12))
    1.78 +#define MULT16_32_Q13(a,b) ADD32(MULT16_16((a),SHR((b),13)), SHR(MULT16_16((a),((b)&0x00001fff)),13))
    1.79 +#define MULT16_32_Q14(a,b) ADD32(MULT16_16((a),SHR((b),14)), SHR(MULT16_16((a),((b)&0x00003fff)),14))
    1.80 +
    1.81 +#define MULT16_32_Q11(a,b) ADD32(MULT16_16((a),SHR((b),11)), SHR(MULT16_16((a),((b)&0x000007ff)),11))
    1.82 +#define MAC16_32_Q11(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),11)), SHR(MULT16_16((a),((b)&0x000007ff)),11)))
    1.83 +
    1.84 +#define MULT16_32_P15(a,b) ADD32(MULT16_16((a),SHR((b),15)), PSHR(MULT16_16((a),((b)&0x00007fff)),15))
    1.85 +#define MULT16_32_Q15(a,b) ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15))
    1.86 +#define MAC16_32_Q15(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15)))
    1.87 +
    1.88 +
    1.89 +#define MAC16_16_Q11(c,a,b)     (ADD32((c),SHR(MULT16_16((a),(b)),11)))
    1.90 +#define MAC16_16_Q13(c,a,b)     (ADD32((c),SHR(MULT16_16((a),(b)),13)))
    1.91 +#define MAC16_16_P13(c,a,b)     (ADD32((c),SHR(ADD32(4096,MULT16_16((a),(b))),13)))
    1.92 +
    1.93 +#define MULT16_16_Q11_32(a,b) (SHR(MULT16_16((a),(b)),11))
    1.94 +#define MULT16_16_Q13(a,b) (SHR(MULT16_16((a),(b)),13))
    1.95 +#define MULT16_16_Q14(a,b) (SHR(MULT16_16((a),(b)),14))
    1.96 +#define MULT16_16_Q15(a,b) (SHR(MULT16_16((a),(b)),15))
    1.97 +
    1.98 +#define MULT16_16_P13(a,b) (SHR(ADD32(4096,MULT16_16((a),(b))),13))
    1.99 +#define MULT16_16_P14(a,b) (SHR(ADD32(8192,MULT16_16((a),(b))),14))
   1.100 +#define MULT16_16_P15(a,b) (SHR(ADD32(16384,MULT16_16((a),(b))),15))
   1.101 +
   1.102 +#define MUL_16_32_R15(a,bh,bl) ADD32(MULT16_16((a),(bh)), SHR(MULT16_16((a),(bl)),15))
   1.103 +
   1.104 +#define DIV32_16(a,b) ((spx_word16_t)(((spx_word32_t)(a))/((spx_word16_t)(b))))
   1.105 +#define PDIV32_16(a,b) ((spx_word16_t)(((spx_word32_t)(a)+((spx_word16_t)(b)>>1))/((spx_word16_t)(b))))
   1.106 +#define DIV32(a,b) (((spx_word32_t)(a))/((spx_word32_t)(b)))
   1.107 +#define PDIV32(a,b) (((spx_word32_t)(a)+((spx_word16_t)(b)>>1))/((spx_word32_t)(b)))
   1.108 +
   1.109 +#endif

mercurial