fixed a double_codebook bug and prevented pitch from doing weird things
authorjm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Wed, 23 Oct 2002 19:06:19 +0000 (19:06 +0000)
committerjm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Wed, 23 Oct 2002 19:06:19 +0000 (19:06 +0000)
in VBR mode when the last frame was vocoded.

git-svn-id: http://svn.xiph.org/trunk/speex@4042 0101bb08-14d6-0310-b084-bc0e0c8e3800

libspeex/cb_search.c
libspeex/ltp.c
libspeex/nb_celp.c
libspeex/nb_celp.h
libspeex/sb_celp.c

index af85375..7a98fb4 100644 (file)
@@ -68,7 +68,7 @@ int   complexity
 {
    int i,j,k,m,n,q;
    float *resp;
-   float *t, *e, *E;
+   float *t, *e, *E, *r2;
    /*FIXME: Should make this dynamic*/
    float *tmp, *_ot[20], *_nt[20];
    float *ndist, *odist;
@@ -89,8 +89,6 @@ int   complexity
    oind=_oind;
    nind=_nind;
    N=complexity;
-   if (N<1)
-      N=1;
    if (N>10)
       N=10;
 
@@ -103,6 +101,7 @@ int   complexity
    resp = PUSH(stack, shape_cb_size*subvect_size);
    t = PUSH(stack, nsf);
    e = PUSH(stack, nsf);
+   r2 = PUSH(stack, nsf);
    E = PUSH(stack, shape_cb_size);
    /*FIXME: This breaks if sizeof(int) != sizeof(float) */
    ind = (int*)PUSH(stack, nb_subvect);
@@ -222,6 +221,8 @@ int   complexity
             {
 
                /*previous target (we don't care what happened before*/
+               for (m=0;m<(i+1)*subvect_size;m++)
+                  t[m]=ct[m];
                for (m=(i+1)*subvect_size;m<nsf;m++)
                   t[m]=ct[m];
                /* New code: update the rest of the target only if it's worth it */
@@ -313,9 +314,9 @@ int   complexity
       exc[j]+=e[j];
    
    /* Update target */
-   syn_percep_zero(e, ak, awk1, awk2, r, nsf,p, stack);
+   syn_percep_zero(e, ak, awk1, awk2, r2, nsf,p, stack);
    for (j=0;j<nsf;j++)
-      target[j]-=r[j];
+      target[j]-=r2[j];
 
 }
 
index 23a3b30..412351f 100644 (file)
@@ -352,15 +352,21 @@ int complexity
    float *gains;
 
    N=complexity;
-   if (N<1)
-      N=1;
    if (N>10)
       N=10;
-
    /*FIXME: This breaks if sizeof(int) != sizeof(float) */
    nbest=(int*)PUSH(stack, N);
    gains = PUSH(stack, N);
    params = (ltp_params*) par;
+
+   if (N==0 || end<start)
+   {
+      speex_bits_pack(bits, 0, params->pitch_bits);
+      speex_bits_pack(bits, 0, params->gain_bits);
+      for (i=0;i<nsf;i++)
+         exc[i]=0;
+      return start;
+   }
    
    best_exc=PUSH(stack,nsf);
    
index 916fa20..a868b4c 100644 (file)
@@ -89,6 +89,7 @@ void *nb_encoder_init(SpeexMode *m)
    st->submodeID=mode->defaultSubmode;
    st->pre_mem=0;
    st->pre_mem2=0;
+   st->bounded_pitch = 0;
 
    /* Allocating input buffer */
    st->inBuf = speex_alloc(st->bufSize*sizeof(float));
@@ -302,10 +303,13 @@ void nb_encode(void *state, float *in, SpeexBits *bits)
 
 
       /*Open-loop pitch*/
-      if (SUBMODE(lbr_pitch) != -1 || st->vbr_enabled || SUBMODE(forced_pitch_gain)) {
+      /*if (SUBMODE(lbr_pitch) != -1 || st->vbr_enabled || SUBMODE(forced_pitch_gain))*/
+      if (!st->submodes[st->submodeID] || st->vbr_enabled || SUBMODE(forced_pitch_gain) ||
+          SUBMODE(lbr_pitch) != -1)
+      {
          int nol_pitch[4];
          float nol_pitch_coef[4];
-
+         
          bw_lpc(st->gamma1, st->interp_lpc, st->bw_lpc1, st->lpcSize);
          bw_lpc(st->gamma2, st->interp_lpc, st->bw_lpc2, st->lpcSize);
          
@@ -570,7 +574,9 @@ void nb_encode(void *state, float *in, SpeexBits *bits)
             pit_min = st->min_pitch;
             pit_max = st->max_pitch;
          }
-
+         
+         if (st->bounded_pitch && pit_max>offset)
+            pit_max=offset;
          pitch = SUBMODE(ltp_quant)(target, sw, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2,
                                     exc, SUBMODE(ltp_params), pit_min, pit_max, ol_pitch_coef,
                                     st->lpcSize, st->subframeSize, bits, stack, 
@@ -724,6 +730,10 @@ void nb_encode(void *state, float *in, SpeexBits *bits)
      in[i]=st->frame[i] + st->preemph*in[i-1];
    st->pre_mem2=in[st->frameSize-1];
 
+   if (SUBMODE(innovation_quant) == noise_codebook_quant)
+      st->bounded_pitch = 1;
+   else
+      st->bounded_pitch = 0;
 }
 
 
@@ -1238,6 +1248,8 @@ void nb_encoder_ctl(void *state, int request, void *ptr)
       break;
    case SPEEX_SET_COMPLEXITY:
       st->complexity = (*(int*)ptr);
+      if (st->complexity<1)
+         st->complexity=1;
       break;
    case SPEEX_GET_COMPLEXITY:
       (*(int*)ptr) = st->complexity;
index bc496b1..7d13de3 100644 (file)
@@ -54,6 +54,8 @@ typedef struct EncState {
    int    min_pitch;      /**< Minimum pitch value allowed */
    int    max_pitch;      /**< Maximum pitch value allowed */
 
+   int    safe_pitch;     /**< Don't use too large values for pitch (in case we lose a packet) */
+   int    bounded_pitch;  /**< Next frame should not rely on previous frames for pitch */
    int    ol_pitch;       /**< Open-loop pitch */
    int    ol_voiced;      /**< Open-loop voiced/non-voiced decision */
    int   *pitch;
index 5a318e8..fd5686b 100644 (file)
@@ -1037,6 +1037,8 @@ void sb_encoder_ctl(void *state, int request, void *ptr)
    case SPEEX_SET_COMPLEXITY:
       speex_encoder_ctl(st->st_low, SPEEX_SET_COMPLEXITY, ptr);
       st->complexity = (*(int*)ptr);
+      if (st->complexity<1)
+         st->complexity=1;
       break;
    case SPEEX_GET_COMPLEXITY:
       (*(int*)ptr) = st->complexity;