A lot of updates

This commit is contained in:
WolverinDEV
2019-10-26 01:51:19 +02:00
parent 53d3814f92
commit b956bad3f7
1039 changed files with 0 additions and 262642 deletions
@@ -1,188 +0,0 @@
/* Copyright (C) 2007 Hong Zhiqian */
/**
@file _kiss_fft_guts_tm.h
@author Hong Zhiqian
@brief Various compatibility routines for Speex (TriMedia version)
*/
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``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 FOUNDATION OR
CONTRIBUTORS 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.
*/
#ifndef _KISS_FFT_GUTS_TM_
#define _KISS_FFT_GUTS_TM_
#ifdef TM_ASM
#include <ops/custom_defs.h>
#ifdef FIXED_POINT
#undef sround
#define sround(x) sex16(((x) + (1<<(FRACBITS-1)) ) >> FRACBITS)
#undef MIN
#undef MAX
#define MIN(a,b) imin(a,b)
#define MAX(a,b) imax(a,b)
#define TM_MUL(res,a,b) \
{ register int a0, a1, b0, b1; \
\
a0 = sex16((a)); \
a1 = asri(16,(a)); \
b0 = sex16((b)); \
b1 = asri(16,(b)); \
(res)= pack16lsb( \
sround(ifir16((a),funshift2((b),(b)))), \
sround(a0*b0-a1*b1)); \
} \
#define TM_ADD(res,a,b) \
{ (res)=dspidualadd((a),(b)); \
} \
#define TM_SUB(res,a,b) \
{ (res)=dspidualsub((a),(b)); \
} \
#define TM_SHR(res,a,shift) \
{ (res)=dualasr((a),(shift)); \
} \
#define TM_DIV(res,c,frac) \
{ register int c1, c0; \
\
c1 = asri(16,(c)); \
c0 = sex16((c)); \
(res) = pack16lsb(sround(c1 * (32767/(frac))), sround(c0 * (32767/(frac))));\
} \
#define TM_NEGMSB(res, a) \
{ (res) = pack16lsb((ineg(asri(16,(a)))), (a)); \
} \
#else
#undef MIN
#undef MAX
#define MIN(a,b) fmin(a,b)
#define MAX(a,b) fmax(a,b)
#endif
#endif
#undef CHECKBUF
#define CHECKBUF(buf,nbuf,n) \
{ \
if ( nbuf < (size_t)(n) ) { \
speex_free(buf); \
buf = (kiss_fft_cpx*)KISS_FFT_MALLOC(sizeof(kiss_fft_cpx)*(n)); \
nbuf = (size_t)(n); \
} \
} \
#undef C_ADD
#define C_ADD( res, a,b) \
{ \
CHECK_OVERFLOW_OP((a).r,+,(b).r) \
CHECK_OVERFLOW_OP((a).i,+,(b).i) \
(res).r=(a).r+(b).r; (res).i=(a).i+(b).i; \
} \
#undef C_SUB
#define C_SUB( res, a,b) \
{ \
CHECK_OVERFLOW_OP((a).r,-,(b).r) \
CHECK_OVERFLOW_OP((a).i,-,(b).i) \
(res).r=(a).r-(b).r; (res).i=(a).i-(b).i; \
} \
#undef C_ADDTO
#define C_ADDTO( res , a) \
{ \
CHECK_OVERFLOW_OP((res).r,+,(a).r) \
CHECK_OVERFLOW_OP((res).i,+,(a).i) \
(res).r += (a).r; (res).i += (a).i; \
} \
#undef C_SUBFROM
#define C_SUBFROM( res, a) \
{ \
CHECK_OVERFLOW_OP((res).r,-,(a).r) \
CHECK_OVERFLOW_OP((res).i,-,(a).i) \
(res).r -= (a).r; (res).i -= (a).i; \
} \
#undef kf_cexp
#define kf_cexp(x,phase) \
{ (x)->r = KISS_FFT_COS(phase); \
(x)->i = KISS_FFT_SIN(phase); } \
#undef kf_cexp2
#define kf_cexp2(x,phase) \
{ (x)->r = spx_cos_norm((phase)); \
(x)->i = spx_cos_norm((phase)-32768); } \
#ifdef FIXED_POINT
#undef C_MUL
#define C_MUL(m,a,b) \
{ (m).r = sround( smul((a).r,(b).r) - smul((a).i,(b).i) ); \
(m).i = sround( smul((a).r,(b).i) + smul((a).i,(b).r) ); } \
#undef C_FIXDIV
#define C_FIXDIV(c,div) \
{ DIVSCALAR( (c).r , div); \
DIVSCALAR( (c).i , div); } \
#undef C_MULBYSCALAR
#define C_MULBYSCALAR( c, s ) \
{ (c).r = sround( smul( (c).r , s ) ) ; \
(c).i = sround( smul( (c).i , s ) ) ; } \
#else
#undef C_MUL
#define C_MUL(m,a,b) \
{ (m).r = (a).r*(b).r - (a).i*(b).i; \
(m).i = (a).r*(b).i + (a).i*(b).r; } \
#undef C_MULBYSCALAR
#define C_MULBYSCALAR( c, s ) \
{ (c).r *= (s); \
(c).i *= (s); } \
#endif
#endif
@@ -1,149 +0,0 @@
/* Copyright (C) 2007 Hong Zhiqian */
/**
@file cb_search_tm.h
@author Hong Zhiqian
@brief Various compatibility routines for Speex (TriMedia version)
*/
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``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 FOUNDATION OR
CONTRIBUTORS 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 <ops/custom_defs.h>
#include "profile_tm.h"
#ifdef FIXED_POINT
#define OVERRIDE_COMPUTE_WEIGHTED_CODEBOOK
static void compute_weighted_codebook(
const signed char * restrict shape_cb,
const Int16 * restrict r,
Int16 * restrict resp,
Int16 * restrict resp2,
Int32 * restrict E,
int shape_cb_size, int subvect_size, char *stack)
{
register int i, j;
register int quadsize;
TMDEBUG_ALIGNMEM(r);
TMDEBUG_ALIGNMEM(resp);
TMDEBUG_ALIGNMEM(resp2);
COMPUTEWEIGHTEDCODEBOOK_START();
quadsize = subvect_size << 2;
for ( i=0 ; i<shape_cb_size ; i+=4 )
{ register int e0, e1, e2, e3;
e0 = e1 = e2 = e3 = 0;
for( j=0 ; j<subvect_size ; ++j )
{
register int k, rr;
register int resj0, resj1, resj2, resj3;
resj0 = resj1 = resj2 = resj3 = 0;
for ( k=0 ; k<=j ; ++k )
{ rr = r[j-k];
resj0 += shape_cb[k] * rr;
resj1 += shape_cb[k+subvect_size] * rr;
resj2 += shape_cb[k+2*subvect_size] * rr;
resj3 += shape_cb[k+3*subvect_size] * rr;
}
resj0 >>= 13;
resj1 >>= 13;
resj2 >>= 13;
resj3 >>= 13;
e0 += resj0 * resj0;
e1 += resj1 * resj1;
e2 += resj2 * resj2;
e3 += resj3 * resj3;
resp[j] = resj0;
resp[j+subvect_size] = resj1;
resp[j+2*subvect_size] = resj2;
resp[j+3*subvect_size] = resj3;
}
E[i] = e0;
E[i+1] = e1;
E[i+2] = e2;
E[i+3] = e3;
resp += quadsize;
shape_cb += quadsize;
}
#ifndef REMARK_ON
(void)resp2;
(void)stack;
#endif
COMPUTEWEIGHTEDCODEBOOK_STOP();
}
#define OVERRIDE_TARGET_UPDATE
static inline void target_update(Int16 * restrict t, Int16 g, Int16 * restrict r, int len)
{
register int n;
register int gr1, gr2, t1, t2, r1, r2;
register int quadsize;
TARGETUPDATE_START();
quadsize = len & 0xFFFFFFFC;
for ( n=0; n<quadsize ; n+=4 )
{ gr1 = pack16lsb(PSHR32((g * r[n]),13) , PSHR32((g * r[n+1]),13));
gr2 = pack16lsb(PSHR32((g * r[n+2]),13), PSHR32((g * r[n+3]),13));
t1 = pack16lsb(t[n], t[n+1]);
t2 = pack16lsb(t[n+2],t[n+3]);
r1 = dspidualsub(t1, gr1);
r2 = dspidualsub(t2, gr2);
t[n] = asri(16,r1);
t[n+1] = sex16(r1);
t[n+2] = asri(16,r2);
t[n+3] = sex16(r2);
}
for ( n=quadsize ; n<len ; ++n )
{ t[n] = SUB16(t[n],PSHR32(MULT16_16(g,r[n]),13));
}
TARGETUPDATE_STOP();
}
#endif
@@ -1,233 +0,0 @@
/* Copyright (C) 2007 Hong Zhiqian */
/**
@file fftwrap_tm.h
@author Hong Zhiqian
@brief Various compatibility routines for Speex (TriMedia version)
*/
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``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 FOUNDATION OR
CONTRIBUTORS 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 <ops/custom_defs.h>
#include "profile_tm.h"
#ifdef FIXED_POINT
#define OVERRIDE_MAXIMIZE_RANGE
static int maximize_range(Int16 *in, Int16 *out, int bound, int len)
{
register int max_val=0;
register int shift=0;
register int i, j;
TMDEBUG_ALIGNMEM(in);
TMDEBUG_ALIGNMEM(out);
MAXIMIZERANGE_START();
len >>= 1;
for ( i=0 ; i<len ; i+=4 )
{
register int x10, x32, x54, x76;
x10 = ld32x(in,i);
x32 = ld32x(in,i+1);
x54 = ld32x(in,i+2);
x76 = ld32x(in,i+3);
x10 = dspidualabs(x10);
x32 = dspidualabs(x32);
x54 = dspidualabs(x54);
x76 = dspidualabs(x76);
x10 = imax(sex16(x10), asri(16,x10));
x32 = imax(sex16(x32), asri(16,x32));
x54 = imax(sex16(x54), asri(16,x54));
x76 = imax(sex16(x76), asri(16,x76));
max_val = imax(max_val,x10);
max_val = imax(max_val,x32);
max_val = imax(max_val,x54);
max_val = imax(max_val,x76);
}
while ( max_val <= (bound>>1) && max_val != 0 )
{ max_val <<= 1;
shift++;
}
if ( shift != 0 )
{
for ( i=0,j=0 ; i<len ; i+=4,j+=16 )
{
register int x10, x32, x54, x76;
x10 = ld32x(in,i);
x32 = ld32x(in,i+1);
x54 = ld32x(in,i+2);
x76 = ld32x(in,i+3);
x10 = dualasl(x10, shift);
x32 = dualasl(x32, shift);
x54 = dualasl(x54, shift);
x76 = dualasl(x76, shift);
st32d(j,out,x10);
st32d(j+4,out,x32);
st32d(j+8,out,x54);
st32d(j+12,out,x76);
}
}
MAXIMIZERANGE_STOP();
return shift;
}
#define OVERRIDE_RENORM_RANGE
static void renorm_range(Int16 *in, Int16 *out, int shift, int len)
{
register int i, j, s, l;
TMDEBUG_ALIGNMEM(in);
TMDEBUG_ALIGNMEM(out);
RENORMRANGE_START();
s = (1<<((shift))>>1);
s = pack16lsb(s,s);
len >>= 1;
l = len & (int)0xFFFFFFFE;
for ( i=0,j=0 ; i<l; i+=2,j+=8 )
{
register int x10, x32;
x10 = ld32x(in,i);
x32 = ld32x(in,i+1);
x10 = dspidualadd(x10, s);
x32 = dspidualadd(x32, s);
x10 = dualasr(x10, shift);
x32 = dualasr(x32, shift);
st32d(j,out,x10);
st32d(j+4,out,x32);
}
if ( len & (int)0x01 )
{
register int x10;
x10 = ld32x(in,i);
x10 = dspidualadd(x10, s);
x10 = dualasr(x10, shift);
st32d(j,out,x10);
}
RENORMRANGE_STOP();
}
#endif
#ifdef USE_COMPACT_KISS_FFT
#ifdef FIXED_POINT
#define OVERRIDE_POWER_SPECTRUM
void power_spectrum(const spx_word16_t *X, spx_word32_t *ps, int N)
{
register int x10, x32, x54, x76, *x;
register int i;
x = (int*)(X-1);
TMDEBUG_ALIGNMEM(x);
POWERSPECTRUM_START();
x76 = 0;
ps[0] = MULT16_16(X[0],X[0]);
N >>= 1;
for( i=1 ; i<N ; i+=4 )
{
x10 = ld32x(x, i);
x32 = ld32x(x, i+1);
x54 = ld32x(x, i+2);
x76 = ld32x(x, i+3);
ps[i] = ifir16(x10,x10);
ps[i+1] = ifir16(x32,x32);
ps[i+2] = ifir16(x54,x54);
ps[i+3] = ifir16(x76,x76);
}
x76 = sex16(x76);
ps[N] = x76 * x76;
POWERSPECTRUM_STOP();
}
#else
#define OVERRIDE_POWER_SPECTRUM
void power_spectrum(const float * restrict X, float * restrict ps, int N)
{
register int i, j;
register float xx;
POWERSPECTRUM_START();
xx = X[0];
ps[0]=MULT16_16(xx,xx);
#pragma TCS_unroll=4
#pragma TCS_unrollexact=1
for (i=1,j=1;i<N-1;i+=2,j++)
{ register float xi, xii;
xi = X[i];
xii = X[i+1];
ps[j] = MULT16_16(xi,xi) + MULT16_16(xii,xii);
}
#pragma TCS_unrollexact=0
#pragma TCS_unroll=0
xx = X[i];
ps[j]=MULT16_16(xx,xx);
POWERSPECTRUM_STOP();
}
#endif
#endif
@@ -1,289 +0,0 @@
/* Copyright (C) 2007 Hong Zhiqian */
/**
@file filterbank_tm.h
@author Hong Zhiqian
@brief Various compatibility routines for Speex (TriMedia version)
*/
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``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 FOUNDATION OR
CONTRIBUTORS 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 <ops/custom_defs.h>
#include "profile_tm.h"
#ifdef FIXED_POINT
#define OVERRIDE_FILTERBANK_COMPUTE_BANK32
void filterbank_compute_bank32(FilterBank * restrict bank, spx_word32_t * restrict ps, spx_word32_t * restrict mel)
{
register int i, j, k, banks, len, zero, s;
register int * restrict left;
register int * restrict right;
register int * restrict bleft;
register int * restrict bright;
left = (int*)bank->filter_left;
right = (int*)bank->filter_right;
bleft = (int*)bank->bank_left;
bright = (int*)bank->bank_right;
TMDEBUG_ALIGNMEM(ps);
TMDEBUG_ALIGNMEM(mel);
TMDEBUG_ALIGNMEM(left);
TMDEBUG_ALIGNMEM(right);
TMDEBUG_ALIGNMEM(bleft);
TMDEBUG_ALIGNMEM(bright);
FILTERBANKCOMPUTEBANK32_START();
banks = bank->nb_banks << 2;
zero = 0;
len = bank->len;
s = (1<<((15))>>1);
#if (TM_UNROLL && TM_UNROLL_FILTERBANKCOMPUTEBANK32)
#pragma TCS_unroll=2
#pragma TCS_unrollexact=1
#endif
for ( i=0 ; i<banks ; i+=4 )
{ st32d(i, mel, zero);
}
#if (TM_UNROLL && TM_UNROLL_FILTERBANKCOMPUTEBANK32)
#pragma TCS_unrollexact=0
#pragma TCS_unroll=0
#endif
#if (TM_UNROLL && TM_UNROLL_FILTERBANKCOMPUTEBANK32)
#pragma TCS_unroll=2
#pragma TCS_unrollexact=1
#endif
for ( i=0,j=1,k=0 ; i<len ; i+=2,j+=2,++k )
{ register int ps1, ps0, _mel, ps0_msb, ps0_lsb, ps1_msb, ps1_lsb;
register int left10, right10, left1, left0, right1, right0;
register int il1, ir1, il0, ir0;
ps0 = ld32x(ps,i);
il0 = ld32x(bleft,i);
_mel = ld32x(mel,il0);
left10 = ld32x(left,k);
ir0 = ld32x(bright,i);
right10 = ld32x(right,k);
ps0_msb = ps0 >> 15;
ps0_lsb = ps0 & 0x00007fff;
left0 = sex16(left10);
right0 = sex16(right10);
_mel += left0 * ps0_msb + ((left0 * ps0_lsb + s ) >> 15);
mel[il0]= _mel;
_mel = ld32x(mel,ir0);
_mel += right0 * ps0_msb + ((right0 * ps0_lsb + s ) >> 15);
mel[ir0]= _mel;
ps1 = ld32x(ps,j);
il1 = ld32x(bleft,j);
_mel = ld32x(mel,il1);
ir1 = ld32x(bright,j);
left1 = asri(16,left10);
right1 = asri(16,right10);
ps1_msb = ps1 >> 15;
ps1_lsb = ps1 & 0x00007fff;
_mel += left1 * ps1_msb + ((left1 * ps1_lsb + s ) >> 15);
mel[il1]= _mel;
_mel = ld32x(mel,ir1);
_mel += right1 * ps1_msb + ((right1 * ps1_lsb + s ) >> 15);
mel[ir1]= _mel;
}
#if (TM_UNROLL && TM_UNROLL_FILTERBANKCOMPUTEBANK32)
#pragma TCS_unrollexact=0
#pragma TCS_unroll=0
#endif
FILTERBANKCOMPUTEBANK32_STOP();
}
#define OVERRIDE_FILTERBANK_COMPUTE_PSD16
void filterbank_compute_psd16(FilterBank * restrict bank, spx_word16_t * restrict mel, spx_word16_t * restrict ps)
{
register int i, j, k, len, s;
register int * restrict left;
register int * restrict right;
register int * restrict bleft;
register int * restrict bright;
left = (int*)bank->filter_left;
right = (int*)bank->filter_right;
bleft = (int*)bank->bank_left;
bright = (int*)bank->bank_right;
TMDEBUG_ALIGNMEM(ps);
TMDEBUG_ALIGNMEM(mel);
TMDEBUG_ALIGNMEM(left);
TMDEBUG_ALIGNMEM(right);
TMDEBUG_ALIGNMEM(bleft);
TMDEBUG_ALIGNMEM(bright);
FILTERBANKCOMPUTEPSD16_START();
len = bank->len;
s = (1<<((15))>>1);
#if (TM_UNROLL && TM_UNROLL_FILTERBANKCOMPUTEPSD16)
#pragma TCS_unroll=2
#pragma TCS_unrollexact=1
#endif
for ( i=0,j=0,k=0 ; i<len ; i+=2,j+=4,++k )
{
register int mell0, melr0, mel1, mel0, mell1, melr1;
register int il1, ir1, il0, ir0;
register int left10, right10, lr1, lr0;
register int acc0, acc1, ps10;
acc0 = acc1 = s;
il0 = ld32x(bleft, i);
ir0 = ld32x(bright,i);
mell0 = mel[il0];
melr0 = mel[ir0];
left10 = ld32x(left, k);
right10 = ld32x(right, k);
mel0 = pack16lsb(mell0, melr0);
lr0 = pack16lsb(left10, right10);
acc0 += ifir16(mel0, lr0);
acc0 >>= 15;
il1 = ld32x(bleft, i+1);
ir1 = ld32x(bright,i+1);
mell1 = mel[il1];
melr1 = mel[ir1];
mel1 = pack16lsb(mell1, melr1);
lr1 = pack16msb(left10, right10);
acc1 += ifir16(mel1, lr1);
acc1 >>= 15;
ps10 = pack16lsb(acc1, acc0);
st32d(j, ps, ps10);
}
#if (TM_UNROLL && TM_UNROLL_FILTERBANKCOMPUTEPSD16)
#pragma TCS_unrollexact=0
#pragma TCS_unroll=0
#endif
FILTERBANKCOMPUTEPSD16_STOP();
}
#else
#define OVERRIDE_FILTERBANK_COMPUTE_BANK32
void filterbank_compute_bank32(FilterBank * restrict bank, float * restrict ps, float * restrict mel)
{
register int i, banks, len;
register int * restrict bleft, * restrict bright;
register float * restrict left, * restrict right;
banks = bank->nb_banks;
len = bank->len;
bleft = bank->bank_left;
bright= bank->bank_right;
left = bank->filter_left;
right = bank->filter_right;
FILTERBANKCOMPUTEBANK32_START();
memset(mel, 0, banks * sizeof(float));
#if (TM_UNROLL && TM_UNROLL_FILTERBANKCOMPUTEBANK32)
#pragma TCS_unroll=4
#pragma TCS_unrollexact=1
#endif
for ( i=0 ; i<len ; ++i)
{
register int id1, id2;
register float psi;
id1 = bleft[i];
id2 = bright[i];
psi = ps[i];
mel[id1] += left[i] * psi;
mel[id2] += right[i] * psi;
}
#if (TM_UNROLL && TM_UNROLL_FILTERBANKCOMPUTEBANK32)
#pragma TCS_unrollexact=0
#pragma TCS_unroll=0
#endif
FILTERBANKCOMPUTEBANK32_STOP();
}
#define OVERRIDE_FILTERBANK_COMPUTE_PSD16
void filterbank_compute_psd16(FilterBank * restrict bank, float * restrict mel, float * restrict ps)
{
register int i, len;
register int * restrict bleft, * restrict bright;
register float * restrict left, * restrict right;
len = bank->len;
bleft = bank->bank_left;
bright= bank->bank_right;
left = bank->filter_left;
right = bank->filter_right;
FILTERBANKCOMPUTEPSD16_START();
#if (TM_UNROLL && TM_UNROLL_FILTERBANKCOMPUTEPSD16)
#pragma TCS_unroll=4
#pragma TCS_unrollexact=1
#endif
for ( i=0 ; i<len ; ++i )
{
register float acc;
register int id1, id2;
id1 = bleft[i];
id2 = bright[i];
acc = mel[id1] * left[i];
acc += mel[id2] * right[i];
ps[i] = acc;
}
#if (TM_UNROLL && TM_UNROLL_FILTERBANKCOMPUTEPSD16)
#pragma TCS_unrollexact=0
#pragma TCS_unroll=0
#endif
FILTERBANKCOMPUTEPSD16_STOP();
}
#endif
File diff suppressed because it is too large Load Diff
-100
View File
@@ -1,100 +0,0 @@
/* Copyright (C) 2007 Hong Zhiqian */
/**
@file fixed_tm.h
@author Hong Zhiqian
@brief Various compatibility routines for Speex (TriMedia version)
*/
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``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 FOUNDATION OR
CONTRIBUTORS 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.
*/
#ifndef FIXED_TM_H
#define FIXED_TM_H
#include <ops/custom_defs.h>
#undef SATURATE
#undef SATURATE16
#undef SATURATE32
#define SATURATE(x,a) iclipi(x,a)
#define SATURATE16(x,a) iclipi(x,a)
#define SATURATE32(x,a) iclipi(x,a)
#undef EXTEND32
#define EXTEND32(x) sex16(x)
#undef NEG16
#undef NEG32
#define NEG16(x) ineg((int)(x))
#define NEG32(x) ineg(x)
#undef ABS
#undef ABS16
#undef ABS32
#define ABS(x) iabs(x)
#define ABS32(x) iabs(x)
#define ABS16(x) iabs((int)(x))
#undef MIN16
#undef MIN32
#define MIN16(a,b) imin((int)(a),(int)(b))
#define MIN32(a,b) imin(a,b)
#undef MAX16
#undef MAX32
#define MAX16(a,b) imax((int)(a),(int)(b))
#define MAX32(a,b) imax(a,b)
#undef ADD16
#undef SUB16
#undef ADD32
#undef SUB32
#undef MULT16_16
#undef MULT16_16_16
#define ADD16(a,b) ((int)(a) + (int)(b))
#define SUB16(a,b) ((int)(a) - (int)(b))
#define ADD32(a,b) ((int)(a) + (int)(b))
#define SUB32(a,b) ((int)(a) - (int)(b))
#define MULT16_16_16(a,b) ((int)(a) * (int)(b))
#define MULT16_16(a,b) ((int)(a) * (int)(b))
#if TM_DEBUGMEM_ALIGNNMENT
#include <stdio.h>
#define TMDEBUG_ALIGNMEM(x) \
{ if( ((int)(x) & (int)(0x00000003)) != 0 ) \
{ printf("memory not align. file: %s, line: %d\n", __FILE__, __LINE__); \
} \
}
#else
#define TMDEBUG_ALIGNMEM(x)
#endif
#endif
@@ -1,599 +0,0 @@
/* Copyright (C) 2007 Hong Zhiqian */
/**
@file kiss_fft_tm.h
@author Hong Zhiqian
@brief Various compatibility routines for Speex (TriMedia version)
*/
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``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 FOUNDATION OR
CONTRIBUTORS 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 "_kiss_fft_guts_tm.h"
#ifdef TM_ASM
#include "profile_tm.h"
#ifdef FIXED_POINT
#define OVERRIDE_KFBFLY2
static void kf_bfly2(
kiss_fft_cpx *Fout,
const int fstride,
const kiss_fft_cfg st,
int m
)
{
register int * restrict Fout2;
register int * restrict tw1 = (int*)st->twiddles;
register int i, j;
register int _inv = !st->inverse;
Fout2 = (int*)Fout + m;
for ( i=0,j=0 ; i<m ; ++i,j+=4,tw1+=fstride )
{ register int tw_10, ff_10, f2_10;
ff_10 = ld32x(Fout, i);
f2_10 = ld32x(Fout2, i);
tw_10 = ld32(tw1);
if ( _inv )
{ TM_SHR(f2_10, f2_10, 1);
TM_SHR(ff_10, ff_10, 1);
}
TM_MUL(tw_10, tw_10, f2_10);
TM_SUB(f2_10, ff_10, tw_10);
TM_ADD(ff_10, ff_10, tw_10);
st32d(j, Fout2, f2_10);
st32d(j, Fout, ff_10);
}
}
#define OVERRIDE_KFBFLY4
static void kf_bfly4(
kiss_fft_cpx *Fout,
const int fstride,
const kiss_fft_cfg st,
const int m
)
{
register int * restrict tw1;
register int * restrict tw2;
register int * restrict tw3;
register int * restrict Fout1;
register int * restrict Fout2;
register int * restrict Fout3;
register int i, j;
register int fstride2, fstride3;
register int _inv = !st->inverse;
tw3 = tw2 = tw1 = (int*)st->twiddles;
fstride2 = fstride << 1;
fstride3 = fstride * 3;
Fout1 = (int*)Fout + m;
Fout2 = (int*)Fout + (m << 1);
Fout3 = (int*)Fout + (m * 3);
for ( i=0,j=0 ; i<m ; ++i,j+=4,tw1+=fstride,tw2+=fstride2,tw3+=fstride3 )
{ register int sc0, sc1, sc2, sc3, sc4, sc5;
register int ff0;
sc0 = ld32x(Fout1,i);
sc3 = ld32(tw1);
sc1 = ld32x(Fout2, i);
sc4 = ld32(tw2);
sc2 = ld32x(Fout3, i);
sc5 = ld32(tw3);
ff0 = ld32x(Fout,i);
if ( _inv )
{
TM_ADD(sc0, sc0, 0x00020002);
TM_ADD(sc1, sc1, 0x00020002);
TM_ADD(sc2, sc2, 0x00020002);
TM_ADD(ff0, ff0, 0x00020002);
TM_SHR(sc0, sc0, 2);
TM_SHR(sc1, sc1, 2);
TM_SHR(sc2, sc2, 2);
TM_SHR(ff0, ff0, 2);
}
TM_MUL(sc0, sc0, sc3);
TM_MUL(sc1, sc1, sc4);
TM_MUL(sc2, sc2, sc5);
TM_SUB(sc5, ff0, sc1);
TM_ADD(ff0, ff0, sc1);
TM_ADD(sc3, sc0, sc2);
TM_SUB(sc4, sc0, sc2);
TM_SUB(sc1, ff0, sc3);
TM_ADD(ff0, ff0, sc3);
st32d(j, Fout2, sc1);
st32d(j, Fout, ff0);
sc5 = funshift2(sc5, sc5);
if ( _inv )
{ TM_ADD(ff0, sc5, sc4);
TM_SUB(sc1, sc5, sc4);
} else
{ TM_ADD(sc1, sc5, sc4);
TM_SUB(ff0, sc5, sc4);
}
sc0 = funshift2(sc1, ff0);
sc2 = funshift2(ff0, sc1);
st32d(j, Fout1, sc0);
st32d(j, Fout3, sc2);
}
}
#define OVERRIDE_KFBFLY3
static void kf_bfly3(
kiss_fft_cpx *Fout,
const int fstride,
const kiss_fft_cfg st,
int m
)
{
register int * restrict tw1;
register int * restrict tw2;
register int * restrict Fout1;
register int * restrict Fout2;
register int epi;
register int i, j;
register int fstride2;
register int _inv = !st->inverse;
tw1 = tw2 = (int*)st->twiddles;
Fout1 = (int*)Fout + m;
Fout2 = (int*)Fout + (m << 1);
epi = tw1[fstride*m];
epi = pack16lsb(epi,epi);
fstride2 = fstride << 1;
for ( i=0,j=0 ; i<m ; ++i,j+=4,tw1+=fstride,tw2+=fstride2 )
{ register int sc0, sc1, sc2, sc3, sc4, sc5;
register int ff0;
sc1 = ld32x(Fout1,i);
sc2 = ld32x(Fout2,i);
sc3 = ld32(tw1);
sc4 = ld32(tw2);
ff0 = ld32x(Fout,i);
if ( _inv )
{
TM_DIV(sc1, sc1, 3);
TM_DIV(sc2, sc2, 3);
TM_DIV(ff0, ff0, 3);
}
TM_MUL(sc1, sc1, sc3);
TM_MUL(sc2, sc2, sc4);
TM_ADD(sc3, sc1, sc2);
TM_SUB(sc0, sc1, sc2);
TM_SHR(sc4, sc3, 1);
TM_SUB(sc1, ff0, sc4);
sc0 = dspidualmul(sc0, epi);
sc0 = funshift2(sc0, sc0);
TM_ADD(ff0, ff0, sc3);
TM_ADD(sc4, sc1, sc0);
TM_SUB(sc5, sc1, sc0);
sc1 = funshift2(sc4, sc5);
sc2 = funshift2(sc5, sc4);
sc2 = funshift2(sc2, sc2);
st32d(j, Fout1, sc1);
st32d(j, Fout, ff0);
st32d(j, Fout2, sc2);
}
}
#define OVERRIDE_KFBFLY5
static void kf_bfly5(
kiss_fft_cpx *Fout,
const int fstride,
const kiss_fft_cfg st,
int m
)
{
register int * restrict tw1;
register int * restrict tw2;
register int * restrict tw3;
register int * restrict tw4;
register int * restrict Fout1;
register int * restrict Fout2;
register int * restrict Fout3;
register int * restrict Fout4;
register int fstride2, fstride3, fstride4;
register int i, j;
register int yab_msb, yab_lsb, yba_msb, yba_lsb;
register int _inv = !st->inverse;
Fout1=(int*)Fout+m;
Fout2=(int*)Fout+(m<<1);
Fout3=(int*)Fout+(3 *m);
Fout4=(int*)Fout+(m<<2);
tw1 = tw2 = tw3 = tw4 = (int*)st->twiddles;
i = tw1[fstride*m];
yab_lsb = tw1[fstride*(m<<1)];
yab_msb = pack16msb(i, yab_lsb);
yab_lsb = pack16lsb(i, yab_lsb);
yba_msb = funshift2(-sex16(yab_msb), yab_msb);
yba_lsb = funshift2(yab_lsb, yab_lsb);
fstride2 = fstride << 1;
fstride3 = fstride * 3;
fstride4 = fstride << 2;
for ( i=0,j=0 ; i<m ; ++i,j+=4,tw1+=fstride,tw2+=fstride2,tw3+=fstride3,tw4+=fstride4 )
{ register int sc0, sc1, sc2, sc3, sc4, sc5, sc6;
register int sc7, sc8, sc9, sc10, sc11, sc12;
register int ff0, sc78_msb, sc78_lsb, sc90_msb, sc90_lsb;
sc0 = ld32x(Fout,i);
sc1 = ld32x(Fout1,i);
sc2 = ld32x(Fout2,i);
sc3 = ld32x(Fout3,i);
sc4 = ld32x(Fout4,i);
sc5 = ld32(tw1);
sc6 = ld32(tw2);
sc7 = ld32(tw3);
sc8 = ld32(tw4);
if ( _inv )
{
TM_DIV(sc0, sc0, 5);
TM_DIV(sc1, sc1, 5);
TM_DIV(sc2, sc2, 5);
TM_DIV(sc3, sc3, 5);
TM_DIV(sc4, sc4, 5);
}
ff0 = sc0;
TM_MUL(sc1, sc1, sc5);
TM_MUL(sc2, sc2, sc6);
TM_MUL(sc3, sc3, sc7);
TM_MUL(sc4, sc4, sc8);
TM_ADD(sc7, sc1, sc4);
TM_SUB(sc10,sc1, sc4);
TM_ADD(sc8, sc2, sc3);
TM_SUB(sc9, sc2, sc3);
TM_ADD(ff0, ff0, sc7);
TM_ADD(ff0, ff0, sc8);
st32d(j, Fout, ff0);
sc78_msb = pack16msb(sc7,sc8);
sc78_lsb = pack16lsb(sc7,sc8);
sc90_msb = pack16msb(sc10,sc9);
sc90_lsb = pack16lsb(sc10,sc9);
sc5 = pack16lsb( sround(ifir16(sc78_msb,yab_lsb)), sround(ifir16(sc78_lsb,yab_lsb)));
sc6 = pack16lsb(-sround(ifir16(sc90_lsb,yab_msb)), sround(ifir16(sc90_msb,yab_msb)));
TM_ADD(sc5, sc5, sc0);
TM_SUB(sc1, sc5, sc6);
TM_ADD(sc4, sc5, sc6);
st32d(j, Fout1, sc1);
st32d(j, Fout4, sc4);
sc11 = pack16lsb( sround(ifir16(sc78_msb,yba_lsb)), sround(ifir16(sc78_lsb,yba_lsb)));
sc12 = pack16lsb(-sround(ifir16(sc90_lsb,yba_msb)), sround(ifir16(sc90_msb,yba_msb)));
TM_ADD(sc11, sc11, sc0);
TM_ADD(sc2, sc11, sc12);
TM_SUB(sc3, sc11, sc12);
st32d(j, Fout2, sc2);
st32d(j, Fout3, sc3);
}
}
#define OVERRIDE_KF_BFLY_GENERIC
static void kf_bfly_generic(
kiss_fft_cpx * restrict Fout,
const size_t fstride,
const kiss_fft_cfg st,
int m,
int p
)
{
register int _inv = !st->inverse;
register int i, j, k, l;
register int * restrict twiddles = (int*)st->twiddles;
register int Norig = st->nfft;
CHECKBUF(scratchbuf,nscratchbuf,p);
for ( i=0; i<m; ++i )
{ register int sc10;
for ( j=0,k=i ; j<p ; ++j,k+=m )
{ register int f10;
f10 = ld32x(Fout,k);
if ( _inv )
{ TM_DIV(f10, f10, p);
}
st32d(j<<2, scratchbuf, f10);
}
for ( j=0,k=i,sc10=ld32(scratchbuf) ; j<p ; ++j,k+=m )
{
register int twidx = 0;
register int f10;
for ( l=1,f10 = sc10 ; l<p ; ++l )
{ register int tw, sc;
twidx += fstride * k;
if ( twidx>=Norig )
{ twidx -= Norig;
}
sc = ld32x(scratchbuf,l);
tw = ld32x(twiddles,twidx);
TM_MUL(sc, sc, tw);
TM_ADD(f10, f10, sc);
}
st32d(k<<2, Fout, f10);
}
}
}
#else
#define OVERRIDE_KFBFLY2
static void kf_bfly2(
kiss_fft_cpx * Fout,
const size_t fstride,
const kiss_fft_cfg st,
int m
)
{
register kiss_fft_cpx * restrict Fout2;
register kiss_fft_cpx * restrict tw1 = st->twiddles;
Fout2 = Fout + m;
do
{
register kiss_fft_cpx _fout2, _fout, t;
_fout2 = *Fout2;
_fout = *Fout;
C_MUL ( t, _fout2, *tw1);
C_SUB (_fout2, _fout, t);
C_ADD (_fout, _fout, t);
*Fout2 = _fout2;
*Fout = _fout;
tw1 += fstride;
++Fout2;
++Fout;
} while ( --m );
}
#define OVERRIDE_KFBFLY4
static void kf_bfly4(
kiss_fft_cpx * Fout,
const int fstride,
const kiss_fft_cfg st,
int m
)
{
register kiss_fft_cpx * restrict tw1,* restrict tw2,* restrict tw3;
register kiss_fft_cpx * restrict Fout1, * restrict Fout2, * restrict Fout3;
register int _inv = !st->inverse;
tw3 = tw2 = tw1 = st->twiddles;
Fout1 = Fout + m;
Fout2 = Fout + (m << 1);
Fout3 = Fout + (m * 3);
do {
register kiss_fft_cpx _fout;
register kiss_fft_cpx sc0, sc1, sc2, sc3, sc4, sc5;
_fout = *Fout;
C_MUL( sc0,*Fout1, *tw1);
C_MUL( sc1,*Fout2, *tw2);
C_MUL( sc2,*Fout3, *tw3);
C_SUB( sc5, _fout, sc1);
C_ADD( _fout, _fout, sc1);
C_ADD( sc3, sc0, sc2);
C_SUB( sc4, sc0, sc2);
C_SUB(*Fout2, _fout, sc3);
C_ADD( *Fout, _fout, sc3);
tw1 += fstride;
tw2 += (fstride << 1);
tw3 += (fstride * 3);
if ( _inv )
{
Fout1->r = sc5.r + sc4.i;
Fout1->i = sc5.i - sc4.r;
Fout3->r = sc5.r - sc4.i;
Fout3->i = sc5.i + sc4.r;
}
else
{ Fout1->r = sc5.r - sc4.i;
Fout1->i = sc5.i + sc4.r;
Fout3->r = sc5.r + sc4.i;
Fout3->i = sc5.i - sc4.r;
}
++Fout; ++Fout1; ++Fout2; ++Fout3;
} while(--m);
}
#define OVERRIDE_KFBFLY3
static void kf_bfly3(
kiss_fft_cpx * Fout,
const int fstride,
const kiss_fft_cfg st,
int m
)
{
register kiss_fft_cpx * restrict Fout1, * restrict Fout2;
register kiss_fft_cpx * restrict tw1,* restrict tw2;
register float epi;
tw1 = tw2 = st->twiddles;
epi = st->twiddles[fstride*m].i;
Fout1 = Fout + m;
Fout2 = Fout + (m << 1);
do {
register kiss_fft_cpx _fout;
register kiss_fft_cpx sc0, sc1, sc2, sc3;
_fout = *Fout;
C_MUL( sc1, *Fout1, *tw1);
C_MUL( sc2, *Fout2, *tw2);
C_ADD( sc3, sc1, sc2);
C_SUB( sc0, sc1, sc2);
tw1 += fstride;
tw2 += (fstride << 1);
sc1.r = _fout.r - HALF_OF(sc3.r);
sc1.i = _fout.i - HALF_OF(sc3.i);
C_MULBYSCALAR(sc0, epi);
C_ADD(*Fout, _fout, sc3);
Fout2->r = sc1.r + sc0.i;
Fout2->i = sc1.i - sc0.r;
Fout1->r = sc1.i - sc0.i;
Fout1->i = sc1.r + sc0.r;
++Fout; ++Fout1; ++Fout2;
} while(--m);
}
#define OVERRIDE_KFBFLY5
static void kf_bfly5(
kiss_fft_cpx * Fout,
const size_t fstride,
const kiss_fft_cfg st,
int m
)
{
register kiss_fft_cpx * restrict Fout1,* restrict Fout2,* restrict Fout3,* restrict Fout4;
register int u;
register kiss_fft_cpx *tw;
register float yar, yai, ybr, ybi;
Fout1=Fout+m;
Fout2=Fout+(m<<1);
Fout3=Fout+(m*3);
Fout4=Fout+(m<<2);
tw = st->twiddles;
yar = tw[fstride*m].r;
yai = tw[fstride*m].i;
ybr = tw[fstride*2*m].r;
ybi = tw[fstride*2*m].i;
for ( u=0; u<m; ++u )
{
register kiss_fft_cpx sc0, sc1, sc2, sc3, sc4, sc5, sc6, sc7, sc8, sc9, sc10, sc11, sc12;
sc0 = *Fout;
C_MUL( sc1,*Fout1, tw[u*fstride]);
C_MUL( sc2,*Fout2, tw[2*u*fstride]);
C_MUL( sc3,*Fout3, tw[3*u*fstride]);
C_MUL( sc4,*Fout4, tw[4*u*fstride]);
C_ADD( sc7, sc1, sc4);
C_SUB( sc10, sc1, sc4);
C_ADD( sc8, sc2, sc3);
C_SUB( sc9, sc2, sc3);
Fout->r = sc0.r + sc7.r + sc8.r;
Fout->i = sc0.i + sc7.i + sc8.i;
sc5.r = sc0.r + S_MUL(sc7.r,yar) + S_MUL(sc8.r,ybr);
sc5.i = sc0.i + S_MUL(sc7.i,yar) + S_MUL(sc8.i,ybr);
sc6.r = S_MUL(sc10.i,yai) + S_MUL(sc9.i,ybi);
sc6.i = -S_MUL(sc10.r,yai) - S_MUL(sc9.r,ybi);
C_SUB(*Fout1,sc5,sc6);
C_ADD(*Fout4,sc5,sc6);
sc11.r = sc0.r + S_MUL(sc7.r,ybr) + S_MUL(sc8.r,yar);
sc11.i = sc0.i + S_MUL(sc7.i,ybr) + S_MUL(sc8.i,yar);
sc12.r = - S_MUL(sc10.i,ybi) + S_MUL(sc9.i,yai);
sc12.i = S_MUL(sc10.r,ybi) - S_MUL(sc9.r,yai);
C_ADD(*Fout2,sc11,sc12);
C_SUB(*Fout3,sc11,sc12);
++Fout1; ++Fout2; ++Fout3; ++Fout4;
}
}
#endif
#endif
@@ -1,235 +0,0 @@
/* Copyright (C) 2007 Hong Zhiqian */
/**
@file kiss_fftr_tm.h
@author Hong Zhiqian
@brief Various compatibility routines for Speex (TriMedia version)
*/
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``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 FOUNDATION OR
CONTRIBUTORS 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 "_kiss_fft_guts_tm.h"
#ifdef TM_ASM
#include "profile_tm.h"
#ifdef FIXED_POINT
#define TM_NDIV(res,c,frac) \
{ register int c1, c0; \
\
c1 = -asri(16,(c)); \
c0 = sex16((c)); \
(res) = pack16lsb(sround(c1 * (32767/(frac))), sround(c0 * (32767/(frac))));\
}
#define OVERRIDE_KISS_FFTR
void kiss_fftr(kiss_fftr_cfg st,const kiss_fft_scalar * restrict timedata, kiss_fft_cpx * restrict freqdata)
{
register int ncfft, ncfft2, k;
register int * restrict tmpbuf;
register int * restrict twiddles;
ncfft = st->substate->nfft;
ncfft2 = ncfft >> 1;
tmpbuf = (int*)st->tmpbuf;
twiddles = (int*)st->super_twiddles;
TMDEBUG_ALIGNMEM(timedata);
TMDEBUG_ALIGNMEM(freqdata);
TMDEBUG_ALIGNMEM(tmpbuf);
TMDEBUG_ALIGNMEM(twiddles);
kiss_fft(st->substate , (const kiss_fft_cpx*)timedata, st->tmpbuf);
{
register int tdcr, tdci;
tdcr = sround(st->tmpbuf[0].r * (32767/2));
tdci = sround(st->tmpbuf[0].i * (32767/2));
freqdata[0].r = tdcr + tdci;
freqdata[ncfft].r = tdcr - tdci;
freqdata[ncfft].i = freqdata[0].i = 0;
}
for ( k=1 ; k <= ncfft2 ; ++k )
{
register int fpk, fpnk, i, tw, f1k, f2k;
register int fq1, fq2;
i = ncfft-k;
fpk = ld32x(tmpbuf,k);
tw = ld32x(twiddles,k);
fpnk = ld32x(tmpbuf,i);
TM_DIV(fpk, fpk, 2);
TM_NDIV(fpnk,fpnk,2);
TM_ADD( f1k, fpk , fpnk );
TM_SUB( f2k, fpk , fpnk );
TM_MUL( tw , f2k, tw );
TM_ADD( fq1, f1k, tw );
TM_SHR( fq1, fq1, 1 );
TM_SUB( fq2, f1k, tw );
TM_NEGMSB( fq2, fq2 );
TM_SHR( fq2, fq2, 1 );
st32d( k<<2, freqdata, fq1 );
st32d( i<<2, freqdata, fq2 );
}
}
#define OVERRIDE_KISS_FFTRI
void kiss_fftri(kiss_fftr_cfg st,const kiss_fft_cpx * restrict freqdata,kiss_fft_scalar * restrict timedata)
{
register int k, ncfft, ncfft2;
register int * restrict tmpbuf;
register int * restrict twiddles;
ncfft = st->substate->nfft;
ncfft2 = ncfft >> 1;
tmpbuf = (int*)st->tmpbuf;
twiddles = (int*)st->super_twiddles;
TMDEBUG_ALIGNMEM(freqdata);
TMDEBUG_ALIGNMEM(timedata);
TMDEBUG_ALIGNMEM(tmpbuf);
TMDEBUG_ALIGNMEM(twiddles);
{
register int fqr, fqnr;
fqr = freqdata[0].r;
fqnr = freqdata[ncfft].r;
st->tmpbuf[0].r = fqr + fqnr;
st->tmpbuf[0].i = fqr - fqnr;
}
for ( k=1 ; k <= ncfft2 ; ++k )
{
register int fk, fnkc, i, tw, fek, fok, tmp;
register int tbk, tbn;
i = ncfft-k;
fk = ld32x(freqdata,k);
tw = ld32x(twiddles,k);
fnkc = pack16lsb(-freqdata[i].i, freqdata[i].r);
TM_ADD (fek, fk, fnkc);
TM_SUB (tmp, fk, fnkc);
TM_MUL (fok, tmp, tw );
TM_ADD (tbk, fek, fok);
TM_SUB (tbn, fek, fok);
TM_NEGMSB(tbn, tbn);
st32d(k<<2, tmpbuf, tbk);
st32d(i<<2, tmpbuf, tbn);
}
kiss_fft (st->substate, st->tmpbuf, (kiss_fft_cpx *) timedata);
}
#else
#define OVERRIDE_KISS_FFTR
void kiss_fftr(kiss_fftr_cfg st,const kiss_fft_scalar * restrict timedata,kiss_fft_cpx * restrict freqdata)
{
register kiss_fft_cpx fpnk, fpk, f1k, f2k, twk;
register int k, ncfft;
register kiss_fft_cpx * restrict tmpbuf, * restrict tw;
register float tdcr, tdci;
ncfft = st->substate->nfft;
tmpbuf= st->tmpbuf;
tw = st->super_twiddles;
kiss_fft( st->substate , (const kiss_fft_cpx*)timedata, tmpbuf );
tdcr = tmpbuf[0].r;
tdci = tmpbuf[0].i;
freqdata[0].r = tdcr + tdci;
freqdata[ncfft].r = tdcr - tdci;
freqdata[ncfft].i = freqdata[0].i = 0;
for ( k=1;k <= ncfft/2 ; ++k )
{
fpk = tmpbuf[k];
fpnk.r = tmpbuf[ncfft-k].r;
fpnk.i = -tmpbuf[ncfft-k].i;
C_ADD( f1k, fpk , fpnk );
C_SUB( f2k, fpk , fpnk );
C_MUL( twk, f2k , tw[k]);
freqdata[k].r = HALF_OF(f1k.r + twk.r);
freqdata[k].i = HALF_OF(f1k.i + twk.i);
freqdata[ncfft-k].r = HALF_OF(f1k.r - twk.r);
freqdata[ncfft-k].i = HALF_OF(twk.i - f1k.i);
}
}
#define OVERRIDE_KISS_FFTRI
void kiss_fftri(kiss_fftr_cfg st,const kiss_fft_cpx * restrict freqdata,kiss_fft_scalar * restrict timedata)
{
register int k, ncfft;
register kiss_fft_cpx * restrict tmpbuf, * restrict tw;
ncfft = st->substate->nfft;
tmpbuf= st->tmpbuf;
tw = st->super_twiddles;
tmpbuf[0].r = freqdata[0].r + freqdata[ncfft].r;
tmpbuf[0].i = freqdata[0].r - freqdata[ncfft].r;
for (k = 1; k <= ncfft / 2; ++k)
{
register kiss_fft_cpx fk, fnkc, fek, fok, tmp;
fk = freqdata[k];
fnkc.r = freqdata[ncfft - k].r;
fnkc.i = -freqdata[ncfft - k].i;
C_ADD (fek, fk, fnkc);
C_SUB (tmp, fk, fnkc);
C_MUL (fok,tmp,tw[k]);
C_ADD (tmpbuf[k],fek, fok);
C_SUB (tmp, fek, fok);
tmpbuf[ncfft - k].r = tmp.r;
tmpbuf[ncfft - k].i = -tmp.i;
}
kiss_fft (st->substate, st->tmpbuf, (kiss_fft_cpx *) timedata);
}
#endif
#endif
-150
View File
@@ -1,150 +0,0 @@
/* Copyright (C) 2007 Hong Zhiqian */
/**
@file lpc_tm.h
@author Hong Zhiqian
@brief Various compatibility routines for Speex (TriMedia version)
*/
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``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 FOUNDATION OR
CONTRIBUTORS 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 <ops/custom_defs.h>
#include "profile_tm.h"
#ifdef FIXED_POINT
#define OVERRIDE_SPEEX_AUTOCORR
void _spx_autocorr(const Int16 *x, Int16 *ac, int lag, int n)
{
register int i, j;
register int shift, ac_shift;
register int n_2;
register int ac0;
TMDEBUG_ALIGNMEM(x);
TMDEBUG_ALIGNMEM(ac);
_SPX_AUTOCORR_START();
n_2 = n >> 1;
ac0 = n + 1;
#if (TM_UNROLL && TM_UNROLL__SPXAUTOCORR)
#pragma TCS_unroll=5
#pragma TCS_unrollexact=1
#endif
for ( j=0 ; j<n_2 ; j+=4 )
{ register int x10, x32, x54, x76;
x10 = ld32x(x,j);
x32 = ld32x(x,j+1);
x54 = ld32x(x,j+2);
x76 = ld32x(x,j+3);
ac0 += ifir16(x10, x10) >> 8;
ac0 += ifir16(x32, x32) >> 8;
ac0 += ifir16(x54, x54) >> 8;
ac0 += ifir16(x76, x76) >> 8;
}
#if (TM_UNROLL && TM_UNROLL__SPXAUTOCORR)
#pragma TCS_unrollexact=0
#pragma TCS_unroll=0
#endif
shift = 8;
while (shift && ac0<0x40000000)
{ shift--;
ac0 <<= 1;
}
ac_shift = 18;
while (ac_shift && ac0<0x40000000)
{ ac_shift--;
ac0 <<= 1;
}
if ( shift == 0 )
{
for ( i=0 ; i<lag ; ++i )
{
register int acc0, acc1, acc2;
register int k, l, m;
register int x10, x32, y10, y32;
acc2 = acc1 = acc0 = 0;
for ( j=i ; j<16 ; ++j )
{ acc0 += (x[j] * x[j-i]);
}
for ( k=16,l=8,m=16-i ; k<n ; k+=4,l+=2,m+=4 )
{
x10 = ld32x(x,l);
y10 = pack16lsb(x[m+1],x[m]);
x32 = ld32x(x,l+1);
y32 = pack16lsb(x[m+3],x[m+2]);
acc1 += ifir16(x10,y10);
acc2 += ifir16(x32,y32);
}
ac[i] = (acc0 + acc1 + acc2) >> ac_shift;
}
} else
{
for ( i=0 ; i<lag ; ++i )
{
register int acc0, acc1, acc2;
register int k, l, m;
register int x10, x32, y10, y32;
acc2 = acc1 = acc0 = 0;
for ( j=i ; j<16 ; ++j )
{ acc0 += (x[j] * x[j-i]) >> shift;
}
for ( k=16,l=8,m=16-i ; k<n ; k+=4,l+=2,m+=4 )
{
x10 = ld32x(x,l);
y10 = pack16lsb(x[m+1],x[m]);
x32 = ld32x(x,l+1);
y32 = pack16lsb(x[m+3],x[m+2]);
acc1 += ifir16(x10,y10) >> shift;
acc2 += ifir16(x32,y32) >> shift;
}
ac[i] = (acc0 + acc1 + acc2) >> ac_shift;
}
}
_SPX_AUTOCORR_STOP();
}
#endif
-310
View File
@@ -1,310 +0,0 @@
/* Copyright (C) 2007 Hong Zhiqian */
/**
@file lsp_tm.h
@author Hong Zhiqian
@brief Various compatibility routines for Speex (TriMedia version)
*/
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``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 FOUNDATION OR
CONTRIBUTORS 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 <ops/custom_defs.h>
#include "profile_tm.h"
#ifdef FIXED_POINT
#define OVERRIDE_LSP_INTERPOLATE
void lsp_interpolate(Int16 *old_lsp, Int16 *new_lsp, Int16 *interp_lsp, int len, int subframe, int nb_subframes)
{
register int tmp = DIV32_16(SHL32(EXTEND32(1 + subframe),14),nb_subframes);
register int tmp2 = 16384-tmp;
register int in_0, in_1, factor, out_1, out_2, olsp, nlsp, ilsp;
register int i;
TMDEBUG_ALIGNMEM(old_lsp);
TMDEBUG_ALIGNMEM(new_lsp);
TMDEBUG_ALIGNMEM(interp_lsp);
LSPINTERPOLATE_START();
factor = pack16lsb(tmp,tmp2);
len >>= 1;
for ( i=0 ; i<len ; ++i )
{
olsp = ld32x(old_lsp,i); // olsp[i+1],olsp[i]
nlsp = ld32x(new_lsp,i); // nlsp[i+1],nlsp[i]
in_0 = pack16lsb(nlsp,olsp);
in_1 = pack16msb(nlsp,olsp);
out_1 = 8192 + ifir16(in_0,factor);
out_2 = 8192 + ifir16(in_1,factor);
ilsp = pack16lsb(out_2 >> 14, out_1 >> 14);
st32d(i << 2, interp_lsp, ilsp);
}
LSPINTERPOLATE_STOP();
}
#define OVERRIDE_CHEB_POLY_EVA
static inline Int32 cheb_poly_eva(Int16 *coef, Int16 x, int m, char *stack)
{
register int c10, c32, c54;
register int sum, b0, f0, f1, f2, f3;
register int xx, f32, f10;
CHEBPOLYEVA_START();
xx = sex16(x);
b0 = iclipi(xx,16383);
#if 0
c10 = ld32(coef);
c32 = ld32x(coef,1);
c54 = ld32x(coef,2);
#else
c10 = pack16lsb(coef[1],coef[0]);
c32 = pack16lsb(coef[3],coef[2]);
c54 = pack16lsb(coef[5],coef[4]);
#endif
f0 = ((xx * b0) >> 13) - 16384;
f1 = ((xx * f0) >> 13) - b0;
f2 = ((xx * f1) >> 13) - f0;
if ( m == 4 )
{ sum = sex16(c54);
f32 = pack16lsb(xx,f0);
f10 = pack16lsb(f1,f2);
} else
{ sum = asri(16,c54);
sum += ((sex16(c54) * xx) + 8192) >> 14;
f3 = ((xx * f2) >> 13) - f1;
f32 = pack16lsb(f0,f1);
f10 = pack16lsb(f2,f3);
}
sum += (ifir16(c32,f32) + 8192) >> 14;
sum += (ifir16(c10,f10) + 8192) >> 14;
#ifndef REMARK_ON
(void)stack;
#endif
CHEBPOLYEVA_STOP();
return sum;
}
#define OVERRIDE_LSP_ENFORCE_MARGIN
void lsp_enforce_margin(Int16 *lsp, int len, Int16 margin)
{
register int i;
register int m = margin;
register int m2 = 25736-margin;
register int lsp0, lsp1, lsp2;
TMDEBUG_ALIGNMEM(lsp);
LSPENFORCEMARGIN_START();
lsp0 = ld32(lsp);
lsp1 = asri(16,lsp0);
lsp0 = sex16(lsp0);
lsp2 = lsp[len-1];
if ( lsp0 < m )
{ lsp0 = m;
lsp[0] = m;
}
if ( lsp2 > m2 )
{ lsp2 = m2;
lsp[len-1] = m2;
}
for ( i=1 ; i<len-1 ; ++i )
{
lsp0 += m;
lsp2 = lsp[i+1];
m2 = lsp2 - m;
if ( lsp1 < lsp0 )
{ lsp1 = lsp0;
lsp[i] = lsp0;
}
if ( lsp1 > m2 )
{ lsp1 = (lsp1 >> 1) + (m2 >> 1);
lsp[i] = lsp1;
}
lsp0 = lsp1;
lsp1 = lsp2;
}
LSPENFORCEMARGIN_STOP();
}
#define OVERRIDE_LSP_TO_LPC
void lsp_to_lpc(Int16 *freq, Int16 *ak,int lpcrdr, char *stack)
{
VARDECL(Int16 *freqn);
VARDECL(int **xp);
VARDECL(int *xpmem);
VARDECL(int **xq);
VARDECL(int *xqmem);
register int i, j, k;
register int xout1,xout2,xin;
register int m;
LSPTOLPC_START();
m = lpcrdr>>1;
/*
Reconstruct P(z) and Q(z) by cascading second order polynomials
in form 1 - 2cos(w)z(-1) + z(-2), where w is the LSP frequency.
In the time domain this is:
y(n) = x(n) - 2cos(w)x(n-1) + x(n-2)
This is what the ALLOCS below are trying to do:
int xp[m+1][lpcrdr+1+2]; // P matrix in QIMP
int xq[m+1][lpcrdr+1+2]; // Q matrix in QIMP
These matrices store the output of each stage on each row. The
final (m-th) row has the output of the final (m-th) cascaded
2nd order filter. The first row is the impulse input to the
system (not written as it is known).
The version below takes advantage of the fact that a lot of the
outputs are zero or known, for example if we put an inpulse
into the first section the "clock" it 10 times only the first 3
outputs samples are non-zero (it's an FIR filter).
*/
ALLOC(xp, (m+1), int*);
ALLOC(xpmem, (m+1)*(lpcrdr+1+2), int);
ALLOC(xq, (m+1), int*);
ALLOC(xqmem, (m+1)*(lpcrdr+1+2), int);
for ( i=0; i<=m; i++ )
{ xp[i] = xpmem + i*(lpcrdr+1+2);
xq[i] = xqmem + i*(lpcrdr+1+2);
}
/* work out 2cos terms in Q14 */
ALLOC(freqn, lpcrdr, Int16);
for ( j=0,k=0 ; j<m ; ++j,k+=2 )
{ register int f;
f = ld32x(freq,j);
freqn[k] = ANGLE2X(sex16(f));
freqn[k+1] = ANGLE2X(asri(16,f));
}
#define QIMP 21 /* scaling for impulse */
xin = SHL32(EXTEND32(1), (QIMP-1)); /* 0.5 in QIMP format */
/* first col and last non-zero values of each row are trivial */
for(i=0;i<=m;i++)
{ xp[i][1] = 0;
xp[i][2] = xin;
xp[i][2+2*i] = xin;
xq[i][1] = 0;
xq[i][2] = xin;
xq[i][2+2*i] = xin;
}
/* 2nd row (first output row) is trivial */
xp[1][3] = -MULT16_32_Q14(freqn[0],xp[0][2]);
xq[1][3] = -MULT16_32_Q14(freqn[1],xq[0][2]);
xout1 = xout2 = 0;
for( i=1 ; i<m ; ++i)
{ register int f, f0, f1, m0, m1;
k = 2*(i+1)-1;
f = ld32x(freqn,i);
f0 = sex16(f);
f1 = asri(16,f);
for( j=1 ; j<k ; ++j)
{ register int _m0, _m1;
_m0 = MULT16_32_Q14(f0,xp[i][j+1]);
xp[i+1][j+2] = ADD32(SUB32(xp[i][j+2], _m0), xp[i][j]);
_m1 = MULT16_32_Q14(f1,xq[i][j+1]);
xq[i+1][j+2] = ADD32(SUB32(xq[i][j+2], _m1), xq[i][j]);
}
m0 = MULT16_32_Q14(f0,xp[i][j+1]);
xp[i+1][j+2] = SUB32(xp[i][j], m0);
m1 = MULT16_32_Q14(f1,xq[i][j+1]);
xq[i+1][j+2] = SUB32(xq[i][j], m1);
}
for( i=0,j=3 ; i<lpcrdr ; ++j,++i )
{ register int _a0, _xp0, _xq0;
_xp0 = xp[m][j];
_xq0 = xq[m][j];
_a0 = PSHR32(_xp0 + xout1 + _xq0 - xout2, QIMP-13);
xout1 = _xp0;
xout2 = _xq0;
ak[i] = iclipi(_a0,32767);
}
LSPTOLPC_STOP();
}
#endif
-479
View File
@@ -1,479 +0,0 @@
/* Copyright (C) 2007 Hong Zhiqian */
/**
@file ltp_tm.h
@author Hong Zhiqian
@brief Various compatibility routines for Speex (TriMedia version)
*/
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``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 FOUNDATION OR
CONTRIBUTORS 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 <ops/custom_defs.h>
#include "profile_tm.h"
#ifdef FIXED_POINT
#define OVERRIDE_INNER_PROD
Int32 inner_prod(const Int16 * restrict x, const Int16 * restrict y, int len)
{
register int sum = 0;
INNERPROD_START();
if ( (int)x & 0x03 == 0 && (int)y & 0x03 == 0 )
{
register int i;
len >>= 1;
for ( i=0 ; i<len ; i+=4 )
{
register int x0, x1, y0, y1, x2, x3, y2, y3;
x0 = ld32x(x,i);
y0 = ld32x(x,i);
x1 = ld32x(x,i+1);
y1 = ld32x(y,i+1);
sum += (ifir16(x0,y0) + ifir16(x1,y1)) >> 6;
x2 = ld32x(x,i+2);
y2 = ld32x(x,i+2);
x3 = ld32x(x,i+3);
y3 = ld32x(x,i+3);
sum += (ifir16(x2,y2) + ifir16(x3,y3)) >> 6;
}
} else
{
len >>= 3;
while( len-- )
{
register int x0, x1, x2, x3, y0, y1, y2, y3;
x0 = pack16lsb(x[0],x[1]);
y0 = pack16lsb(y[0],y[1]);
x1 = pack16lsb(x[2],x[3]);
y1 = pack16lsb(y[2],y[3]);
sum += (ifir16(x0,y0) + ifir16(x1,y1)) >> 6;
x2 = pack16lsb(x[4],x[5]);
y2 = pack16lsb(y[4],y[5]);
x3 = pack16lsb(x[6],x[7]);
y3 = pack16lsb(y[6],y[7]);
sum += (ifir16(x2,y2) + ifir16(x3,y3)) >> 6;
x += 8;
y += 8;
}
}
INNERPROD_STOP();
return sum;
}
#define OVERRIDE_PITCH_XCORR
void pitch_xcorr(const Int16 *_x, const Int16 *_y, Int32 *corr, int len, int nb_pitch, char *stack)
{
register int sum_1, sum_2, sum_3, sum_4;
register int y10, y32, y54, y76, y21, y43, y65;
register int x10, x32;
register int i, j, k, limit;
TMDEBUG_ALIGNMEM(_x);
TMDEBUG_ALIGNMEM(_y);
PITCHXCORR_START();
limit = nb_pitch >> 1;
len >>= 1;
for (i=0 ; i<limit ; i+=2 )
{
sum_1 = sum_2 = sum_3 = sum_4 = 0;
y10 = ld32x(_y,i);
y32 = ld32x(_y,i+1);
for ( j=0 ; j<len ; j+=2 )
{
x10 = ld32x(_x,j);
x32 = ld32x(_x,j+1);
y54 = ld32x(_y,i+j+2);
y76 = ld32x(_y,i+j+3);
sum_1 += (ifir16(x10,y10) + ifir16(x32,y32)) >> 6;
sum_3 += (ifir16(x10,y32) + ifir16(x32,y54)) >> 6;
y21 = funshift2(y32,y10);
y43 = funshift2(y54,y32);
y65 = funshift2(y76,y54);
sum_2 += (ifir16(x10,y21) + ifir16(x32,y43)) >> 6;
sum_4 += (ifir16(x10,y43) + ifir16(x32,y65)) >> 6;
y10 = y54;
y32 = y76;
}
k = i << 1;
corr[nb_pitch-1-k]=sum_1;
corr[nb_pitch-2-k]=sum_2;
corr[nb_pitch-3-k]=sum_3;
corr[nb_pitch-4-k]=sum_4;
}
#ifndef REMARK_ON
(void)stack;
#endif
PITCHXCORR_STOP();
}
#ifndef ttisim
#define OVERRIDE_PITCH_GAIN_SEARCH_3TAP_VQ
static int pitch_gain_search_3tap_vq
(
const signed char *gain_cdbk,
int gain_cdbk_size,
Int16 *C16,
Int16 max_gain
)
{
register int pp = 0x00400040, p=64;
register int g10, g2, g20, g21, g02, g22, g01;
register int cb0, cb1, cb2, cb5432;
register int C10, C32, C54, C76, C98, C83, C2;
register int acc0, acc1, acc2, acc3, sum, gsum, bsum=-VERY_LARGE32;
register int i, best_cdbk=0;
register Int16 tmp;
TMDEBUG_ALIGNMEM(C16);
TMDEBUG_ALIGNMEM(gain_cdbk+2);
PITCHGAINSEARCH3TAPVQ_START();
tmp = ild16(gain_cdbk);
C98 = ld32x(C16,4);
C32 = ld32x(C16,1);
C10 = ld32(C16);
C54 = ld32x(C16,2);
C76 = ld32x(C16,3);
cb0 = sex8(tmp);
cb1 = sex8(tmp>>8);
C83 = funshift2(C98,C32);
C2 = sex16(C32);
gain_cdbk += 2;
#if (TM_UNROLL && TM_UNROLL_PITCHGAINSEARCH3TAPVQ > 0)
#pragma TCS_unroll=4
#pragma TCS_unrollexact=1
#endif
for ( i=0 ; i<gain_cdbk_size ; ++i )
{
cb5432 = ld32x(gain_cdbk,i);
cb2 = sex8(cb5432);
gsum = sex8(cb5432>>8);
sum = 0;
g10 = pack16lsb(cb1 + 32, cb0 + 32);
g2 = cb2 + 32;
g02 = pack16lsb(g10, g2);
acc0 = dspidualmul(g10,pp);
sum += ifir16(acc0,C10);
sum += p * g2 * C2;
g22 = pack16lsb(g02, g02);
g01 = funshift2(g10, g10);
acc1 = dspidualmul(g22, g01);
sum -= ifir16(acc1, C54);
acc2 = dspidualmul(g10, g10);
sum -= ifir16(acc2, C76);
g20 = pack16lsb(g2, g10);
g21 = funshift2(g2, g10);
acc3 = dspidualmul(g20, g21);
sum -= ifir16(acc3, C83);
if ( sum>bsum && gsum<=max_gain )
{ bsum = sum;
best_cdbk=i;
}
cb0 = sex8(cb5432 >> 16);
cb1 = asri(24,cb5432);
}
#if (TM_UNROLL && TM_UNROLL_PITCHGAINSEARCH3TAPVQ > 0)
#pragma TCS_unrollexact=0
#pragma TCS_unroll=0
#endif
PITCHGAINSEARCH3TAPVQ_STOP();
return best_cdbk;
}
#endif
#define OVERRIDE_COMPUTE_PITCH_ERROR
#ifndef OVERRIDE_PITCH_GAIN_SEARCH_3TAP_VQ
inline Int32 compute_pitch_error(Int16 *C, Int16 *g, Int16 pitch_control)
{
register int c10, c32, c54, c76, c98, c83;
register int g10, g32, g02, g22, g01, g21, g20;
register int pp, tmp0, tmp1, tmp2, tmp3;
register int sum = 0;
COMPUTEPITCHERROR_START();
g10 = ld32(g);
g32 = ld32x(g,1);
pp = pack16lsb(pitch_control,pitch_control);
c10 = ld32(C);
c32 = ld32x(C,1);
g02 = pack16lsb(g10,g32);
g22 = pack16lsb(g32,g32);
g01 = funshift2(g10,g10);
tmp0 = dspidualmul(g10,pp);
sum += ifir16(tmp0, c10);
sum += pitch_control * sex16(g32) * sex16(c32);
c54 = ld32x(C,2);
c76 = ld32x(C,3);
c98 = ld32x(C,4);
tmp1 = dspidualmul(g22,g01);
sum -= ifir16(tmp1, c54);
tmp2 = dspidualmul(g10,g10);
sum -= ifir16(tmp2,c76);
c83 = funshift2(c98,c32);
g20 = funshift2(g02,g02);
g21 = funshift2(g02,g10);
tmp3 = dspidualmul(g20,g21);
sum -= ifir16(tmp3,c83);
COMPUTEPITCHERROR_STOP();
return sum;
}
#endif
#define OVERRIDE_OPEN_LOOP_NBEST_PITCH
void open_loop_nbest_pitch(Int16 *sw, int start, int end, int len, int *pitch, Int16 *gain, int N, char *stack)
{
VARDECL(int *best_score);
VARDECL(int *best_ener);
VARDECL(Int32 *corr);
VARDECL(Int16 *corr16);
VARDECL(Int16 *ener16);
register int i, j, k, l, N4, N2;
register int _sw10, _sw32, _s0, _s2, limit;
register int *energy;
register int cshift=0, eshift=0;
register int scaledown = 0;
register int e0, _energy0;
ALLOC(corr16, end-start+1, Int16);
ALLOC(ener16, end-start+1, Int16);
ALLOC(corr, end-start+1, Int32);
ALLOC(best_score, N, int);
ALLOC(best_ener, N, int);
energy = corr;
N4 = N << 2;
N2 = N >> 1;
TMDEBUG_ALIGNMEM(sw);
TMDEBUG_ALIGNMEM(pitch);
TMDEBUG_ALIGNMEM(gain);
TMDEBUG_ALIGNMEM(best_score);
TMDEBUG_ALIGNMEM(best_ener);
TMDEBUG_ALIGNMEM(corr16);
TMDEBUG_ALIGNMEM(ener16);
OPENLOOPNBESTPITCH_START();
for ( i=0 ; i<N4 ; i+=4 )
{ st32d(i,best_score,-1);
st32d(i,best_ener,0);
st32d(i,pitch,start);
}
for ( j=asri(1,-end) ; j<N2 ; ++j )
{ register int _sw10;
_sw10 = ld32x(sw,j);
_sw10 = dspidualabs(_sw10);
if ( _sw10 & 0xC000C000 )
{ scaledown = 1;
break;
}
}
if ( scaledown )
{
for ( j=asri(1,-end),k=asli(1,-end) ; j<N2 ; ++j,k+=4 )
{ register int _sw10;
_sw10 = ld32x(sw,j);
_sw10 = dualasr(_sw10,1);
st32d(k, sw, _sw10);
}
}
energy[0] = _energy0 = inner_prod(sw-start, sw-start, len);
e0 = inner_prod(sw, sw, len);
j=asri(1,-start-1); k=j+20;
_sw10 = ld32x(sw,j);
_sw32 = ld32x(sw,k);
limit = end-1-start;
for ( i=1,--j,--k ; i<limit ; i+=2,--j,--k )
{ register int _energy1, __sw10, __sw32, __s0, __s2;
_s0 = sex16(_sw10);
_s2 = sex16(_sw32);
_energy1 = (_energy0 + ((_s0 * _s0) >> 6)) - ((_s2 * _s2) >> 6);
_energy0 = imax(0,_energy1);
energy[i] = _energy0;
__sw10 = ld32x(sw,j);
__sw32 = ld32x(sw,k);
__s0 = asri(16,__sw10);
__s2 = asri(16,__sw32);
_energy1 = (_energy0 + ((__s0 * __s0) >> 6)) - ((__s2 * __s2) >> 6);
_energy0 = imax(0,_energy1);
energy[i+1] = _energy0;
_sw10 = __sw10;
_sw32 = __sw32;
}
_s0 = sex16(_sw10);
_s2 = sex16(_sw32);
_energy0 = imax(0,(_energy0 + ((_s0 * _s0) >> 6)) - ((_s2 * _s2) >> 6));
energy[i] = _energy0;
eshift = normalize16(energy, ener16, 32766, end-start+1);
/* In fixed-point, this actually overrites the energy array (aliased to corr) */
pitch_xcorr(sw, sw-end, corr, len, end-start+1, stack);
/* Normalize to 180 so we can square it and it still fits in 16 bits */
cshift = normalize16(corr, corr16, 180, end-start+1);
/* If we scaled weighted input down, we need to scale it up again (OK, so we've just lost the LSB, who cares?) */
if ( scaledown )
{
for ( j=asri(1,-end),k=asli(1,-end) ; j<N2 ; ++j,k+=4 )
{ register int _sw10;
_sw10 = ld32x(sw,j);
_sw10 = dualasl(_sw10,1);
st32d(k, sw, _sw10);
}
}
/* Search for the best pitch prediction gain */
for ( i=start,l=0 ; i<end ; i+=2,++l )
{ register int _corr16, _c0, _c1;
register int _ener16, _e0, _e1;
_corr16 = ld32x(corr16,l);
_corr16 = dspidualmul(_corr16,_corr16);
_c0 = sex16(_corr16);
_c1 = asri(16,_corr16);
_ener16 = ld32x(ener16,l);
_ener16 = dspidualadd(_ener16,0x00010001);
_e0 = sex16(_ener16);
_e1 = asri(16,_ener16);
/* Instead of dividing the tmp by the energy, we multiply on the other side */
if ( (_c0 * best_ener[N-1]) > (best_score[N-1] * _e0) )
{
best_score[N-1] = _c0;
best_ener[N-1] = _e0;
pitch[N-1] = i;
for( j=0 ; j<N-1 ; ++j )
{ if ( (_c0 * best_ener[j]) > best_score[j] * _e0 )
{ for( k=N-1 ; k>j ; --k )
{
best_score[k]=best_score[k-1];
best_ener[k]=best_ener[k-1];
pitch[k]=pitch[k-1];
}
best_score[j]=_c0;
best_ener[j]=_e0;
pitch[j]=i;
break;
}
}
}
if ( (_c1 * best_ener[N-1]) > (best_score[N-1] * _e1) )
{
best_score[N-1] = _c1;
best_ener[N-1] = _e1;
pitch[N-1] = i+1;
for( j=0 ; j<N-1 ; ++j )
{ if ( (_c1 * best_ener[j]) > best_score[j] * _e1 )
{ for( k=N-1 ; k>j ; --k )
{
best_score[k]=best_score[k-1];
best_ener[k]=best_ener[k-1];
pitch[k]=pitch[k-1];
}
best_score[j]=_c1;
best_ener[j]=_e1;
pitch[j]=i+1;
break;
}
}
}
}
/* Compute open-loop gain if necessary */
if (gain)
{
for (j=0;j<N;j++)
{
spx_word16_t g;
i=pitch[j];
g = DIV32(SHL32(EXTEND32(corr16[i-start]),cshift), 10+SHR32(MULT16_16(spx_sqrt(e0),spx_sqrt(SHL32(EXTEND32(ener16[i-start]),eshift))),6));
gain[j] = imax(0,g);
}
}
OPENLOOPNBESTPITCH_STOP();
}
#endif
@@ -1,92 +0,0 @@
/* Copyright (C) 2007 Hong Zhiqian */
/**
@file misc_tm.h
@author Hong Zhiqian
@brief Various compatibility routines for Speex (TriMedia version)
*/
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``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 FOUNDATION OR
CONTRIBUTORS 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 <tmml.h>
#if TM_PROFILE
int __profile_begin;
int __profile_end;
#endif
#define OVERRIDE_SPEEX_ALLOC
void *speex_alloc (int size)
{
void *ptr;
if ( tmmlMalloc(0, size, (pVoid*)&ptr, tmmlMallocCacheAligned | tmmlMallocCleared) != TM_OK )
{ return NULL;
}
return ptr;
}
#define OVERRIDE_SPEEX_ALLOC_SCRATCH
void *speex_alloc_scratch (int size)
{
void *ptr;
if ( tmmlMalloc(0, size, (pVoid*)&ptr, tmmlMallocCacheAligned | tmmlMallocCleared) != TM_OK )
{ return NULL;
}
return ptr;
}
#define OVERRIDE_SPEEX_REALLOC
void *speex_realloc (void *ptr, int size)
{
if ( tmmlRealloc(0, size, (pVoid)ptr, (pVoid*)&ptr, tmmlMallocCacheAligned | tmmlMallocCleared) != TM_OK )
{ return NULL;
}
return ptr;
}
#define OVERRIDE_SPEEX_FREE
void speex_free (void *ptr)
{
tmmlFree(ptr);
}
#define OVERRIDE_SPEEX_FREE_SCRATCH
void speex_free_scratch (void *ptr)
{
tmmlFree(ptr);
}
@@ -1,407 +0,0 @@
/* Copyright (C) 2007 Hong Zhiqian */
/**
@file profile_tm.h
@author Hong Zhiqian
@brief Various compatibility routines for Speex (TriMedia version)
*/
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``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 FOUNDATION OR
CONTRIBUTORS 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.
*/
/**
* @remarks This file provide some capabilities to measure clock cycles.
* Use this if unable to compile with TriMedia profile options
*/
extern int __profile_begin;
extern int __profile_end;
#if TM_PROFILE
#define PROFILE_START() \
{ \
__profile_begin = cycles(); \
} \
#define PROFILE_STOP() \
{ \
__profile_end = cycles(); \
printf("%s\t%d\n", __FUNCTION__, end - begin); \
} \
#else
#define PROFILE_START()
#define PROFILE_STOP()
#endif
#if TM_PROFILE_SPXAUTOCORR
#define _SPX_AUTOCORR_START() PROFILE_START()
#define _SPX_AUTOCORR_STOP() PROFILE_STOP()
#else
#define _SPX_AUTOCORR_START()
#define _SPX_AUTOCORR_STOP()
#endif
#if TM_PROFILE_INNERPROD
#define INNERPROD_START() PROFILE_START()
#define INNERPROD_STOP() PROFILE_STOP()
#else
#define INNERPROD_START()
#define INNERPROD_STOP()
#endif
#if TM_PROFILE_PITCHXCORR
#define PITCHXCORR_START() PROFILE_START()
#define PITCHXCORR_STOP() PROFILE_STOP()
#else
#define PITCHXCORR_START()
#define PITCHXCORR_STOP()
#endif
#if TM_PROFILE_COMPUTEPITCHERROR
#define COMPUTEPITCHERROR_START() PROFILE_START()
#define COMPUTEPITCHERROR_STOP() PROFILE_STOP()
#else
#define COMPUTEPITCHERROR_START()
#define COMPUTEPITCHERROR_STOP()
#endif
#if TM_PROFILE_PITCHGAINSEARCH3TAPVQ
#define PITCHGAINSEARCH3TAPVQ_START() PROFILE_START()
#define PITCHGAINSEARCH3TAPVQ_STOP() PROFILE_STOP()
#else
#define PITCHGAINSEARCH3TAPVQ_START()
#define PITCHGAINSEARCH3TAPVQ_STOP()
#endif
#if TM_PROFILE_OPENLOOPNBESTPITCH
#define OPENLOOPNBESTPITCH_START() PROFILE_START()
#define OPENLOOPNBESTPITCH_STOP() PROFILE_STOP()
#else
#define OPENLOOPNBESTPITCH_START()
#define OPENLOOPNBESTPITCH_STOP()
#endif
#if TM_PROFILE_LSP_INTERPOLATE
#define LSPINTERPOLATE_START() PROFILE_START()
#define LSPINTERPOLATE_STOP() PROFILE_STOP()
#else
#define LSPINTERPOLATE_START()
#define LSPINTERPOLATE_STOP()
#endif
#if TM_PROFILE_CHEBPOLYEVA
#define CHEBPOLYEVA_START() PROFILE_START()
#define CHEBPOLYEVA_STOP() PROFILE_STOP()
#else
#define CHEBPOLYEVA_START()
#define CHEBPOLYEVA_STOP()
#endif
#if TM_PROFILE_COMPUTEQUANTWEIGHTS
#define COMPUTEQUANTWEIGHTS_START() PROFILE_START()
#define COMPUTEQUANTWEIGHTS_STOP() PROFILE_STOP()
#else
#define COMPUTEQUANTWEIGHTS_START()
#define COMPUTEQUANTWEIGHTS_STOP()
#endif
#if TM_PROFILE_LSPQUANT
#define LSPQUANT_START() PROFILE_START()
#define LSPQUANT_STOP() PROFILE_STOP()
#else
#define LSPQUANT_START()
#define LSPQUANT_STOP()
#endif
#if TM_PROFILE_LSPWEIGHTQUANT
#define LSPWEIGHTQUANT_START() PROFILE_START()
#define LSPWEIGHTQUANT_STOP() PROFILE_STOP()
#else
#define LSPWEIGHTQUANT_START()
#define LSPWEIGHTQUANT_STOP()
#endif
#if TM_PROFILE_FIRMEM16
#define FIRMEM16_START() PROFILE_START()
#define FIRMEM16_STOP() PROFILE_STOP()
#else
#define FIRMEM16_START()
#define FIRMEM16_STOP()
#endif
#if TM_PROFILE_IIRMEM16
#define IIRMEM16_START() PROFILE_START()
#define IIRMEM16_STOP() PROFILE_STOP()
#else
#define IIRMEM16_START()
#define IIRMEM16_STOP()
#endif
#if TM_PROFILE_FILTERMEM16
#define FILTERMEM16_START() PROFILE_START()
#define FILTERMEM16_STOP() PROFILE_STOP()
#else
#define FILTERMEM16_START()
#define FILTERMEM16_STOP()
#endif
#if TM_PROFILE_COMPUTERMS16
#define COMPUTERMS16_START() PROFILE_START()
#define COMPUTERMS16_STOP() PROFILE_STOP()
#else
#define COMPUTERMS16_START()
#define COMPUTERMS16_STOP()
#endif
#if TM_PROFILE_NORMALIZE16
#define NORMALIZE16_START() PROFILE_START()
#define NORMALIZE16_STOP() PROFILE_STOP()
#else
#define NORMALIZE16_START()
#define NORMALIZE16_STOP()
#endif
#if TM_PROFILE_BWLPC
#define BWLPC_START() PROFILE_START()
#define BWLPC_STOP() PROFILE_STOP()
#else
#define BWLPC_START()
#define BWLPC_STOP()
#endif
#if TM_PROFILE_HIGHPASS
#define HIGHPASS_START() PROFILE_START()
#define HIGHPASS_STOP() PROFILE_STOP()
#else
#define HIGHPASS_START()
#define HIGHPASS_STOP()
#endif
#if TM_PROFILE_SIGNALMUL
#define SIGNALMUL_START() PROFILE_START()
#define SIGNALMUL_STOP() PROFILE_STOP()
#else
#define SIGNALMUL_START()
#define SIGNALMUL_STOP()
#endif
#if TM_PROFILE_SIGNALDIV
#define SIGNALDIV_START() PROFILE_START()
#define SIGNALDIV_STOP() PROFILE_STOP()
#else
#define SIGNALDIV_START()
#define SIGNALDIV_STOP()
#endif
#if TM_PROFILE_COMPUTEIMPULSERESPONSE
#define COMPUTEIMPULSERESPONSE_START() PROFILE_START()
#define COMPUTEIMPULSERESPONSE_STOP() PROFILE_STOP()
#else
#define COMPUTEIMPULSERESPONSE_START()
#define COMPUTEIMPULSERESPONSE_STOP()
#endif
#if TM_PROFILE_COMPUTEWEIGHTEDCODEBOOK
#define COMPUTEWEIGHTEDCODEBOOK_START() PROFILE_START()
#define COMPUTEWEIGHTEDCODEBOOK_STOP() PROFILE_STOP()
#else
#define COMPUTEWEIGHTEDCODEBOOK_START()
#define COMPUTEWEIGHTEDCODEBOOK_STOP()
#endif
#if TM_PROFILE_TARGETUPDATE
#define TARGETUPDATE_START() PROFILE_START()
#define TARGETUPDATE_STOP() PROFILE_STOP()
#else
#define TARGETUPDATE_START()
#define TARGETUPDATE_STOP()
#endif
#if TM_PROFILE_VQNBEST
#define VQNBEST_START() PROFILE_START()
#define VQNBEST_STOP() PROFILE_STOP()
#else
#define VQNBEST_START()
#define VQNBEST_STOP()
#endif
#if TM_PROFILE_VQNBESTSIGN
#define VQNBESTSIGN_START() PROFILE_START()
#define VQNBESTSIGN_STOP() PROFILE_STOP()
#else
#define VQNBESTSIGN_START()
#define VQNBESTSIGN_STOP()
#endif
#if TM_PROFILE_PREPROCESSANALYSIS
#define PREPROCESSANAYLSIS_START() PROFILE_START()
#define PREPROCESSANAYLSIS_STOP() PROFILE_STOP()
#else
#define PREPROCESSANAYLSIS_START()
#define PREPROCESSANAYLSIS_STOP()
#endif
#if TM_PROFILE_UPDATENOISEPROB
#define UPDATENOISEPROB_START() PROFILE_START()
#define UPDATENOISEPROB_STOP() PROFILE_STOP()
#else
#define UPDATENOISEPROB_START()
#define UPDATENOISEPROB_STOP()
#endif
#if TM_PROFILE_COMPUTEGAINFLOOR
#define COMPUTEGAINFLOOR_START() PROFILE_START()
#define COMPUTEGAINFLOOR_STOP() PROFILE_STOP()
#else
#define COMPUTEGAINFLOOR_START()
#define COMPUTEGAINFLOOR_STOP()
#endif
#if TM_PROFILE_FILTERDCNOTCH16
#define FILTERDCNOTCH16_START() PROFILE_START()
#define FILTERDCNOTCH16_STOP() PROFILE_STOP()
#else
#define FILTERDCNOTCH16_START()
#define FILTERDCNOTCH16_STOP()
#endif
#if TM_PROFILE_MDFINNERPROD
#define MDFINNERPROD_START() PROFILE_START()
#define MDFINNERPROD_STOP() PROFILE_STOP()
#else
#define MDFINNERPROD_START()
#define MDFINNERPROD_STOP()
#endif
#if TM_PROFILE_SPECTRALMULACCUM
#define SPECTRALMULACCUM_START() PROFILE_START()
#define SPECTRALMULACCUM_STOP() PROFILE_STOP()
#else
#define SPECTRALMULACCUM_START()
#define SPECTRALMULACCUM_STOP()
#endif
#if TM_PROFILE_WEIGHTEDSPECTRALMULCONJ
#define WEIGHTEDSPECTRALMULCONJ_START() PROFILE_START()
#define WEIGHTEDSPECTRALMULCONJ_STOP() PROFILE_STOP()
#else
#define WEIGHTEDSPECTRALMULCONJ_START()
#define WEIGHTEDSPECTRALMULCONJ_STOP()
#endif
#if TM_PROFILE_MDFADJUSTPROP
#define MDFADJUSTPROP_START() PROFILE_START()
#define MDFADJUSTPROP_STOP() PROFILE_STOP()
#else
#define MDFADJUSTPROP_START()
#define MDFADJUSTPROP_STOP()
#endif
#if TM_PROFILE_SPEEXECHOGETRESIDUAL
#define SPEEXECHOGETRESIDUAL_START() PROFILE_START()
#define SPEEXECHOGETRESIDUAL_STOP() PROFILE_STOP()
#else
#define SPEEXECHOGETRESIDUAL_START()
#define SPEEXECHOGETRESIDUAL_STOP()
#endif
#if TM_PROFILE_LSPENFORCEMARGIN
#define LSPENFORCEMARGIN_START() PROFILE_START()
#define LSPENFORCEMARGIN_STOP() PROFILE_STOP()
#else
#define LSPENFORCEMARGIN_START()
#define LSPENFORCEMARGIN_STOP()
#endif
#if TM_PROFILE_LSPTOLPC
#define LSPTOLPC_START() PROFILE_START()
#define LSPTOLPC_STOP() PROFILE_STOP()
#else
#define LSPTOLPC_START()
#define LSPTOLPC_STOP()
#endif
#if TM_PROFILE_MAXIMIZERANGE
#define MAXIMIZERANGE_START() PROFILE_START()
#define MAXIMIZERANGE_STOP() PROFILE_STOP()
#else
#define MAXIMIZERANGE_START()
#define MAXIMIZERANGE_STOP()
#endif
#if TM_PROFILE_RENORMRANGE
#define RENORMRANGE_START() PROFILE_START()
#define RENORMRANGE_STOP() PROFILE_STOP()
#else
#define RENORMRANGE_START()
#define RENORMRANGE_STOP()
#endif
#if TM_PROFILE_POWERSPECTRUM
#define POWERSPECTRUM_START() PROFILE_START()
#define POWERSPECTRUM_STOP() PROFILE_STOP()
#else
#define POWERSPECTRUM_START()
#define POWERSPECTRUM_STOP()
#endif
#if TM_PROFILE_QMFSYNTH
#define QMFSYNTH_START() PROFILE_START()
#define QMFSYNTH_STOP() PROFILE_STOP()
#else
#define QMFSYNTH_START()
#define QMFSYNTH_STOP()
#endif
#if TM_PROFILE_QMFDECOMP
#define QMFDECOMP_START() PROFILE_START()
#define QMFDECOMP_STOP() PROFILE_STOP()
#else
#define QMFDECOMP_START()
#define QMFDECOMP_STOP()
#endif
#if TM_PROFILE_FILTERBANKCOMPUTEBANK32
#define FILTERBANKCOMPUTEBANK32_START() PROFILE_START()
#define FILTERBANKCOMPUTEBANK32_STOP() PROFILE_STOP()
#else
#define FILTERBANKCOMPUTEBANK32_START()
#define FILTERBANKCOMPUTEBANK32_STOP()
#endif
#if TM_PROFILE_FILTERBANKCOMPUTEPSD16
#define FILTERBANKCOMPUTEPSD16_START() PROFILE_START()
#define FILTERBANKCOMPUTEPSD16_STOP() PROFILE_STOP()
#else
#define FILTERBANKCOMPUTEPSD16_START()
#define FILTERBANKCOMPUTEPSD16_STOP()
#endif
@@ -1,448 +0,0 @@
/* Copyright (C) 2007 Hong Zhiqian */
/**
@file quant_lsp_tm.h
@author Hong Zhiqian
@brief Various compatibility routines for Speex (TriMedia version)
*/
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``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 FOUNDATION OR
CONTRIBUTORS 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 <ops/custom_defs.h>
#include "profile_tm.h"
#ifdef FIXED_POINT
#define OVERRIDE_COMPUTE_QUANT_WEIGHTS
static void compute_quant_weights(Int16 *qlsp, Int16 *qw, int order)
{
int qlspi, qlspii;
int w1, w2;
int i;
TMDEBUG_ALIGNMEM(qlsp);
TMDEBUG_ALIGNMEM(qw);
COMPUTEQUANTWEIGHTS_START();
--order;
qlspi = (int)qlsp[0];
qlspii = (int)qlsp[1];
w1 = qlspi;
w2 = qlspii - qlspi;
qw[0] = 81920 / (300 + imin(w1,w2));
for ( i=1 ; i<order ; ++i )
{ qlspi = qlspii;
qlspii = qlsp[i+1];
w1 = w2;
w2 = qlspii - qlspi;
qw[i] = 81920 / (300 + imin(w1,w2));
}
w1 = LSP_PI - qlspii;
qw[i] = 81920 / (300 + imin(w1,w2));
COMPUTEQUANTWEIGHTS_STOP();
}
#define OVERRIDE_LSP_QUANT
static int lsp_quant(Int16 *x, const signed char *cdbk, int nbVec, int nbDim)
{
register int best_dist=VERY_LARGE32;
register int best_id=0;
register int i, j;
register int dt0, dt1, dt2, dt3;
register int cb0, cb1, cb2, cb3, xx;
register int ptr_inc = nbDim * 3;
register int five = 5;
const signed char *ptr;
TMDEBUG_ALIGNMEM(x);
LSPQUANT_START();
for ( i=0, ptr=cdbk ; i<nbVec ; i+=4, ptr += ptr_inc )
{ dt3 = dt2 = dt1 = dt0 = 0;
for ( j=0 ; j <nbDim ; j += 2 )
{
xx = ld32x(x,j>>1);
cb0 = pack16lsb((int)ptr[1], (int)ptr[0]);
cb0 = dualasl(cb0,five);
cb0 = dspidualsub(xx,cb0);
dt0 += ifir16(cb0,cb0);
cb1 = pack16lsb((int)ptr[nbDim+1], (int)ptr[nbDim]);
cb1 = dualasl(cb1,five);
cb1 = dspidualsub(xx,cb1);
dt1 += ifir16(cb1, cb1);
cb2 = pack16lsb((int)ptr[nbDim*2+1], (int)ptr[nbDim*2]);
cb2 = dualasl(cb2,five);
cb2 = dspidualsub(xx,cb2);
dt2 += ifir16(cb2, cb2);
cb3 = pack16lsb((int)ptr[nbDim*3+1], (int)ptr[nbDim*3]);
cb3 = dualasl(cb3,five);
cb3 = dspidualsub(xx,cb3);
dt3 += ifir16(cb3, cb3);
ptr += 2;
}
if ( dt0<best_dist )
{ best_dist = dt0;
best_id = i;
}
if ( dt1<best_dist )
{ best_dist = dt1;
best_id = i+1;
}
if ( dt2<best_dist )
{ best_dist = dt2;
best_id = i+2;
}
if ( dt3<best_dist )
{ best_dist = dt3;
best_id = i+3;
}
}
for ( j=0,ptr=cdbk+best_id*nbDim ; j<nbDim ; j+=2 )
{ xx = ld32x(x,j>>1);
cb0 = pack16lsb((int)ptr[j+1], (int)ptr[j]);
cb0 = dualasl(cb0,five);
dt0 = dspidualsub(xx,cb0);
st32d(j<<1, x, dt0);
}
LSPQUANT_STOP();
return best_id;
}
#define OVERRIDE_LSP_WEIGHT_QUANT
static int lsp_weight_quant(Int16 *x, Int16 *weight, const signed char *cdbk, int nbVec, int nbDim)
{
register int best_dist=VERY_LARGE32;
register int best_id=0;
register int i, j;
register int dt1, dt2, dt3, dt4;
register int cb1, cb2, cb3, cb4, wt, xx;
register int ptr_inc = nbDim * 3;
const signed char *ptr;
LSPWEIGHTQUANT_START();
for ( i=0, ptr=cdbk ; i<nbVec ; i+=4, ptr += ptr_inc )
{ dt4 = dt3 = dt2 = dt1 = 0;
for ( j=0 ; j<nbDim ; ++j )
{ wt = weight[j];
xx = x[j];
cb1 = xx - (ptr[0] << 5);
cb2 = xx - (ptr[nbDim] << 5);
cb3 = xx - (ptr[nbDim*2] << 5);
cb4 = xx - (ptr[nbDim*3] << 5);
++ptr;
cb1 *= cb1;
cb2 *= cb2;
cb3 *= cb3;
cb4 *= cb4;
dt1 += (wt * (cb1 >> 15)) + ((wt * (cb1 & 0x7fff)) >> 15);
dt2 += (wt * (cb2 >> 15)) + ((wt * (cb2 & 0x7fff)) >> 15);
dt3 += (wt * (cb3 >> 15)) + ((wt * (cb3 & 0x7fff)) >> 15);
dt4 += (wt * (cb4 >> 15)) + ((wt * (cb4 & 0x7fff)) >> 15);
}
if ( dt1<best_dist )
{ best_dist = dt1;
best_id = i;
}
if ( dt2<best_dist )
{ best_dist = dt2;
best_id = i+1;
}
if ( dt3<best_dist )
{ best_dist = dt3;
best_id = i+2;
}
if ( dt4<best_dist )
{ best_dist = dt4;
best_id = i+3;
}
}
for ( j=0 ; j<nbDim ; ++j )
{ x[j] = x[j] - ((Int16)cdbk[best_id*nbDim+j] << 5);
}
LSPWEIGHTQUANT_STOP();
return best_id;
}
#if 0
// TODO: unroll loops
#define OVERRIDE_LSP_QUANT_NB
void lsp_quant_nb(spx_lsp_t *lsp, spx_lsp_t *qlsp, int order, SpeexBits *bits)
{
int i;
int id;
spx_word16_t quant_weight[10];
for (i=0;i<order;i++)
qlsp[i]=lsp[i];
compute_quant_weights(qlsp, quant_weight, order);
for (i=0;i<order;i++)
qlsp[i]=SUB16(qlsp[i],LSP_LINEAR(i));
#ifndef FIXED_POINT
for (i=0;i<order;i++)
qlsp[i] = LSP_SCALE*qlsp[i];
#endif
id = lsp_quant(qlsp, cdbk_nb, NB_CDBK_SIZE, order);
speex_bits_pack(bits, id, 6);
for (i=0;i<order;i++)
qlsp[i]*=2;
id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
speex_bits_pack(bits, id, 6);
for (i=0;i<5;i++)
qlsp[i]*=2;
id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low2, NB_CDBK_SIZE_LOW2, 5);
speex_bits_pack(bits, id, 6);
id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
speex_bits_pack(bits, id, 6);
for (i=5;i<10;i++)
qlsp[i]*=2;
id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high2, NB_CDBK_SIZE_HIGH2, 5);
speex_bits_pack(bits, id, 6);
#ifdef FIXED_POINT
for (i=0;i<order;i++)
qlsp[i]=PSHR16(qlsp[i],2);
#else
for (i=0;i<order;i++)
qlsp[i]=qlsp[i] * .00097656;
#endif
for (i=0;i<order;i++)
qlsp[i]=lsp[i]-qlsp[i];
}
#define OVERRIDE_LSP_UNQUANT_NB
void lsp_unquant_nb(spx_lsp_t *lsp, int order, SpeexBits *bits)
{
int i, id;
for (i=0;i<order;i++)
lsp[i]=LSP_LINEAR(i);
id=speex_bits_unpack_unsigned(bits, 6);
for (i=0;i<10;i++)
lsp[i] = ADD32(lsp[i], LSP_DIV_256(cdbk_nb[id*10+i]));
id=speex_bits_unpack_unsigned(bits, 6);
for (i=0;i<5;i++)
lsp[i] = ADD16(lsp[i], LSP_DIV_512(cdbk_nb_low1[id*5+i]));
id=speex_bits_unpack_unsigned(bits, 6);
for (i=0;i<5;i++)
lsp[i] = ADD32(lsp[i], LSP_DIV_1024(cdbk_nb_low2[id*5+i]));
id=speex_bits_unpack_unsigned(bits, 6);
for (i=0;i<5;i++)
lsp[i+5] = ADD32(lsp[i+5], LSP_DIV_512(cdbk_nb_high1[id*5+i]));
id=speex_bits_unpack_unsigned(bits, 6);
for (i=0;i<5;i++)
lsp[i+5] = ADD32(lsp[i+5], LSP_DIV_1024(cdbk_nb_high2[id*5+i]));
}
#define OVERRIDE_LSP_QUANT_LBR
void lsp_quant_lbr(spx_lsp_t *lsp, spx_lsp_t *qlsp, int order, SpeexBits *bits)
{
int i;
int id;
spx_word16_t quant_weight[10];
for (i=0;i<order;i++)
qlsp[i]=lsp[i];
compute_quant_weights(qlsp, quant_weight, order);
for (i=0;i<order;i++)
qlsp[i]=SUB16(qlsp[i],LSP_LINEAR(i));
#ifndef FIXED_POINT
for (i=0;i<order;i++)
qlsp[i]=qlsp[i]*LSP_SCALE;
#endif
id = lsp_quant(qlsp, cdbk_nb, NB_CDBK_SIZE, order);
speex_bits_pack(bits, id, 6);
for (i=0;i<order;i++)
qlsp[i]*=2;
id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
speex_bits_pack(bits, id, 6);
id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
speex_bits_pack(bits, id, 6);
#ifdef FIXED_POINT
for (i=0;i<order;i++)
qlsp[i] = PSHR16(qlsp[i],1);
#else
for (i=0;i<order;i++)
qlsp[i] = qlsp[i]*0.0019531;
#endif
for (i=0;i<order;i++)
qlsp[i]=lsp[i]-qlsp[i];
}
#define OVERRIDE_LSP_UNQUANT_LBR
void lsp_unquant_lbr(spx_lsp_t *lsp, int order, SpeexBits *bits)
{
int i, id;
for (i=0;i<order;i++)
lsp[i]=LSP_LINEAR(i);
id=speex_bits_unpack_unsigned(bits, 6);
for (i=0;i<10;i++)
lsp[i] += LSP_DIV_256(cdbk_nb[id*10+i]);
id=speex_bits_unpack_unsigned(bits, 6);
for (i=0;i<5;i++)
lsp[i] += LSP_DIV_512(cdbk_nb_low1[id*5+i]);
id=speex_bits_unpack_unsigned(bits, 6);
for (i=0;i<5;i++)
lsp[i+5] += LSP_DIV_512(cdbk_nb_high1[id*5+i]);
}
extern const signed char high_lsp_cdbk[];
extern const signed char high_lsp_cdbk2[];
#define OVERRIDE_LSP_UNQUANT_HIGH
void lsp_unquant_high(spx_lsp_t *lsp, int order, SpeexBits *bits)
{
int i, id;
for (i=0;i<order;i++)
lsp[i]=LSP_LINEAR_HIGH(i);
id=speex_bits_unpack_unsigned(bits, 6);
for (i=0;i<order;i++)
lsp[i] += LSP_DIV_256(high_lsp_cdbk[id*order+i]);
id=speex_bits_unpack_unsigned(bits, 6);
for (i=0;i<order;i++)
lsp[i] += LSP_DIV_512(high_lsp_cdbk2[id*order+i]);
}
#define OVERRIDE_LSP_QUANT_HIGH
void lsp_quant_high(spx_lsp_t *lsp, spx_lsp_t *qlsp, int order, SpeexBits *bits)
{
int i;
int id;
spx_word16_t quant_weight[10];
for (i=0;i<order;i++)
qlsp[i]=lsp[i];
compute_quant_weights(qlsp, quant_weight, order);
/* quant_weight[0] = 10/(qlsp[1]-qlsp[0]);
quant_weight[order-1] = 10/(qlsp[order-1]-qlsp[order-2]);
for (i=1;i<order-1;i++)
{
tmp1 = 10/(qlsp[i]-qlsp[i-1]);
tmp2 = 10/(qlsp[i+1]-qlsp[i]);
quant_weight[i] = tmp1 > tmp2 ? tmp1 : tmp2;
}*/
for (i=0;i<order;i++)
qlsp[i]=SUB16(qlsp[i],LSP_LINEAR_HIGH(i));
#ifndef FIXED_POINT
for (i=0;i<order;i++)
qlsp[i] = qlsp[i]*LSP_SCALE;
#endif
id = lsp_quant(qlsp, high_lsp_cdbk, 64, order);
speex_bits_pack(bits, id, 6);
for (i=0;i<order;i++)
qlsp[i]*=2;
id = lsp_weight_quant(qlsp, quant_weight, high_lsp_cdbk2, 64, order);
speex_bits_pack(bits, id, 6);
#ifdef FIXED_POINT
for (i=0;i<order;i++)
qlsp[i] = PSHR16(qlsp[i],1);
#else
for (i=0;i<order;i++)
qlsp[i] = qlsp[i]*0.0019531;
#endif
for (i=0;i<order;i++)
qlsp[i]=lsp[i]-qlsp[i];
}
#endif
#endif
@@ -1,31 +0,0 @@
#ifndef __SPEEX_TYPES_H__
#define __SPEEX_TYPES_H__
#ifdef __TCS__
#include <tmNxTypes.h>
typedef Int16 spx_int16_t;
typedef UInt16 spx_uint16_t;
typedef Int32 spx_int32_t;
typedef UInt32 spx_uint32_t;
#ifdef FIXED_POINT
#define VMUX(a,b,c) mux((a),(b),(c))
#define VABS(a) iabs((a))
#define VMAX(a,b) imax((a),(b))
#define VMIN(a,b) imin((a),(b))
#else
#define VMUX(a,b,c) fmux((a),(b),(c))
#define VABS(a) fabs((a))
#define VMAX(a,b) fmax((a),(b))
#define VMIN(a,b) fmin((a),(b))
#endif
#endif
#endif
-494
View File
@@ -1,494 +0,0 @@
/* Copyright (C) 2007 Hong Zhiqian */
/**
@file vq_tm.h
@author Hong Zhiqian
@brief Various compatibility routines for Speex (TriMedia version)
*/
/*
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
- Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
- 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.
- Neither the name of the Xiph.org Foundation nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``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 FOUNDATION OR
CONTRIBUTORS 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 <ops/custom_defs.h>
#include "profile_tm.h"
#ifdef FIXED_POINT
inline void vq_nbest_dist(int i, int N, int dist, int *used, int *nbest, Int32 *best_dist)
{
register int k;
if (i<N || dist<best_dist[N-1])
{
for (k=N-1; (k >= 1) && (k > *used || dist < best_dist[k-1]); k--)
{ best_dist[k]=best_dist[k-1];
nbest[k] = nbest[k-1];
}
best_dist[k]=dist;
nbest[k]=i;
*used++;
}
}
void vq_nbest_5(Int16 *in, const Int16 *codebook, int entries, Int32 *E, int N, int *nbest, Int32 *best_dist)
{
register int i, j;
register int in10, in32, in4;
int used = 0;
in10 = pack16lsb(in[1],in[0]); /* Note: memory is not align here */
in32 = pack16lsb(in[3],in[2]);
in4 = sex16(in[4]);
#if (TM_UNROLL && TM_UNROLL_VQNBEST > 0)
#pragma TCS_unroll=2
#pragma TCS_unrollexact=1
#endif
for ( i=0,j=0 ; i<entries ; i+=2,j+=5 )
{
register int dist1, dist2;
register int cb10, cb32, cb54, cb76, cb98, cb87, cb65;
cb10 = ld32x(codebook,j);
cb32 = ld32x(codebook,j+1);
cb54 = ld32x(codebook,j+2);
cb76 = ld32x(codebook,j+3);
cb98 = ld32x(codebook,j+4);
dist1 = sex16(cb54) * in4;
dist1 += ifir16(in10,cb10) + ifir16(in32,cb32);
dist1 = (E[i] >> 1) - dist1;
cb65 = funshift2(cb76,cb54);
cb87 = funshift2(cb98,cb76);
dist2 = asri(16,cb98) * in4;
dist2 += ifir16(in10,cb65) + ifir16(in32,cb87);
dist2 = (E[i+1] >> 1) - dist2;
vq_nbest_dist(i,N,dist1,&used,nbest,best_dist);
vq_nbest_dist(i+1,N,dist2,&used,nbest,best_dist);
}
#if (TM_UNROLL && TM_UNROLL_VQNBEST > 0)
#pragma TCS_unrollexact=0
#pragma TCS_unroll=0
#endif
}
void vq_nbest_8(Int16 *in, const Int16 *codebook, int entries, Int32 *E, int N, int *nbest, Int32 *best_dist)
{
register int i, j;
register int in10, in32, in54, in76;
int used = 0;
in10 = pack16lsb(in[1],in[0]); /* Note: memory is not align here */
in32 = pack16lsb(in[3],in[2]);
in54 = pack16lsb(in[5],in[4]);
in76 = pack16lsb(in[7],in[6]);
#if (TM_UNROLL && TM_UNROLL_VQNBEST > 0)
#pragma TCS_unroll=4
#pragma TCS_unrollexact=1
#endif
for ( i=0,j=0 ; i<entries ; ++i,j+=4 )
{
register int dist;
register int cb10, cb32, cb54, cb76;
cb10 = ld32x(codebook,j);
cb32 = ld32x(codebook,j+1);
cb54 = ld32x(codebook,j+2);
cb76 = ld32x(codebook,j+3);
dist = ifir16(in10,cb10) + ifir16(in32,cb32);
dist += ifir16(in54,cb54) + ifir16(in76,cb76);
dist = (E[i] >> 1) - dist;
vq_nbest_dist(i,N,dist,&used,nbest,best_dist);
}
#if (TM_UNROLL && TM_UNROLL_VQNBEST > 0)
#pragma TCS_unrollexact=0
#pragma TCS_unroll=0
#endif
}
void vq_nbest_10(Int16 *in, const Int16 *codebook, int entries, Int32 *E, int N, int *nbest, Int32 *best_dist)
{
register int i, j;
register int in10, in32, in54, in76, in98;
int used = 0;
in10 = pack16lsb(in[1],in[0]);
in32 = pack16lsb(in[3],in[2]);
in54 = pack16lsb(in[5],in[4]);
in76 = pack16lsb(in[7],in[6]);
in98 = pack16lsb(in[9],in[8]);
#if (TM_UNROLL && TM_UNROLL_VQNBEST > 0)
#pragma TCS_unroll=4
#pragma TCS_unrollexact=1
#endif
for ( i=0,j=0 ; i<entries ; ++i,j+=5 )
{
register int dist;
register int cb10, cb32, cb54, cb76, cb98;
cb10 = ld32x(codebook,j);
cb32 = ld32x(codebook,j+1);
cb54 = ld32x(codebook,j+2);
cb76 = ld32x(codebook,j+3);
cb98 = ld32x(codebook,j+4);
dist = ifir16(in10,cb10) + ifir16(in32,cb32);
dist += ifir16(in54,cb54) + ifir16(in76,cb76);
dist += ifir16(in98,cb98);
dist = (E[i] >> 1) - dist;
vq_nbest_dist(i,N,dist,&used,nbest,best_dist);
}
#if (TM_UNROLL && TM_UNROLL_VQNBEST > 0)
#pragma TCS_unrollexact=0
#pragma TCS_unroll=0
#endif
}
void vq_nbest_20(Int16 *in, const Int16 *codebook, int entries, Int32 *E, int N, int *nbest, Int32 *best_dist)
{
register int i, j;
register int in10, in32, in54, in76, in98, in_10, in_32, in_54, in_76, in_98;
int used = 0;
in10 = pack16lsb(in[1],in[0]); /* Note: memory is not align here */
in32 = pack16lsb(in[3],in[2]);
in54 = pack16lsb(in[5],in[4]);
in76 = pack16lsb(in[6],in[6]);
in98 = pack16lsb(in[9],in[8]);
in_10 = pack16lsb(in[11],in[10]);
in_32 = pack16lsb(in[13],in[12]);
in_54 = pack16lsb(in[15],in[14]);
in_76 = pack16lsb(in[17],in[16]);
in_98 = pack16lsb(in[19],in[18]);
#if (TM_UNROLL && TM_UNROLL_VQNBEST > 0)
#pragma TCS_unroll=2
#pragma TCS_unrollexact=1
#endif
for ( i=0,j=0 ; i<entries ; ++i,j+=10 )
{
register int dist;
register int cb10, cb32, cb54, cb76, cb98, cb_10, cb_32, cb_54, cb_76, cb_98;
cb10 = ld32x(codebook,j);
cb32 = ld32x(codebook,j+1);
cb54 = ld32x(codebook,j+2);
cb76 = ld32x(codebook,j+3);
cb98 = ld32x(codebook,j+4);
cb_10 = ld32x(codebook,j+5);
cb_32 = ld32x(codebook,j+6);
cb_54 = ld32x(codebook,j+7);
cb_76 = ld32x(codebook,j+8);
cb_98 = ld32x(codebook,j+9);
dist = ifir16(in10,cb10) + ifir16(in32,cb32);
dist += ifir16(in54,cb54) + ifir16(in76,cb76);
dist += ifir16(in98,cb98) + ifir16(in_10,cb_10);
dist += ifir16(in_32,cb_32) + ifir16(in_54,cb_54);
dist += ifir16(in_76,cb_76) + ifir16(in_98,cb_98);
dist = (E[i] >> 1) - dist;
vq_nbest_dist(i,N,dist,&used,nbest,best_dist);
}
#if (TM_UNROLL && TM_UNROLL_VQNBEST > 0)
#pragma TCS_unrollexact=0
#pragma TCS_unroll=0
#endif
}
#define OVERRIDE_VQ_NBEST
void vq_nbest (Int16 *in, const Int16 *codebook, int len, int entries, Int32 *E, int N, int *nbest, Int32 *best_dist, char *stack)
{
TMDEBUG_ALIGNMEM(codebook);
VQNBEST_START();
if( len==5 )
vq_nbest_5(in,codebook,entries,E,N,nbest,best_dist);
else if ( len==8 )
vq_nbest_8(in,codebook,entries,E,N,nbest,best_dist);
else if ( len==10 )
vq_nbest_10(in,codebook,entries,E,N,nbest,best_dist);
else if ( len==20 )
vq_nbest_20(in,codebook,entries,E,N,nbest,best_dist);
#ifndef REMARK_ON
(void)stack;
#endif
VQNBEST_STOP();
}
inline void vq_nbest_sign_dist(int i, int N, int dist, int sign, int entries, int *used, int *nbest, Int32 *best_dist)
{
register int k;
if (i<N || dist<best_dist[N-1])
{ for (k=N-1; (k >= 1) && (k > *used || dist < best_dist[k-1]); k--)
{
best_dist[k]=best_dist[k-1];
nbest[k] = nbest[k-1];
}
if ( sign ) i += entries;
best_dist[k]=dist;
*used++;
nbest[k] = i;
}
}
void vq_nbest_sign_5(Int16 *in, const Int16 *codebook, int entries, Int32 *E, int N, int *nbest, Int32 *best_dist)
{
register int i, j;
register int in10, in32, in4;
int used = 0;
in10 = ld32(in);
in32 = ld32x(in,1);
in4 = sex16(in[4]);
#if (TM_UNROLL && TM_UNROLL_VQSIGNNBEST > 0)
#pragma TCS_unroll=2
#pragma TCS_unrollexact=1
#endif
for ( i=0,j=0 ; i<entries ; i+=2,j+=5 )
{
register int dist1, dist2, sign1, sign2;
register int cb10, cb32, cb54, cb76, cb98, cb87, cb65;
cb10 = ld32x(codebook,j);
cb32 = ld32x(codebook,j+1);
cb54 = ld32x(codebook,j+2);
cb76 = ld32x(codebook,j+3);
cb98 = ld32x(codebook,j+4);
dist1 = sex16(cb54) * in4;
dist1 += ifir16(in10,cb10) + ifir16(in32,cb32);
sign1 = mux(dist1>0,0,1);
dist1 = iflip(dist1>0,dist1);
dist1 = (E[i] >> 1) + dist1;
cb65 = funshift2(cb76,cb54);
cb87 = funshift2(cb98,cb76);
dist2 = asri(16,cb98) * in4;
dist2 += ifir16(in10,cb65) + ifir16(in32,cb87);
sign2 = mux(dist2>0,0,1);
dist2 = iflip(dist2>0,dist2);
dist2 = (E[i] >> 1) + dist2;
vq_nbest_sign_dist(i,N,dist1,sign1,entries,&used,nbest,best_dist);
vq_nbest_sign_dist(i+1,N,dist2,sign2,entries,&used,nbest,best_dist);
}
#if (TM_UNROLL && TM_UNROLL_VQSIGNNBEST > 0)
#pragma TCS_unrollexact=0
#pragma TCS_unroll=0
#endif
}
void vq_nbest_sign_8(Int16 *in, const Int16 *codebook, int entries, Int32 *E, int N, int *nbest, Int32 *best_dist)
{
register int i, j;
register int sign;
register int in10, in32, in54, in76;
int used = 0;
in10 = ld32(in);
in32 = ld32x(in,1);
in54 = ld32x(in,2);
in76 = ld32x(in,3);
#if (TM_UNROLL && TM_UNROLL_VQSIGNNBEST > 0)
#pragma TCS_unroll=4
#pragma TCS_unrollexact=1
#endif
for ( i=0,j=0 ; i<entries ; ++i,j+=4 )
{
register int dist;
register int cb10, cb32, cb54, cb76;
cb10 = ld32x(codebook,j);
cb32 = ld32x(codebook,j+1);
cb54 = ld32x(codebook,j+2);
cb76 = ld32x(codebook,j+3);
dist = ifir16(in10,cb10) + ifir16(in32,cb32);
dist += ifir16(in54,cb54) + ifir16(in76,cb76);
sign = mux(dist>0,0,1);
dist = iflip(dist>0,dist);
dist = (E[i] >> 1) + dist;
vq_nbest_sign_dist(i,N,dist,sign,entries,&used,nbest,best_dist);
}
#if (TM_UNROLL && TM_UNROLL_VQSIGNNBEST > 0)
#pragma TCS_unrollexact=0
#pragma TCS_unroll=0
#endif
}
void vq_nbest_sign_10(Int16 *in, const Int16 *codebook, int entries, Int32 *E, int N, int *nbest, Int32 *best_dist)
{
register int i, j;
register int sign;
register int in10, in32, in54, in76, in98;
int used = 0;
in10 = ld32(in);
in32 = ld32x(in,1);
in54 = ld32x(in,2);
in76 = ld32x(in,3);
in98 = ld32x(in,4);
#if (TM_UNROLL && TM_UNROLL_VQSIGNNBEST > 0)
#pragma TCS_unroll=4
#pragma TCS_unrollexact=1
#endif
for ( i=0,j=0 ; i<entries ; ++i,j+=5 )
{
register int dist;
register int cb10, cb32, cb54, cb76, cb98;
cb10 = ld32x(codebook,j);
cb32 = ld32x(codebook,j+1);
cb54 = ld32x(codebook,j+2);
cb76 = ld32x(codebook,j+3);
cb98 = ld32x(codebook,j+4);
dist = ifir16(in10,cb10) + ifir16(in32,cb32);
dist += ifir16(in54,cb54) + ifir16(in76,cb76);
dist += ifir16(in98,cb98);
sign = mux(dist>0,0,1);
dist = iflip(dist>0,dist);
dist = (E[i] >> 1) + dist;
vq_nbest_sign_dist(i,N,dist,sign,entries,&used,nbest,best_dist);
}
#if (TM_UNROLL && TM_UNROLL_VQSIGNNBEST > 0)
#pragma TCS_unrollexact=0
#pragma TCS_unroll=0
#endif
}
void vq_nbest_sign_20(Int16 *in, const Int16 *codebook, int entries, Int32 *E, int N, int *nbest, Int32 *best_dist)
{
register int i, j;
register int sign;
register int in10, in32, in54, in76, in98, in_10, in_32, in_54, in_76, in_98;
int used = 0;
in10 = ld32(in);
in32 = ld32x(in,1);
in54 = ld32x(in,2);
in76 = ld32x(in,3);
in98 = ld32x(in,4);
in_10 = ld32x(in,5);
in_32 = ld32x(in,6);
in_54 = ld32x(in,7);
in_76 = ld32x(in,8);
in_98 = ld32x(in,9);
#if (TM_UNROLL && TM_UNROLL_VQSIGNNBEST > 0)
#pragma TCS_unroll=2
#pragma TCS_unrollexact=1
#endif
for ( i=0,j=0 ; i<entries ; ++i,j+=10 )
{
register int dist;
register int cb10, cb32, cb54, cb76, cb98, cb_10, cb_32, cb_54, cb_76, cb_98;
cb10 = ld32x(codebook,j);
cb32 = ld32x(codebook,j+1);
cb54 = ld32x(codebook,j+2);
cb76 = ld32x(codebook,j+3);
cb98 = ld32x(codebook,j+4);
cb_10 = ld32x(codebook,j+5);
cb_32 = ld32x(codebook,j+6);
cb_54 = ld32x(codebook,j+7);
cb_76 = ld32x(codebook,j+8);
cb_98 = ld32x(codebook,j+9);
dist = ifir16(in10,cb10) + ifir16(in32,cb32);
dist += ifir16(in54,cb54) + ifir16(in76,cb76);
dist += ifir16(in98,cb98) + ifir16(in_10,cb_10);
dist += ifir16(in_32,cb_32) + ifir16(in_54,cb_54);
dist += ifir16(in_76,cb_76) + ifir16(in_98,cb_98);
sign = mux(dist>0,0,1);
dist = iflip(dist>0,dist);
dist = (E[i] >> 1) + dist;
vq_nbest_sign_dist(i,N,dist,sign,entries,&used,nbest,best_dist);
}
#if (TM_UNROLL && TM_UNROLL_VQSIGNNBEST > 0)
#pragma TCS_unrollexact=0
#pragma TCS_unroll=0
#endif
}
#define OVERRIDE_VQ_NBEST_SIGN
void vq_nbest_sign (Int16 *in, const Int16 *codebook, int len, int entries, Int32 *E, int N, int *nbest, Int32 *best_dist, char *stack)
{
TMDEBUG_ALIGNMEM(in);
TMDEBUG_ALIGNMEM(codebook);
VQNBESTSIGN_START();
if( len==5 )
vq_nbest_sign_5(in,codebook,entries,E,N,nbest,best_dist);
else if ( len==8 )
vq_nbest_sign_8(in,codebook,entries,E,N,nbest,best_dist);
else if ( len==10 )
vq_nbest_sign_10(in,codebook,entries,E,N,nbest,best_dist);
else if ( len==20 )
vq_nbest_sign_20(in,codebook,entries,E,N,nbest,best_dist);
#ifndef REMARK_ON
(void)stack;
#endif
VQNBESTSIGN_STOP();
}
#endif