have a good quaity delta-t quantiser at about 15 bits/frame, when used for every...
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 2 Nov 2011 05:03:24 +0000 (05:03 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Wed, 2 Nov 2011 05:03:24 +0000 (05:03 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@297 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/Makefile.am
codec2-dev/src/Makefile.in
codec2-dev/src/c2sim.c
codec2-dev/src/defines.h
codec2-dev/src/genlspdtcb.c [new file with mode: 0644]
codec2-dev/src/quantise.c
codec2-dev/src/quantise.h

index 5f23697fa98001b630df5d4c3189c8a401541fd2..24bacf9c2edce4ebf7a8172db608bbc40b241295 100644 (file)
@@ -43,13 +43,20 @@ CODEBOOKSRES= \
   $D/lsp3.txt \
   $D/lsp4.txt
 
-noinst_PROGRAMS = generate_codebook
+CODEBOOKSDT= \
+  $D/lspdt1-4.txt \
+  $D/lspdt5-10.txt
+
+noinst_PROGRAMS = generate_codebook genlspdtcb
 
 codebook.$(OBJEXT): codebook.c
 codebookd.$(OBJEXT): codebookd.c
 codebookvq.$(OBJEXT): codebookvq.c
 codebookres.$(OBJEXT): codebookres.c
 
+$(CODEBOOKSDT): genlspdtcb
+       ./genlspdtcb
+
 codebook.lo: codebook.c
 
 codebook.c: generate_codebook $(CODEBOOKS)
@@ -64,8 +71,11 @@ codebookvq.c: generate_codebook $(CODEBOOKSVQ)
 codebookres.c: generate_codebook $(CODEBOOKSRES)
        ./generate_codebook lsp_cbres $(CODEBOOKSRES) > codebookres.c
 
+codebookdt.c: generate_codebook $(CODEBOOKSDT)
+       ./generate_codebook lsp_cbdt $(CODEBOOKSDT) > codebookdt.c
+
 clean-local:
-       -rm -f codebook.c codebookd.c codebookdvq.c codebookres.c
+       -rm -f codebook.c codebookd.c codebookdvq.c codebookres.c codebookdt.c
 
 lib_LTLIBRARIES        = libcodec2.la
 libcodec2_la_SOURCES = dump.c \
@@ -84,7 +94,8 @@ pack.c \
 codebook.c \
 codebookd.c \
 codebookvq.c \
-codebookres.c
+codebookres.c \
+codebookdt.c
 
 libcodec2_la_CFLAGS = $(AM_CFLAGS)
 libcodec2_la_LDFLAGS = $(LIBS)
index 603c08bc760db03e42f10ad429d7a15782aeb32c..39a273cc54755f049e20a55760c3578211e21f20 100644 (file)
@@ -38,7 +38,7 @@ PRE_UNINSTALL = :
 POST_UNINSTALL = :
 build_triplet = @build@
 host_triplet = @host@
-noinst_PROGRAMS = generate_codebook$(EXEEXT)
+noinst_PROGRAMS = generate_codebook$(EXEEXT) genlspdtcb$(EXEEXT)
 bin_PROGRAMS = c2demo$(EXEEXT) c2enc$(EXEEXT) c2dec$(EXEEXT) \
        c2sim$(EXEEXT)
 subdir = src
@@ -69,7 +69,7 @@ am_libcodec2_la_OBJECTS = libcodec2_la-dump.lo libcodec2_la-lpc.lo \
        libcodec2_la-phase.lo libcodec2_la-quantise.lo \
        libcodec2_la-pack.lo libcodec2_la-codebook.lo \
        libcodec2_la-codebookd.lo libcodec2_la-codebookvq.lo \
-       libcodec2_la-codebookres.lo
+       libcodec2_la-codebookres.lo libcodec2_la-codebookdt.lo
 libcodec2_la_OBJECTS = $(am_libcodec2_la_OBJECTS)
 binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
 PROGRAMS = $(bin_PROGRAMS) $(noinst_PROGRAMS)
@@ -89,6 +89,9 @@ c2sim_DEPENDENCIES = $(am__DEPENDENCIES_1)
 generate_codebook_SOURCES = generate_codebook.c
 generate_codebook_OBJECTS = generate_codebook.$(OBJEXT)
 generate_codebook_LDADD = $(LDADD)
+genlspdtcb_SOURCES = genlspdtcb.c
+genlspdtcb_OBJECTS = genlspdtcb.$(OBJEXT)
+genlspdtcb_LDADD = $(LDADD)
 DEFAULT_INCLUDES = -I. -I$(srcdir)
 depcomp = $(SHELL) $(top_srcdir)/depcomp
 am__depfiles_maybe = depfiles
@@ -101,10 +104,11 @@ CCLD = $(CC)
 LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
        $(AM_LDFLAGS) $(LDFLAGS) -o $@
 SOURCES = $(libcodec2_la_SOURCES) $(c2dec_SOURCES) $(c2demo_SOURCES) \
-       $(c2enc_SOURCES) $(c2sim_SOURCES) generate_codebook.c
+       $(c2enc_SOURCES) $(c2sim_SOURCES) generate_codebook.c \
+       genlspdtcb.c
 DIST_SOURCES = $(libcodec2_la_SOURCES) $(c2dec_SOURCES) \
        $(c2demo_SOURCES) $(c2enc_SOURCES) $(c2sim_SOURCES) \
-       generate_codebook.c
+       generate_codebook.c genlspdtcb.c
 library_includeHEADERS_INSTALL = $(INSTALL_HEADER)
 HEADERS = $(library_include_HEADERS)
 ETAGS = etags
@@ -257,6 +261,10 @@ CODEBOOKSRES = \
   $D/lsp3.txt \
   $D/lsp4.txt
 
+CODEBOOKSDT = \
+  $D/lspdt1-4.txt \
+  $D/lspdt5-10.txt
+
 lib_LTLIBRARIES = libcodec2.la
 libcodec2_la_SOURCES = dump.c \
 lpc.c \
@@ -274,7 +282,8 @@ pack.c \
 codebook.c \
 codebookd.c \
 codebookvq.c \
-codebookres.c
+codebookres.c \
+codebookdt.c
 
 libcodec2_la_CFLAGS = $(AM_CFLAGS)
 libcodec2_la_LDFLAGS = $(LIBS)
@@ -419,6 +428,9 @@ c2sim$(EXEEXT): $(c2sim_OBJECTS) $(c2sim_DEPENDENCIES)
 generate_codebook$(EXEEXT): $(generate_codebook_OBJECTS) $(generate_codebook_DEPENDENCIES) 
        @rm -f generate_codebook$(EXEEXT)
        $(LINK) $(generate_codebook_LDFLAGS) $(generate_codebook_OBJECTS) $(generate_codebook_LDADD) $(LIBS)
+genlspdtcb$(EXEEXT): $(genlspdtcb_OBJECTS) $(genlspdtcb_DEPENDENCIES) 
+       @rm -f genlspdtcb$(EXEEXT)
+       $(LINK) $(genlspdtcb_LDFLAGS) $(genlspdtcb_OBJECTS) $(genlspdtcb_LDADD) $(LIBS)
 
 mostlyclean-compile:
        -rm -f *.$(OBJEXT)
@@ -431,8 +443,10 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/c2enc.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/c2sim.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/generate_codebook.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/genlspdtcb.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-codebook.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-codebookd.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-codebookdt.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-codebookres.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-codebookvq.Plo@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-codec2.Plo@am__quote@
@@ -589,6 +603,13 @@ libcodec2_la-codebookres.lo: codebookres.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -c -o libcodec2_la-codebookres.lo `test -f 'codebookres.c' || echo '$(srcdir)/'`codebookres.c
 
+libcodec2_la-codebookdt.lo: codebookdt.c
+@am__fastdepCC_TRUE@   if $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -MT libcodec2_la-codebookdt.lo -MD -MP -MF "$(DEPDIR)/libcodec2_la-codebookdt.Tpo" -c -o libcodec2_la-codebookdt.lo `test -f 'codebookdt.c' || echo '$(srcdir)/'`codebookdt.c; \
+@am__fastdepCC_TRUE@   then mv -f "$(DEPDIR)/libcodec2_la-codebookdt.Tpo" "$(DEPDIR)/libcodec2_la-codebookdt.Plo"; else rm -f "$(DEPDIR)/libcodec2_la-codebookdt.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='codebookdt.c' object='libcodec2_la-codebookdt.lo' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libcodec2_la_CFLAGS) $(CFLAGS) -c -o libcodec2_la-codebookdt.lo `test -f 'codebookdt.c' || echo '$(srcdir)/'`codebookdt.c
+
 mostlyclean-libtool:
        -rm -f *.lo
 
@@ -797,6 +818,9 @@ codebookd.$(OBJEXT): codebookd.c
 codebookvq.$(OBJEXT): codebookvq.c
 codebookres.$(OBJEXT): codebookres.c
 
+$(CODEBOOKSDT): genlspdtcb
+       ./genlspdtcb
+
 codebook.lo: codebook.c
 
 codebook.c: generate_codebook $(CODEBOOKS)
@@ -811,8 +835,11 @@ codebookvq.c: generate_codebook $(CODEBOOKSVQ)
 codebookres.c: generate_codebook $(CODEBOOKSRES)
        ./generate_codebook lsp_cbres $(CODEBOOKSRES) > codebookres.c
 
+codebookdt.c: generate_codebook $(CODEBOOKSDT)
+       ./generate_codebook lsp_cbdt $(CODEBOOKSDT) > codebookdt.c
+
 clean-local:
-       -rm -f codebook.c codebookd.c codebookdvq.c codebookres.c
+       -rm -f codebook.c codebookd.c codebookdvq.c codebookres.c codebookdt.c
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
 .NOEXPORT:
index 13bf92abbdb39ae731d2215968cd8274ecfad10f..59ce66c739c44879356d3a51ec572b31c0832548 100644 (file)
@@ -100,7 +100,7 @@ int main(int argc, char *argv[])
   float sum_snr;
 
   int lpc_model, order = LPC_ORD;
-  int lsp, lspd, lspvq, lsp_quantiser, lspres;
+  int lsp, lspd, lspvq, lsp_quantiser, lspres, lspdt;
   float ak[LPC_MAX];
   COMP  Sw_[FFT_ENC];
   COMP  Ew[FFT_ENC]; 
@@ -120,6 +120,7 @@ int main(int argc, char *argv[])
   int decimate;
   float lsps[LPC_ORD];
   float prev_lsps[LPC_ORD];
+  float lsps__prev[LPC_ORD];
   float e, prev_e;
   float ak_interp[LPC_MAX];
 
@@ -144,6 +145,7 @@ int main(int argc, char *argv[])
   }
   for(i=0; i<LPC_ORD; i++) {
       prev_lsps[i] = i*PI/(LPC_ORD+1);
+      lsps__prev[i] = i*PI/(LPC_ORD+1);
   }
   e = prev_e = 1;
   hpf_states[0] = hpf_states[1] = 0.0;
@@ -159,6 +161,7 @@ int main(int argc, char *argv[])
      "\t[--lspd]\n"
      "\t[--lspvq]\n"
      "\t[--lspres]\n"
+     "\t[--lspdt]\n"
      "\t[--phase0]\n"
      "\t[--postfilter]\n"
      "\t[--hand_voicing]\n"
@@ -220,6 +223,7 @@ int main(int argc, char *argv[])
       assert(order == LPC_ORD);
 
   lspres = switch_present("--lspres",argc,argv);
+  lspdt = switch_present("--lspdt",argc,argv);
 
   phase0 = switch_present("--phase0",argc,argv);
   if (phase0) {
@@ -296,7 +300,7 @@ int main(int argc, char *argv[])
        
        /* determine voicing */
 
-       snr = est_voicing_mbe(&model, Sw, W, Sw_, Ew, prev_Wo);
+       snr = est_voicing_mbe(&model, Sw, Sw_, Ew, W, prev_Wo);
 #ifdef DUMP
        dump_Sw_(Sw_);
        dump_Ew(Ew);
@@ -333,7 +337,7 @@ int main(int argc, char *argv[])
        }
 
        if (lspd) {
-           locate_lsps_jnd_steps(lsps, LPC_ORD);
+           //locate_lsps_jnd_steps(lsps, LPC_ORD);
            lspd_quantise(lsps, lsps_, LPC_ORD);
            locate_lsps_jnd_steps(lsps_, LPC_ORD);
            lsp_to_lpc(lsps_, ak, LPC_ORD);
@@ -348,10 +352,30 @@ int main(int argc, char *argv[])
 
        if (lspres) {
            lspres_quantise(lsps, lsps_, LPC_ORD);
+           locate_lsps_jnd_steps(lsps_, LPC_ORD);
+           lsp_to_lpc(lsps_, ak, LPC_ORD);
+       }
+
+       if (lspdt) {
+#define ALTERNATE              
+#ifdef ALTERNATE
+           if (frames%2) {
+               //locate_lsps_jnd_steps(lsps, LPC_ORD);
+               //lspvq_quantise(lsps, lsps_, LPC_ORD);
+               for(i=0; i<LPC_ORD; i++) {
+                   lsps_[i] = lsps[i];
+                   lsps__prev[i] = lsps_[i];
+               }
+
+           }
+           else {
+               lspdt_quantise(lsps, lsps_, lsps__prev);
+           }
+#else
+           lspdt_quantise(lsps, lsps_, lsps__prev);
+#endif
            //locate_lsps_jnd_steps(lsps_, LPC_ORD);
-           bw_expand_lsps(lsps_, LPC_ORD);
            lsp_to_lpc(lsps_, ak, LPC_ORD);
-           //printf("%f %f %f %f\n", lsps[0], lsps_[0], lsps[1], lsps_[1]);
        }
 
 #ifdef DUMP
index b5e1bf8abc6753403aae8436d57c6d13ac93375c..64e19fe6a23e5cc15125f78edc7ecd91e84d68ed 100644 (file)
@@ -86,5 +86,6 @@ extern const struct lsp_codebook lsp_cb[];
 extern const struct lsp_codebook lsp_cbd[];
 extern const struct lsp_codebook lsp_cbvq[];
 extern const struct lsp_codebook lsp_cbres[];
+extern const struct lsp_codebook lsp_cbdt[];
 
 #endif
diff --git a/codec2-dev/src/genlspdtcb.c b/codec2-dev/src/genlspdtcb.c
new file mode 100644 (file)
index 0000000..efac19c
--- /dev/null
@@ -0,0 +1,90 @@
+/*---------------------------------------------------------------------------*\
+                                                                             
+  FILE........: genlspdtcb.c
+  AUTHOR......: David Rowe                                                     
+  DATE CREATED: 2 Nov 2011
+                                                                             
+  Generates codebooks (quantisation tables) for LSP delta-T VQ.
+                                                                             
+\*---------------------------------------------------------------------------*/
+
+/*
+  All rights reserved.
+
+  This program is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License version 2.1, as
+  published by the Free Software Foundation.  This program is
+  distributed in the hope that it will be useful, but WITHOUT ANY
+  WARRANTY; without even the implied warranty of MERCHANTABILITY or
+  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
+  License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with this program; if not, see <http://www.gnu.org/licenses/>.
+
+*/
+
+#define MAX_ROWS 10
+
+float lsp1to4[] = {
+    -25,0,25,
+    -25,0,25,
+    -50,0,50,
+    -50,0,50
+};
+
+float lsp5to10[] = {
+    -50,0,50,
+    -50,0,50,
+    -50,0,50,
+    -50,0,50,
+    -50,0,50,
+    -50,0,50
+};
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+void create_codebook_text_file(char filename[], float lsp[], 
+                              int rows, int cols);
+
+int main(void) {
+    create_codebook_text_file("codebook/lspdt1-4.txt",  lsp1to4,  4, 3);
+    create_codebook_text_file("codebook/lspdt5-10.txt", lsp5to10, 6, 3); 
+    return 0;
+}
+
+void create_codebook_text_file(char filename[], float lsp[], 
+                              int rows, int cols) 
+{
+    FILE *f;
+    int   i, digits[MAX_ROWS]; 
+
+    f = fopen(filename, "wt");
+    if (f == NULL) {
+       printf("Can't open codebook text file %s\n", filename);
+       exit(0);
+    }
+
+    for(i=0; i<rows; i++)
+       digits[i] = 0;
+
+    fprintf(f, "%d %d\n", rows, (int)pow(cols, rows));
+
+    do {
+       for(i=0; i<rows; i++)
+           fprintf(f, "%4.0f ", lsp[cols*i + digits[i]]);
+       fprintf(f, "\n");
+       digits[0]++;
+       for(i=0; i<rows-1; i++)
+           if (digits[i]== cols) {
+               digits[i] = 0;
+               digits[i+1]++;
+           }
+    } while (digits[rows-1] != cols);
+       
+    fclose(f);
+}
index 0b5445e07794bee7c57923ec08aaa2ceec17c9b6..f7b7c03e971bc1e700a60e0ba161bc207f6d8cbe 100644 (file)
@@ -135,14 +135,10 @@ void lspd_quantise(
     float lsp__hz[LPC_MAX];
     float dlsp[LPC_MAX];
     float dlsp_[LPC_MAX];
-    float lsplog[LPC_MAX];
-    float lsplog_[LPC_MAX];
     float wt[LPC_MAX];
     const float *cb;
     float se;
     int   indexes[LPC_MAX];
-    float diff1,diff2;
-    float centre_hz, bw_hz, bwe;
 
     for(i=0; i<LPC_ORD; i++) {
        wt[i] = 1.0;
@@ -289,7 +285,7 @@ void lspres_quantise(float lsps[], float lsps_[], int order)
     const float *cb;
     float se = 0.0;
     int   index;
-    float centre_hz, bw_hz, lsp_hz, bwe;
+    float centre_hz, bw_hz, lsp_hz;
 
     for(i=0; i<LPC_ORD; i++) {
        wt[i] = 1.0;
@@ -338,6 +334,59 @@ void lspres_quantise(float lsps[], float lsps_[], int order)
 
 }
 
+/*---------------------------------------------------------------------------*\
+                                                                             
+  lspdt_quantise
+
+  LSP difference in time quantiser.
+
+\*---------------------------------------------------------------------------*/
+
+void lspdt_quantise(float lsps[], float lsps_[], float lsps__prev[]) 
+{
+    int   i,k,m;
+    float wt[LPC_ORD];
+    float lsps_dt[LPC_ORD];
+    const float *cb;
+    float se = 0.0;
+    int   index;
+
+    for(i=0; i<LPC_ORD; i++) {
+       wt[i] = 1.0;
+       lsps_[i] = lsps[i];
+    }
+
+    for(i=0; i<LPC_ORD; i++) {
+       lsps_dt[i] = (4000/PI)*(lsps[i] - lsps__prev[i]);
+       //      printf("%f ", lsps_dt[i]);
+    }
+    printf("\n");
+    k = lsp_cbdt[0].k;
+    m = lsp_cbdt[0].m;
+    cb = lsp_cbdt[0].cb;
+    //printf("k %d  m %d  cb[0]\n", k, m, cb[0]);
+    index = quantise(cb, lsps_dt, wt, k, m, &se);
+    //printf("index %d\n", index);
+
+    for(i=0; i<4; i++) {
+       lsps_[i] = lsps__prev[i] + (PI/4000.0)*cb[index*k + i];
+       lsps__prev[i] = lsps_[i];
+    }
+
+    k = lsp_cbdt[1].k;
+    m = lsp_cbdt[1].m;
+    cb = lsp_cbdt[1].cb;
+    index = quantise(cb, &lsps_dt[4], wt, k, m, &se);
+    printf("index %d\n", index);
+    for(i=4; i<10; i++) {
+       printf("%f ", cb[index*k + i - 4]);
+       lsps_[i] = lsps__prev[i] + (PI/4000.0)*cb[index*k + i - 4];
+       lsps__prev[i] = lsps_[i];
+    }
+
+    printf("\n");
+}
+
 void check_lsp_order(float lsp[], int lpc_order)
 {
     int   i;
@@ -391,10 +440,6 @@ float lpc_model_amplitudes(
   float lsp_hz[LPC_MAX];
   float lsp_[LPC_MAX];
   int   roots;                  /* number of LSP roots found */
-  int   index;
-  float se;
-  int   k,m;
-  const float * cb;
   float wt[LPC_MAX];
 
   for(i=0; i<M; i++)
index e66e843fa33a6aa47ee15ab323676e04b79564c8..65c358976f2584cfd2412b599dae2472e79c2461 100644 (file)
@@ -47,6 +47,7 @@ void decode_lsps(float lsp[], int indexes[], int order);
 void lspd_quantise(float lsp[], float lsp_[], int order);
 void lspvq_quantise(float lsp[], float lsp_[], int order); 
 void lspres_quantise(float lsp[], float lsp_[], int order);
+void lspdt_quantise(float lsps[], float lsps_[], float lsps__prev[]);
 
 int encode_energy(float e);
 float decode_energy(int index);