⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cb_search.c

📁 tcpmp.src.0.72RC1 优秀的多媒体播放器TCPMP的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* Copyright (C) 2002 Jean-Marc Valin    File: cb_search.c   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.*/#ifdef HAVE_CONFIG_H#include "config.h"#endif#include "cb_search.h"#include "filters.h"#include "stack_alloc.h"#include "vq.h"#include "misc.h"#ifdef _USE_SSE#include "cb_search_sse.h"#elif defined(ARM4_ASM) || defined(ARM5E_ASM)#include "cb_search_arm4.h"#elif defined(BFIN_ASM)#include "cb_search_bfin.h"#endif#ifndef OVERRIDE_COMPUTE_WEIGHTED_CODEBOOKstatic void compute_weighted_codebook(const signed char *shape_cb, const spx_word16_t *r, spx_word16_t *resp, spx_word16_t *resp2, spx_word32_t *E, int shape_cb_size, int subvect_size, char *stack){   int i, j, k;   VARDECL(spx_word16_t *shape);   ALLOC(shape, subvect_size, spx_word16_t);   for (i=0;i<shape_cb_size;i++)   {      spx_word16_t *res;            res = resp+i*subvect_size;      for (k=0;k<subvect_size;k++)         shape[k] = (spx_word16_t)shape_cb[i*subvect_size+k];      E[i]=0;      /* Compute codeword response using convolution with impulse response */      for(j=0;j<subvect_size;j++)      {         spx_word32_t resj=0;         spx_word16_t res16;         for (k=0;k<=j;k++)            resj = MAC16_16(resj,shape[k],r[j-k]);#ifdef FIXED_POINT         res16 = EXTRACT16(SHR32(resj, 11));#else         res16 = 0.03125f*resj;#endif         /* Compute codeword energy */         E[i]=MAC16_16(E[i],res16,res16);         res[j] = res16;         /*printf ("%d\n", (int)res[j]);*/      }   }}#endif#ifndef OVERRIDE_TARGET_UPDATEstatic inline void target_update(spx_word16_t *t, spx_word16_t g, spx_word16_t *r, int len){   int n;   int q=0;   for (n=0;n<len;n++,q++)      t[n] = SUB32(t[n],MULT16_16_Q11_32(g,r[q]));}#endifstatic void split_cb_search_shape_sign_N1(spx_sig_t target[],			/* target vector */spx_coef_t ak[],			/* LPCs for this subframe */spx_coef_t awk1[],			/* Weighted LPCs for this subframe */spx_coef_t awk2[],			/* Weighted LPCs for this subframe */const void *par,                      /* Codebook/search parameters*/int   p,                        /* number of LPC coeffs */int   nsf,                      /* number of samples in subframe */spx_sig_t *exc,spx_word16_t *r,SpeexBits *bits,char *stack,int   complexity,int   update_target){   int i,j,m,n,q;   VARDECL(spx_word16_t *resp);#ifdef _USE_SSE   VARDECL(__m128 *resp2);   VARDECL(__m128 *E);#else   spx_word16_t *resp2;   VARDECL(spx_word32_t *E);#endif   VARDECL(spx_word16_t *t);   VARDECL(spx_sig_t *e);   const signed char *shape_cb;   int shape_cb_size, subvect_size, nb_subvect;   const split_cb_params *params;   int N=2;   int best_index;   spx_word32_t best_dist;   int have_sign;   N=complexity;   if (N>10)      N=10;   if (N<1)      N=1;      params = (const split_cb_params *) par;   subvect_size = params->subvect_size;   nb_subvect = params->nb_subvect;   shape_cb_size = 1<<params->shape_bits;   shape_cb = params->shape_cb;   have_sign = params->have_sign;   ALLOC(resp, shape_cb_size*subvect_size, spx_word16_t);#ifdef _USE_SSE   ALLOC(resp2, (shape_cb_size*subvect_size)>>2, __m128);   ALLOC(E, shape_cb_size>>2, __m128);#else   resp2 = resp;   ALLOC(E, shape_cb_size, spx_word32_t);#endif   ALLOC(t, nsf, spx_word16_t);   ALLOC(e, nsf, spx_sig_t);      /* FIXME: make that adaptive? */   for (i=0;i<nsf;i++)      t[i]=EXTRACT16(PSHR32(target[i],6));   compute_weighted_codebook(shape_cb, r, resp, resp2, E, shape_cb_size, subvect_size, stack);   for (i=0;i<nb_subvect;i++)   {      spx_word16_t *x=t+subvect_size*i;      /*Find new n-best based on previous n-best j*/      if (have_sign)         vq_nbest_sign(x, resp2, subvect_size, shape_cb_size, E, 1, &best_index, &best_dist, stack);      else         vq_nbest(x, resp2, subvect_size, shape_cb_size, E, 1, &best_index, &best_dist, stack);            speex_bits_pack(bits,best_index,params->shape_bits+have_sign);            {         int rind;         spx_word16_t *res;         spx_word16_t sign=1;         rind = best_index;         if (rind>=shape_cb_size)         {            sign=-1;            rind-=shape_cb_size;         }         res = resp+rind*subvect_size;         if (sign>0)            for (m=0;m<subvect_size;m++)               t[subvect_size*i+m] = SUB16(t[subvect_size*i+m], res[m]);         else            for (m=0;m<subvect_size;m++)               t[subvect_size*i+m] = ADD16(t[subvect_size*i+m], res[m]);#ifdef FIXED_POINT         if (sign)         {            for (j=0;j<subvect_size;j++)               e[subvect_size*i+j]=SHL32(EXTEND32(shape_cb[rind*subvect_size+j]),SIG_SHIFT-5);         } else {            for (j=0;j<subvect_size;j++)               e[subvect_size*i+j]=NEG32(SHL32(EXTEND32(shape_cb[rind*subvect_size+j]),SIG_SHIFT-5));         }#else         for (j=0;j<subvect_size;j++)            e[subvect_size*i+j]=sign*0.03125*shape_cb[rind*subvect_size+j];#endif            }                  for (m=0;m<subvect_size;m++)      {         spx_word16_t g;         int rind;         spx_word16_t sign=1;         rind = best_index;         if (rind>=shape_cb_size)         {            sign=-1;            rind-=shape_cb_size;         }                  q=subvect_size-m;#ifdef FIXED_POINT         g=sign*shape_cb[rind*subvect_size+m];         target_update(t+subvect_size*(i+1), g, r+q, nsf-subvect_size*(i+1));#else         g=sign*0.03125*shape_cb[rind*subvect_size+m];         /*FIXME: I think that one too can be replaced by target_update */         for (n=subvect_size*(i+1);n<nsf;n++,q++)            t[n] = SUB32(t[n],g*r[q]);#endif      }   }   /* Update excitation */   /* FIXME: We could update the excitation directly above */   for (j=0;j<nsf;j++)      exc[j]=ADD32(exc[j],e[j]);      /* Update target: only update target if necessary */   if (update_target)   {      VARDECL(spx_sig_t *r2);      ALLOC(r2, nsf, spx_sig_t);      syn_percep_zero(e, ak, awk1, awk2, r2, nsf,p, stack);      for (j=0;j<nsf;j++)         target[j]=SUB32(target[j],r2[j]);   }}void split_cb_search_shape_sign(spx_sig_t target[],			/* target vector */spx_coef_t ak[],			/* LPCs for this subframe */spx_coef_t awk1[],			/* Weighted LPCs for this subframe */spx_coef_t awk2[],			/* Weighted LPCs for this subframe */const void *par,                      /* Codebook/search parameters*/int   p,                        /* number of LPC coeffs */int   nsf,                      /* number of samples in subframe */spx_sig_t *exc,spx_word16_t *r,SpeexBits *bits,char *stack,int   complexity,int   update_target){   int i,j,k,m,n,q;   VARDECL(spx_word16_t *resp);#ifdef _USE_SSE   VARDECL(__m128 *resp2);   VARDECL(__m128 *E);#else   spx_word16_t *resp2;   VARDECL(spx_word32_t *E);#endif   VARDECL(spx_word16_t *t);   VARDECL(spx_sig_t *e);   VARDECL(spx_sig_t *r2);   VARDECL(spx_word16_t *tmp);   VARDECL(spx_word32_t *ndist);   VARDECL(spx_word32_t *odist);   VARDECL(int *itmp);   VARDECL(spx_word16_t **ot2);   VARDECL(spx_word16_t **nt2);   spx_word16_t **ot, **nt;   VARDECL(int **nind);   VARDECL(int **oind);   VARDECL(int *ind);   const signed char *shape_cb;   int shape_cb_size, subvect_size, nb_subvect;   const split_cb_params *params;   int N=2;   VARDECL(int *best_index);   VARDECL(spx_word32_t *best_dist);   VARDECL(int *best_nind);   VARDECL(int *best_ntarget);   int have_sign;   N=complexity;   if (N>10)      N=10;   if (N<1)      N=1;      if (N==1)   {      split_cb_search_shape_sign_N1(target,ak,awk1,awk2,par,p,nsf,exc,r,bits,stack,complexity,update_target);      return;   }   ALLOC(ot2, N, spx_word16_t*);   ALLOC(nt2, N, spx_word16_t*);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -