passable 650 bit/s mode, a lot better than previous 450
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 15 Apr 2015 05:28:01 +0000 (05:28 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 15 Apr 2015 05:28:01 +0000 (05:28 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@2118 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/bpf.h
codec2-dev/src/codec2.c
codec2-dev/src/codec2_internal.h

index 9cc916f513499022750c46e7717524f16c569ebc..0b0a6e277624954853263096146a616289fa0e2d 100644 (file)
@@ -102,4 +102,5 @@ float bpf[]={
   0.002147,
   0.003245,
   0.002174
-};
\ No newline at end of file
+};
+
index 1a4fc21a775a9fd74f00a2989e6645bd365b0176..7289f54ff576234b60476f580fadbf75d0816fe1 100644 (file)
@@ -45,6 +45,7 @@
 #include "lsp.h"
 #include "codec2_internal.h"
 #include "machdep.h"
+#include "bpf.h"
 
 /*---------------------------------------------------------------------------*\
                                                        
@@ -150,6 +151,11 @@ struct CODEC2 * CODEC2_WIN32SUPPORT codec2_create(int mode)
 
     c2->smoothing = 0;
 
+    c2->bpf_buf = (float*)malloc(sizeof(float)*(BPF_N+4*N));
+    assert(c2->bpf_buf != NULL);
+    for(i=0; i<BPF_N+4*N; i++)
+        c2->bpf_buf[i] = 0.0;
+
     return c2;
 }
 
@@ -166,6 +172,7 @@ struct CODEC2 * CODEC2_WIN32SUPPORT codec2_create(int mode)
 void CODEC2_WIN32SUPPORT codec2_destroy(struct CODEC2 *c2)
 {
     assert(c2 != NULL);
+    free(c2->bpf_buf);
     nlp_destroy(c2->nlp);
     KISS_FFT_FREE(c2->fft_fwd_cfg);
     KISS_FFT_FREE(c2->fft_inv_cfg);
@@ -1346,26 +1353,38 @@ void codec2_encode_650(struct CODEC2 *c2, unsigned char * bits, short speech[])
     int     indexes[LPC_ORD_LOW];
     int     Wo_index, e_index, i;
     unsigned int nbit = 0;
+    float   bpf_out[4*N];
+    short   bpf_speech[4*N];
 
     assert(c2 != NULL);
 
     memset(bits, '\0',  ((codec2_bits_per_frame(c2) + 7) / 8));
 
+    /* band pass filter */
+
+    for(i=0; i<BPF_N; i++)
+        c2->bpf_buf[i] = c2->bpf_buf[4*N+i];
+    for(i=0; i<4*N; i++)
+        c2->bpf_buf[BPF_N+i] = speech[i];
+    inverse_filter(&c2->bpf_buf[BPF_N], bpf, 4*N, bpf_out, BPF_N);
+    for(i=0; i<4*N; i++)
+        bpf_speech[i] = bpf_out[i];
+
     /* frame 1 --------------------------------------------------------*/
 
-    analyse_one_frame(c2, &model, speech);
+    analyse_one_frame(c2, &model, bpf_speech);
  
     /* frame 2 --------------------------------------------------------*/
 
-    analyse_one_frame(c2, &model, &speech[N]);
+    analyse_one_frame(c2, &model, &bpf_speech[N]);
  
     /* frame 3 --------------------------------------------------------*/
 
-    analyse_one_frame(c2, &model, &speech[2*N]);
+    analyse_one_frame(c2, &model, &bpf_speech[2*N]);
 
     /* frame 4: - voicing, scalar Wo & E, scalar LSPs -----------------*/
 
-    analyse_one_frame(c2, &model, &speech[3*N]);
+    analyse_one_frame(c2, &model, &bpf_speech[3*N]);
     pack(bits, &nbit, model.voiced, 1);
     Wo_index = encode_log_Wo(model.Wo, 5);
     pack_natural_or_gray(bits, &nbit, Wo_index, 5, c2->gray);
index aaaf0baa74b6f2bb0dfb21451943111e3185041a..bb1f207b5d1082fba3ee96b8c5a90d7e163e5013 100644 (file)
@@ -35,6 +35,7 @@ struct CODEC2 {
     float         w[M];                           /* time domain hamming window                */
     COMP          W[FFT_ENC];             /* DFT of w[]                                */
     float         Pn[2*N];                /* trapezoidal synthesis window              */
+    float        *bpf_buf;                /* buffer for band pass filter               */
     float         Sn[M];                   /* input speech                              */
     float         hpf_states[2];           /* high pass filter states                   */
     void         *nlp;                     /* pitch predictor states                    */