00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef FIXED_GENERIC_H
00036 #define FIXED_GENERIC_H
00037
00038 #define QCONST16(x,bits) ((spx_word16_t)(.5+(x)*(1<<(bits))))
00039 #define QCONST32(x,bits) ((spx_word32_t)(.5+(x)*(1<<(bits))))
00040
00041 #define NEG16(x) (-(x))
00042 #define NEG32(x) (-(x))
00043 #define EXTRACT16(x) ((spx_word16_t)x)
00044 #define EXTEND32(x) ((spx_word32_t)x)
00045 #define SHR16(a,shift) ((a) >> (shift))
00046 #define SHL16(a,shift) ((a) << (shift))
00047 #define SHR32(a,shift) ((a) >> (shift))
00048 #define SHL32(a,shift) ((a) << (shift))
00049 #define PSHR16(a,shift) (SHR16((a)+(1<<((shift)-1)),shift))
00050 #define PSHR32(a,shift) (SHR32((a)+(1<<((shift)-1)),shift))
00051 #define SATURATE16(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
00052 #define SATURATE32(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
00053
00054 #define SHR(a,shift) ((a) >> (shift))
00055 #define SHL(a,shift) ((spx_word32_t)(a) << (shift))
00056 #define PSHR(a,shift) (SHR((a)+(1<<((shift)-1)),shift))
00057 #define SATURATE(x,a) (((x)>(a) ? (a) : (x)<-(a) ? -(a) : (x)))
00058
00059
00060 #define ADD16(a,b) ((spx_word16_t)((spx_word16_t)(a)+(spx_word16_t)(b)))
00061 #define SUB16(a,b) ((spx_word16_t)(a)-(spx_word16_t)(b))
00062 #define ADD32(a,b) ((spx_word32_t)(a)+(spx_word32_t)(b))
00063 #define SUB32(a,b) ((spx_word32_t)(a)-(spx_word32_t)(b))
00064 #define ADD64(a,b) ((spx_word64_t)(a)+(spx_word64_t)(b))
00065
00066
00067
00068 #define MULT16_16_16(a,b) ((((spx_word16_t)(a))*((spx_word16_t)(b))))
00069
00070
00071 #define MULT16_16(a,b) (((spx_word32_t)(spx_word16_t)(a))*((spx_word32_t)(spx_word16_t)(b)))
00072
00073 #define MAC16_16(c,a,b) (ADD32((c),MULT16_16((a),(b))))
00074 #define MULT16_32_Q12(a,b) ADD32(MULT16_16((a),SHR((b),12)), SHR(MULT16_16((a),((b)&0x00000fff)),12))
00075 #define MULT16_32_Q13(a,b) ADD32(MULT16_16((a),SHR((b),13)), SHR(MULT16_16((a),((b)&0x00001fff)),13))
00076 #define MULT16_32_Q14(a,b) ADD32(MULT16_16((a),SHR((b),14)), SHR(MULT16_16((a),((b)&0x00003fff)),14))
00077
00078 #define MULT16_32_Q11(a,b) ADD32(MULT16_16((a),SHR((b),11)), SHR(MULT16_16((a),((b)&0x000007ff)),11))
00079 #define MAC16_32_Q11(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),11)), SHR(MULT16_16((a),((b)&0x000007ff)),11)))
00080
00081 #define MULT16_32_Q15(a,b) ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15))
00082 #define MAC16_32_Q15(c,a,b) ADD32(c,ADD32(MULT16_16((a),SHR((b),15)), SHR(MULT16_16((a),((b)&0x00007fff)),15)))
00083
00084
00085 #define MAC16_16_Q11(c,a,b) (ADD32((c),SHR(MULT16_16((a),(b)),11)))
00086 #define MAC16_16_Q13(c,a,b) (ADD32((c),SHR(MULT16_16((a),(b)),13)))
00087
00088 #define MULT16_16_Q11_32(a,b) (SHR(MULT16_16((a),(b)),11))
00089 #define MULT16_16_Q13(a,b) (SHR(MULT16_16((a),(b)),13))
00090 #define MULT16_16_Q14(a,b) (SHR(MULT16_16((a),(b)),14))
00091 #define MULT16_16_Q15(a,b) (SHR(MULT16_16((a),(b)),15))
00092
00093 #define MULT16_16_P13(a,b) (SHR(ADD32(4096,MULT16_16((a),(b))),13))
00094 #define MULT16_16_P14(a,b) (SHR(ADD32(8192,MULT16_16((a),(b))),14))
00095 #define MULT16_16_P15(a,b) (SHR(ADD32(16384,MULT16_16((a),(b))),15))
00096
00097 #define MUL_16_32_R15(a,bh,bl) ADD32(MULT16_16((a),(bh)), SHR(MULT16_16((a),(bl)),15))
00098
00099 #define DIV32_16(a,b) ((spx_word16_t)(((spx_word32_t)(a))/((spx_word16_t)(b))))
00100 #define DIV32(a,b) (((spx_word32_t)(a))/((spx_word32_t)(b)))
00101
00102 #endif