first pass at 1400 bit/s simulation
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 7 Nov 2011 01:05:24 +0000 (01:05 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Mon, 7 Nov 2011 01:05:24 +0000 (01:05 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@301 01035d8c-6547-0410-b346-abe4f91aad63

codec2-dev/src/c2sim.c
codec2-dev/src/quantise.c
codec2-dev/src/quantise.h
codec2-dev/unittest/Makefile.am
codec2-dev/unittest/Makefile.in
codec2-dev/unittest/genlsp.c

index 90d984346c6acdd5bc69fa6d5934206f54596077..36155c950eb74d04bebe8d1a465c8f64bf4a4652 100644 (file)
@@ -6,7 +6,7 @@
 
   Codec2 simulation.  Combines encoder and decoder and allows
   switching in and out various algorithms and quantisation
-  steps. Primary program for algorithm developments.
+  steps. Used for algorithm development.
 
 \*---------------------------------------------------------------------------*/
 
 #include "postfilter.h"
 #include "interp.h"
 
-/*---------------------------------------------------------------------------*\
-                                                                             
- switch_present()                                                            
-                                                                             
- Searches the command line arguments for a "switch".  If the switch is       
- found, returns the command line argument where it ws found, else returns    
- NULL.                                                                       
-                                                                             
-\*---------------------------------------------------------------------------*/
-
-int switch_present(sw,argc,argv)
-register char sw[];     /* switch in string form */
-register int argc;      /* number of command line arguments */
-register char *argv[];  /* array of command line arguments in string form */
-{
-  register int i;       /* loop variable */
-
-  for(i=1; i<argc; i++)
-    if (!strcmp(sw,argv[i]))
-      return(i);
-
-  return 0;
-}
-
+int switch_present(char sw[],int argc, char *argv[]);
 void synth_one_frame(short buf[], MODEL *model, float Sn_[], float Pn[]);
 
 /*---------------------------------------------------------------------------*\
@@ -79,466 +56,538 @@ void synth_one_frame(short buf[], MODEL *model, float Sn_[], float Pn[]);
 
 int main(int argc, char *argv[])
 {
-  FILE *fout;          /* output speech file                    */
-  FILE *fin;           /* input speech file                     */
-  short buf[N];                /* input/output buffer                   */
-  float Sn[M];         /* float input speech samples            */
-  COMP  Sw[FFT_ENC];   /* DFT of Sn[]                           */
-  float w[M];          /* time domain hamming window            */
-  COMP  W[FFT_ENC];    /* DFT of w[]                            */
-  MODEL model;
-  float Pn[2*N];       /* trapezoidal synthesis window          */
-  float Sn_[2*N];      /* synthesised speech */
-  int   i;             /* loop variable                         */
-  int   frames;
-  float prev_Wo, prev__Wo;
-  float pitch;
-  int   voiced1 = 0;
-
-  char  out_file[MAX_STR];
-  int   arg;
-  float snr;
-  float sum_snr;
-
-  int lpc_model, order = LPC_ORD;
-  int lsp, lspd, lspvq, lsp_quantiser, lspres, lspdt, lspdt_mode;
-  float ak[LPC_MAX];
-  COMP  Sw_[FFT_ENC];
-  COMP  Ew[FFT_ENC]; 
+    FILE *fout;                /* output speech file                    */
+    FILE *fin;         /* input speech file                     */
+    short buf[N];              /* input/output buffer                   */
+    float Sn[M];               /* float input speech samples            */
+    COMP  Sw[FFT_ENC]; /* DFT of Sn[]                           */
+    float w[M];                /* time domain hamming window            */
+    COMP  W[FFT_ENC];  /* DFT of w[]                            */
+    MODEL model;
+    float Pn[2*N];     /* trapezoidal synthesis window          */
+    float Sn_[2*N];    /* synthesised speech */
+    int   i;           /* loop variable                         */
+    int   frames;
+    float prev_Wo, prev__Wo;
+    float pitch;
+    int   voiced1 = 0;
+
+    char  out_file[MAX_STR];
+    int   arg;
+    float snr;
+    float sum_snr;
+
+    int lpc_model, order = LPC_ORD;
+    int lsp, lspd, lspvq, lsp_quantiser, lspres, lspdt, lspdt_mode, dt;
+    float ak[LPC_MAX];
+    COMP  Sw_[FFT_ENC];
+    COMP  Ew[FFT_ENC]; 
  
-  int dump;
+    int dump;
   
-  int phase0;
-  float ex_phase[MAX_AMP+1];
-
-  int   postfilt;
-  float bg_est;
-
-  int   hand_voicing;
-  FILE *fvoicing = 0;
-
-  MODEL prev_model, interp_model;
-  int decimate;
-  float lsps[LPC_ORD];
-  float prev_lsps[LPC_ORD];
-  float lsps__prev[LPC_ORD];
-  float lsps__prev2[LPC_ORD];
-  float e, prev_e;
-  float ak_interp[LPC_MAX];
-
-  void *nlp_states;
-  float hpf_states[2];
-
-  for(i=0; i<M; i++)
-      Sn[i] = 1.0;
-  for(i=0; i<2*N; i++)
-      Sn_[i] = 0;
-
-  prev_Wo = TWO_PI/P_MAX;
-
-  prev_model.Wo = TWO_PI/P_MIN;
-  prev_model.L = floor(PI/prev_model.Wo);
-  for(i=1; i<=prev_model.L; i++) {
-      prev_model.A[i] = 0.0;
-      prev_model.phi[i] = 0.0;
-  }
-  for(i=1; i<=MAX_AMP; i++) {
-      ex_phase[i] = 0.0;
-  }
-  for(i=0; i<LPC_ORD; i++) {
-      prev_lsps[i] = i*PI/(LPC_ORD+1);
-      lsps__prev[i] = lsps__prev2[i] = i*PI/(LPC_ORD+1);
-  }
-  e = prev_e = 1;
-  hpf_states[0] = hpf_states[1] = 0.0;
-
-  nlp_states = nlp_create();
-
-  if (argc < 2) {
-    fprintf(stderr, "\nCodec2 - 2400 bit/s speech codec - Simulation Program\n"
-     "\thttp://rowetel.com/codec2.html\n\n"
-     "usage: %s InputFile [-o OutputFile]\n"
-     "\t[--lpc Order]\n"
-     "\t[--lsp]\n"
-     "\t[--lspd]\n"
-     "\t[--lspvq]\n"
-     "\t[--lspres]\n"
-     "\t[--lspdt]\n"
-     "\t[--lspdt_mode all|high|low]\n"
-     "\t[--phase0]\n"
-     "\t[--postfilter]\n"
-     "\t[--hand_voicing]\n"
-     "\t[--dec]\n"
-     "\t[--dump DumpFilePrefix]\n", argv[0]);
-    exit(1);
-  }
-
-  /* Interpret command line arguments -------------------------------------*/
-
-  /* Input file */
-
-  if ((fin = fopen(argv[1],"rb")) == NULL) {
-    fprintf(stderr, "Error opening input speech file: %s: %s.\n",
-     argv[1], strerror(errno));
-    exit(1);
-  }
-
-  /* Output file */
-
-  if ((arg = switch_present("-o",argc,argv))) {
-    if ((fout = fopen(argv[arg+1],"wb")) == NULL) {
-      fprintf(stderr, "Error opening output speech file: %s: %s.\n",
-       argv[arg+1], strerror(errno));
-      exit(1);
+    int phase0;
+    float ex_phase[MAX_AMP+1];
+
+    int   postfilt;
+    float bg_est;
+
+    int   hand_voicing;
+    FILE *fvoicing = 0;
+
+    MODEL prev_model, interp_model;
+    int decimate;
+    float lsps[LPC_ORD];
+    float prev_lsps[LPC_ORD];
+    float lsps__prev[LPC_ORD];
+    float lsps__prev2[LPC_ORD];
+    float e, prev_e;
+    float ak_interp[LPC_MAX];
+
+    void *nlp_states;
+    float hpf_states[2];
+
+    for(i=0; i<M; i++)
+       Sn[i] = 1.0;
+    for(i=0; i<2*N; i++)
+       Sn_[i] = 0;
+
+    prev_Wo = prev__Wo = TWO_PI/P_MAX;
+
+    prev_model.Wo = TWO_PI/P_MIN;
+    prev_model.L = floor(PI/prev_model.Wo);
+    for(i=1; i<=prev_model.L; i++) {
+       prev_model.A[i] = 0.0;
+       prev_model.phi[i] = 0.0;
     }
-    strcpy(out_file,argv[arg+1]);
-  }
-  else
-    fout = NULL;
-
-  lpc_model = 0;
-  if ((arg = switch_present("--lpc",argc,argv))) {
-      lpc_model = 1;
-      order = atoi(argv[arg+1]);
-      if ((order < 4) || (order > 20)) {
-        fprintf(stderr, "Error in lpc order: %d\n", order);
-        exit(1);
-      }          
-  }
-
-  dump = switch_present("--dump",argc,argv);
+    for(i=1; i<=MAX_AMP; i++) {
+       ex_phase[i] = 0.0;
+    }
+    for(i=0; i<LPC_ORD; i++) {
+       prev_lsps[i] = i*PI/(LPC_ORD+1);
+       lsps__prev[i] = lsps__prev2[i] = i*PI/(LPC_ORD+1);
+    }
+    e = prev_e = 1;
+    hpf_states[0] = hpf_states[1] = 0.0;
+
+    nlp_states = nlp_create();
+
+    if (argc < 2) {
+       fprintf(stderr, "\nCodec2 - 2400 bit/s speech codec - Simulation Program\n"
+               "\thttp://rowetel.com/codec2.html\n\n"
+               "usage: %s InputFile [-o OutputFile]\n"
+               "\t[--lpc Order]\n"
+               "\t[--lsp]\n"
+               "\t[--lspd]\n"
+               "\t[--lspvq]\n"
+               "\t[--lspres]\n"
+               "\t[--lspdt]\n"
+               "\t[--lspdt_mode all|high|low]\n"
+               "\t[--phase0]\n"
+               "\t[--postfilter]\n"
+               "\t[--hand_voicing]\n"
+               "\t[--dec]\n"
+               "\t[--dt]\n"
+               "\t[--1400]\n"
+               "\t[--dump DumpFilePrefix]\n", argv[0]);
+       exit(1);
+    }
+
+    /* Interpret command line arguments -------------------------------------*/
+
+    /* Input file */
+
+    if ((fin = fopen(argv[1],"rb")) == NULL) {
+       fprintf(stderr, "Error opening input speech file: %s: %s.\n",
+               argv[1], strerror(errno));
+       exit(1);
+    }
+
+    /* Output file */
+
+    if ((arg = switch_present("-o",argc,argv))) {
+       if ((fout = fopen(argv[arg+1],"wb")) == NULL) {
+           fprintf(stderr, "Error opening output speech file: %s: %s.\n",
+                   argv[arg+1], strerror(errno));
+           exit(1);
+       }
+       strcpy(out_file,argv[arg+1]);
+    }
+    else
+       fout = NULL;
+
+    lpc_model = 0;
+    if ((arg = switch_present("--lpc",argc,argv))) {
+       lpc_model = 1;
+       order = atoi(argv[arg+1]);
+       if ((order < 4) || (order > 20)) {
+           fprintf(stderr, "Error in lpc order: %d\n", order);
+           exit(1);
+       }         
+    }
+
+    dump = switch_present("--dump",argc,argv);
 #ifdef DUMP
-  if (dump) 
-      dump_on(argv[dump+1]);
+    if (dump) 
+       dump_on(argv[dump+1]);
 #endif
 
-  lsp = switch_present("--lsp",argc,argv);
-  lsp_quantiser = 0;
-  if (lsp)
-      assert(order == LPC_ORD);
-
-  lspd = switch_present("--lspd",argc,argv);
-  if (lspd)
-      assert(order == LPC_ORD);
-
-  lspvq = switch_present("--lspvq",argc,argv);
-  if (lspvq)
-      assert(order == LPC_ORD);
-
-  lspres = switch_present("--lspres",argc,argv);
-
-  lspdt = switch_present("--lspdt",argc,argv);
-  if ( (arg = switch_present("--lspdt_mode",argc,argv))) {
-      if (strcmp(argv[arg+1],"all") == 0)
-         lspdt_mode = LSPDT_ALL;
-      else if (strcmp(argv[arg+1],"low") == 0)
-         lspdt_mode = LSPDT_LOW;
-      else if (strcmp(argv[arg+1],"high") == 0)
-         lspdt_mode = LSPDT_HIGH;
-      else {
-         fprintf(stderr, "Error in lspdt_mode: %d\n", lspdt_mode);
-         exit(1);
-      }
-  }
-  else
-     lspdt_mode = LSPDT_ALL;
-
-  phase0 = switch_present("--phase0",argc,argv);
-  if (phase0) {
-      ex_phase[0] = 0;
-  }
-
-  hand_voicing = switch_present("--hand_voicing",argc,argv);
-  if (hand_voicing) {
-      fvoicing = fopen(argv[hand_voicing+1],"rt");
-      assert(fvoicing != NULL);
-  }
-
-  bg_est = 0.0;
-  postfilt = switch_present("--postfilter",argc,argv);
-
-  decimate = switch_present("--dec",argc,argv);
-
-  /* Initialise ------------------------------------------------------------*/
-
-  make_analysis_window(w,W);
-  make_synthesis_window(Pn);
-  quantise_init();
-
-  /* Main loop ------------------------------------------------------------*/
-
-  frames = 0;
-  sum_snr = 0;
-  while(fread(buf,sizeof(short),N,fin)) {
-    frames++;
-    //printf("frame: %d", frames);
-
-    /* Read input speech */
-
-    for(i=0; i<M-N; i++)
-      Sn[i] = Sn[i+N];
-    for(i=0; i<N; i++)
-       Sn[i+M-N] = buf[i];
+    lsp = switch_present("--lsp",argc,argv);
+    lsp_quantiser = 0;
+    if (lsp)
+       assert(order == LPC_ORD);
+
+    lspd = switch_present("--lspd",argc,argv);
+    if (lspd)
+       assert(order == LPC_ORD);
+
+    lspvq = switch_present("--lspvq",argc,argv);
+    if (lspvq)
+       assert(order == LPC_ORD);
+
+    lspres = switch_present("--lspres",argc,argv);
+
+    lspdt = switch_present("--lspdt",argc,argv);
+    if ( (arg = switch_present("--lspdt_mode",argc,argv))) {
+       if (strcmp(argv[arg+1],"all") == 0)
+           lspdt_mode = LSPDT_ALL;
+       else if (strcmp(argv[arg+1],"low") == 0)
+           lspdt_mode = LSPDT_LOW;
+       else if (strcmp(argv[arg+1],"high") == 0)
+           lspdt_mode = LSPDT_HIGH;
+       else {
+           fprintf(stderr, "Error in lspdt_mode: %d\n", lspdt_mode);
+           exit(1);
+       }
+    }
+    else
+       lspdt_mode = LSPDT_ALL;
+
+    phase0 = switch_present("--phase0",argc,argv);
+    if (phase0) {
+       ex_phase[0] = 0;
+    }
+
+    hand_voicing = switch_present("--hand_voicing",argc,argv);
+    if (hand_voicing) {
+       fvoicing = fopen(argv[hand_voicing+1],"rt");
+       assert(fvoicing != NULL);
+    }
+
+    bg_est = 0.0;
+    postfilt = switch_present("--postfilter",argc,argv);
+
+    decimate = switch_present("--dec",argc,argv);
+
+    dt = switch_present("--dt",argc,argv);
+
+    if (switch_present("--1400",argc,argv)) {
+       lpc_model = 1; order = 10;
+       lspdt = 1; lspdt_mode = LSPDT_LOW;
+       phase0 = 1;
+       postfilt = 1;
+       decimate = 1;
+       dt = 1;
+    }
+
+    /* Initialise ------------------------------------------------------------*/
+
+    make_analysis_window(w,W);
+    make_synthesis_window(Pn);
+    quantise_init();
+
+    /* Main Loop ------------------------------------------------------------*/
+
+    frames = 0;
+    sum_snr = 0;
+    while(fread(buf,sizeof(short),N,fin)) {
+       frames++;
+       //printf("frame: %d", frames);
+
+       /* Read input speech */
+
+       for(i=0; i<M-N; i++)
+           Sn[i] = Sn[i+N];
+       for(i=0; i<N; i++)
+           Sn[i+M-N] = buf[i];
  
-    /* Estimate pitch */
+       /* Estimate pitch */
 
-    nlp(nlp_states,Sn,N,M,P_MIN,P_MAX,&pitch,Sw,&prev_Wo);
-    model.Wo = TWO_PI/pitch;
+       nlp(nlp_states,Sn,N,M,P_MIN,P_MAX,&pitch,Sw,&prev_Wo);
+       model.Wo = TWO_PI/pitch;
 
-    /* estimate model parameters */
+       /* estimate model parameters --------------------------------------*/
 
-    dft_speech(Sw, Sn, w); 
-    two_stage_pitch_refinement(&model, Sw);
-    estimate_amplitudes(&model, Sw, W);
+       dft_speech(Sw, Sn, w); 
+       two_stage_pitch_refinement(&model, Sw);
+       estimate_amplitudes(&model, Sw, W);
 #ifdef DUMP 
-    dump_Sn(Sn); dump_Sw(Sw); dump_model(&model);
+       dump_Sn(Sn); dump_Sw(Sw); dump_model(&model);
 #endif
 
-    /* optional zero-phase modelling */
+       /* optional zero-phase modelling ----------------------------------*/
 
-    if (phase0) {
-       float Wn[M];                    /* windowed speech samples */
-       float Rk[LPC_MAX+1];            /* autocorrelation coeffs  */
-       int ret;
+       if (phase0) {
+           float Wn[M];                        /* windowed speech samples */
+           float Rk[LPC_MAX+1];                /* autocorrelation coeffs  */
+           int ret;
 
 #ifdef DUMP
-       dump_phase(&model.phi[0], model.L);
+           dump_phase(&model.phi[0], model.L);
 #endif
 
-       /* find aks here, these are overwritten if LPC modelling is enabled */
+           /* find aks here, these are overwritten if LPC modelling is enabled */
 
-       for(i=0; i<M; i++)
-           Wn[i] = Sn[i]*w[i];
-       autocorrelate(Wn,Rk,M,order);
-       levinson_durbin(Rk,ak,order);
+           for(i=0; i<M; i++)
+               Wn[i] = Sn[i]*w[i];
+           autocorrelate(Wn,Rk,M,order);
+           levinson_durbin(Rk,ak,order);
 
 #ifdef DUMP
-       dump_ak(ak, LPC_ORD);
+           dump_ak(ak, LPC_ORD);
 #endif
        
-       /* determine voicing */
+           /* determine voicing */
 
-       snr = est_voicing_mbe(&model, Sw, W, Sw_, Ew, prev_Wo);
+           snr = est_voicing_mbe(&model, Sw, W, Sw_, Ew, prev_Wo);
 #ifdef DUMP
-       dump_Sw_(Sw_);
-       dump_Ew(Ew);
-       dump_snr(snr);
+           dump_Sw_(Sw_);
+           dump_Ew(Ew);
+           dump_snr(snr);
 #endif
 
-       /* just to make sure we are not cheating - kill all phases */
+           /* just to make sure we are not cheating - kill all phases */
 
-       for(i=0; i<MAX_AMP; i++)
-           model.phi[i] = 0;
+           for(i=0; i<MAX_AMP; i++)
+               model.phi[i] = 0;
        
-       if (hand_voicing) {
-           ret = fscanf(fvoicing,"%d\n",&model.voiced);
+           if (hand_voicing) {
+               ret = fscanf(fvoicing,"%d\n",&model.voiced);
+           }
        }
-    }
 
-    /* optional LPC model amplitudes */
+       /* optional LPC model amplitudes and LSP quantisation -----------------*/
 
-    if (lpc_model) {
-       int   lsp_indexes[LPC_MAX];
-       float lsps_[LPC_ORD];
+       if (lpc_model) {
+           int   lsp_indexes[LPC_MAX];
+           float lsps_[LPC_ORD];
 
-       e = speech_to_uq_lsps(lsps, ak, Sn, w, order);
+           e = speech_to_uq_lsps(lsps, ak, Sn, w, order);
 
 #ifdef DUMP
            dump_lsp(lsps);
 #endif
 
-       if (lsp) {
-           encode_lsps(lsp_indexes, lsps, LPC_ORD);
-           decode_lsps(lsps_, lsp_indexes, LPC_ORD);
-           bw_expand_lsps(lsps_, LPC_ORD);
-           lsp_to_lpc(lsps_, ak, LPC_ORD);
-       }
-
-       if (lspd) {
-           //locate_lsps_jnd_steps(lsps, LPC_ORD);
-           lspd_quantise(lsps, lsps_, LPC_ORD);
-           bw_expand_lsps(lsps_, LPC_ORD);
-           lsp_to_lpc(lsps_, ak, LPC_ORD);
-       }
-
-       if (lspvq) {
-           locate_lsps_jnd_steps(lsps, LPC_ORD);
-           lspvq_quantise(lsps, lsps_, LPC_ORD);
-           locate_lsps_jnd_steps(lsps_, LPC_ORD);
-           lsp_to_lpc(lsps_, ak, LPC_ORD);
-       }
+           /* various LSP quantisation schemes */
 
-       if (lspres) {
-           lspres_quantise(lsps, lsps_, LPC_ORD);
-           locate_lsps_jnd_steps(lsps_, LPC_ORD);
-           lsp_to_lpc(lsps_, ak, LPC_ORD);
-       }
-       
-       /* we need lsp__prev[] for lspdt.  If no other
-          LSP quantisation is used we use original LSPs 
-          rather than quantised version. */
-
-       if (!lsp && !lspd && !lspvq && !lspres)
-           for(i=0; i<LPC_ORD; i++)
-               lsps_[i] = lsps[i];
-
-       /* Odd frames are generated by quantising the difference
-          between the previous frames LSPs and this frames */
-       
-       if (lspdt && !decimate) {
-           if (frames%2) {
-               lspdt_quantise(lsps, lsps_, lsps__prev, lspdt_mode);
+           if (lsp) {
+               encode_lsps(lsp_indexes, lsps, LPC_ORD);
+               decode_lsps(lsps_, lsp_indexes, LPC_ORD);
                bw_expand_lsps(lsps_, LPC_ORD);
                lsp_to_lpc(lsps_, ak, LPC_ORD);
            }
-           for(i=0; i<LPC_ORD; i++)
-               lsps__prev[i] = lsps_[i];               
-       }
 
-       /* 
-          When decimation is enabled we only send LSPs to the decoder
-          on odd frames.  In the Delta-time LSPs case we encode every
-          second odd frame (i.e. every 3rd frame) by quantising the
-          difference between the 1st frames LSPs and this frames:
-
-          10ms, frame 1: send "full" LSP frame
-          20ms, frame 2: discard (interpolate at decoder)
-          30ms, frame 3: send LSPs differences between frame 3 and frame 1
-          40ms, frame 4: discard (interpolate at decoder)
-       */
-
-       if (lspdt && decimate) {
-           if ((frames%4) == 3) {
-               lspdt_quantise(lsps, lsps_, lsps__prev2, lspdt_mode);
+           if (lspd) {
+               //locate_lsps_jnd_steps(lsps, LPC_ORD);
+               lspd_quantise(lsps, lsps_, LPC_ORD);
                bw_expand_lsps(lsps_, LPC_ORD);
                lsp_to_lpc(lsps_, ak, LPC_ORD);
            }
-           for(i=0; i<LPC_ORD; i++) {
-               lsps__prev2[i] = lsps__prev[i];
-               lsps__prev[i] = lsps_[i];
+
+           if (lspvq) {
+               locate_lsps_jnd_steps(lsps, LPC_ORD);
+               lspvq_quantise(lsps, lsps_, LPC_ORD);
+               locate_lsps_jnd_steps(lsps_, LPC_ORD);
+               lsp_to_lpc(lsps_, ak, LPC_ORD);
            }
-       }
 
+           if (lspres) {
+               lspres_quantise(lsps, lsps_, LPC_ORD);
+               locate_lsps_jnd_steps(lsps_, LPC_ORD);
+               lsp_to_lpc(lsps_, ak, LPC_ORD);
+           }
+       
+           /* we need lsp__prev[] for lspdt.  If no other
+              LSP quantisation is used we use original LSPs 
+              as there is no quantised version available. */
+
+           if (!lsp && !lspd && !lspvq && !lspres)
+               for(i=0; i<LPC_ORD; i++)
+                   lsps_[i] = lsps[i];
+
+           /* Odd frames are generated by quantising the difference
+              between the previous frames LSPs and this frames */
+       
+           if (lspdt && !decimate) {
+               if (frames%2) {
+                   lspdt_quantise(lsps, lsps_, lsps__prev, lspdt_mode);
+                   bw_expand_lsps(lsps_, LPC_ORD);
+                   lsp_to_lpc(lsps_, ak, LPC_ORD);
+               }
+               for(i=0; i<LPC_ORD; i++)
+                   lsps__prev[i] = lsps_[i];           
+           }
+
+           /* 
+              When decimation is enabled we only send LSPs to the
+              decoder on odd frames.  In the Delta-time LSPs case we
+              encode every second odd frame (i.e. every 3rd frame out
+              of 4) by quantising the difference between the 1st
+              frames LSPs and the 3rd frames:
+
+              10ms, frame 1: send "full" LSP frame
+              20ms, frame 2: discard (interpolate at decoder)
+              30ms, frame 3: send LSPs differences between frame 3 and frame 1
+              40ms, frame 4: discard (interpolate at decoder)
+           */
+
+           if (lspdt && decimate) {
+               if ((frames%4) == 3) {
+                   lspdt_quantise(lsps, lsps_, lsps__prev2, lspdt_mode);
+                   bw_expand_lsps(lsps_, LPC_ORD);
+                   lsp_to_lpc(lsps_, ak, LPC_ORD);
+               }
+               for(i=0; i<LPC_ORD; i++) {
+                   lsps__prev2[i] = lsps__prev[i];
+                   lsps__prev[i] = lsps_[i];
+               }
+           }
+       
 #ifdef DUMP
            dump_lsp(lsps_);
 #endif
-       e = decode_energy(encode_energy(e));
-       model.Wo = decode_Wo(encode_Wo(model.Wo));
+       
+           /* We quantise energy and Wo when doing any form of LPC
+              modelling.  This sounds transparent and saves an extra 
+              command line switch to enable/disable. */
+
+           e = decode_energy(encode_energy(e));
 
-       aks_to_M2(ak, order, &model, e, &snr, 1); 
+           if (!decimate && dt && (frames % 2)) {
+               model.Wo = decode_Wo_dt(encode_Wo_dt(model.Wo, prev_Wo),prev_Wo);
+               model.L  = PI/model.Wo;
+           }
+
+           if (decimate && dt && ((frames % 4) == 3)) {
+               model.Wo = decode_Wo_dt(encode_Wo_dt(model.Wo, prev__Wo),prev__Wo);
+               model.L  = PI/model.Wo;
+               //printf("dWo");
+           }
+          
+           if (!decimate && !dt)
+               model.Wo = decode_Wo(encode_Wo(model.Wo));
+
+           aks_to_M2(ak, order, &model, e, &snr, 1); 
 #ifdef DUMP
-       dump_lpc_snr(snr);
+           dump_lpc_snr(snr);
 #endif
-       apply_lpc_correction(&model);
-       sum_snr += snr;
+           apply_lpc_correction(&model);
+           sum_snr += snr;
 #ifdef DUMP
-        dump_quantised_model(&model);
+           dump_quantised_model(&model);
 #endif
-    }
+       }
 
 #ifdef RESAMPLE
-    /* optional resampling of model amplitudes */
+       /* optional resampling of model amplitudes */
 
-    //printf("frames=%d\n", frames);
-    if (resample) {
-       snr = resample_amp_nl(&model, resample, AresdB_prev);
-       sum_snr += snr;
+       //printf("frames=%d\n", frames);
+       if (resample) {
+           snr = resample_amp_nl(&model, resample, AresdB_prev);
+           sum_snr += snr;
 #ifdef DUMP
-        dump_quantised_model(&model);
+           dump_quantised_model(&model);
 #endif
-    }
+       }
 #endif
 
-    /* option decimation to 20ms rate, which enables interpolation
-       routine to synthesise in between frame */
+       /* option decimation to 20ms rate, which enables interpolation
+          routine to synthesise in between frame ---------------------------*/
   
-    if (decimate) {
-       if (!phase0) {
-           printf("needs --phase0 to resample phase for interpolated Wo\n");
-           exit(0);
-       }
-       if (!lpc_model) {
-           printf("needs --lpc 10 to resample amplitudes\n");
-           exit(0);
-       }
+       if (decimate) {
+           if (!phase0) {
+               printf("needs --phase0 to resample phase for interpolated Wo\n");
+               exit(0);
+           }
+           if (!lpc_model) {
+               printf("needs --lpc 10 to resample amplitudes\n");
+               exit(0);
+           }
 
-       /* 
-          Each 20ms we synthesise two 10ms frames:
+           /* 
+              Each 20ms we synthesise two 10ms frames:
 
-          frame 1: interpolate frame 0 LSPs from frame -1 and frame 1
-                    synthesis frame 0 and frame 1 speech
-          frame 2: discard except for voicing bit
-          frame 3: interpolate frame 2 LSPs from frame 1 and frame 3
-                    synthesis frame 2 and frame 3 speech
-          frame 4: discard except for voicing bit
-       */
+              frame 1: interpolate frame 0 LSPs from frame -1 and frame 1
+                       synthesise frame 0 and frame 1 speech
+              frame 2: discard except for voicing bit
+              frame 3: interpolate frame 2 LSPs from frame 1 and frame 3
+                       synthesise frame 2 and frame 3 speech
+              frame 4: discard except for voicing bit
+           */
 
-       if (frames%2) {
+           if (frames%2) {
+               //printf("interp\n");
 
-           interp_model.voiced = voiced1;
+               /* decode interpolated frame */
 
-           #ifdef LOG_LIN_INTERP
-           interpolate(&interp_model, &prev_model, &model);
-           #else
-           interpolate_lsp(&interp_model, &prev_model, &model,
-                           prev_lsps, prev_e, lsps, e, ak_interp);
-           apply_lpc_correction(&interp_model);
-           #endif
-           
-           if (phase0)
-               phase_synth_zero_order(&interp_model, ak_interp, ex_phase,
-                                      order);  
-           if (postfilt)
-               postfilter(&interp_model, &bg_est);
-           synth_one_frame(buf, &interp_model, Sn_, Pn);
-           if (fout != NULL) fwrite(buf,sizeof(short),N,fout);
+               interp_model.voiced = voiced1;
 
+#ifdef LOG_LIN_INTERP
+               interpolate(&interp_model, &prev_model, &model);
+#else
+               interpolate_lsp(&interp_model, &prev_model, &model,
+                               prev_lsps, prev_e, lsps, e, ak_interp);
+               apply_lpc_correction(&interp_model);
+#endif
+           
+               if (phase0)
+                   phase_synth_zero_order(&interp_model, ak_interp, ex_phase,
+                                          order);      
+               if (postfilt)
+                   postfilter(&interp_model, &bg_est);
+               synth_one_frame(buf, &interp_model, Sn_, Pn);
+               if (fout != NULL) 
+                   fwrite(buf,sizeof(short),N,fout);
+
+               /* decode this frame */
+
+               if (phase0)
+                   phase_synth_zero_order(&model, ak, ex_phase, order);        
+               if (postfilt)
+                   postfilter(&model, &bg_est);
+               synth_one_frame(buf, &model, Sn_, Pn);
+               if (fout != NULL) 
+                   fwrite(buf,sizeof(short),N,fout);
+
+               /* update states for next time */
+
+               prev_model = model;
+               for(i=0; i<LPC_ORD; i++)
+                   prev_lsps[i] = lsps[i];
+               prev_e = e;
+           }
+           else {
+               voiced1 = model.voiced;
+           }
+       }
+       else {
            if (phase0)
                phase_synth_zero_order(&model, ak, ex_phase, order);    
            if (postfilt)
                postfilter(&model, &bg_est);
            synth_one_frame(buf, &model, Sn_, Pn);
            if (fout != NULL) fwrite(buf,sizeof(short),N,fout);
-
-           prev_model = model;
-           for(i=0; i<LPC_ORD; i++)
-               prev_lsps[i] = lsps[i];
-           prev_e = e;
-       }
-       else {
-           voiced1 = model.voiced;
        }
+       prev__Wo = prev_Wo;
+       prev_Wo = TWO_PI/pitch;
     }
-    else {
-       if (phase0)
-           phase_synth_zero_order(&model, ak, ex_phase, order);        
-       if (postfilt)
-           postfilter(&model, &bg_est);
-       synth_one_frame(buf, &model, Sn_, Pn);
-       if (fout != NULL) fwrite(buf,sizeof(short),N,fout);
-    }
-    prev_Wo = TWO_PI/pitch;
-    prev__Wo = Wo;
-  }
-  fclose(fin);
 
-  if (fout != NULL)
-    fclose(fout);
+    /* End Main Loop -----------------------------------------------------*/
 
-  if (lpc_model)
-      printf("SNR av = %5.2f dB\n", sum_snr/frames);
+    fclose(fin);
+
+    if (fout != NULL)
+       fclose(fout);
+
+    if (lpc_model)
+       printf("SNR av = %5.2f dB\n", sum_snr/frames);
 
 #ifdef DUMP
-  if (dump)
-      dump_off();
+    if (dump)
+       dump_off();
 #endif
 
-  if (hand_voicing)
-    fclose(fvoicing);
+    if (hand_voicing)
+       fclose(fvoicing);
+
+    nlp_destroy(nlp_states);
+
+    return 0;
+}
+
+/*---------------------------------------------------------------------------*\
+                                                                             
+ switch_present()                                                            
+                                                                             
+ Searches the command line arguments for a "switch".  If the switch is       
+ found, returns the command line argument where it ws found, else returns    
+ NULL.                                                                       
+                                                                             
+\*---------------------------------------------------------------------------*/
+
+int switch_present(
+                  char sw[],     /* switch in string form            */
+                  int argc,      /* number of command line arguments */
+                  char *argv[]   /* array of command line arguments in string 
+                                    form */
+                  )
+{
+    int i;
 
-  nlp_destroy(nlp_states);
+    for(i=1; i<argc; i++)
+       if (!strcmp(sw,argv[i]))
+           return(i);
 
-  return 0;
+    return 0;
 }
 
 void synth_one_frame(short buf[], MODEL *model, float Sn_[], float Pn[])
index e40a2de83fd504b5dd69bf0ba8965e949c5b56ef..dfa709693cf9d79dbf3e0c4102b76473fc833c90 100644 (file)
@@ -659,6 +659,78 @@ float decode_Wo(int index)
     return Wo;
 }
 
+/*---------------------------------------------------------------------------*\
+                                                       
+  FUNCTION....: encode_Wo_dt()      
+  AUTHOR......: David Rowe                           
+  DATE CREATED: 6 Nov 2011 
+
+  Encodes Wo difference from last frame.
+
+\*---------------------------------------------------------------------------*/
+
+int encode_Wo_dt(float Wo, float prev_Wo)
+{
+    int   index, mask, max_index, min_index;
+    float Wo_min = TWO_PI/P_MAX;
+    float Wo_max = TWO_PI/P_MIN;
+    float norm;
+
+    norm = (Wo - prev_Wo)/(Wo_max - Wo_min);
+    index = floor(WO_LEVELS * norm + 0.5);
+    //printf("ENC index: %d ", index);
+
+    /* hard limit */
+    
+    max_index = (1 << (WO_DT_BITS-1)) - 1;
+    min_index = - (max_index+1);
+    if (index > max_index) index = max_index;
+    if (index < min_index) index = min_index;
+    //printf("max_index: %d  min_index: %d hard index: %d ",
+    //    max_index,  min_index, index);
+
+    /* mask so that only LSB WO_DT_BITS remain, bit WO_DT_BITS is the sign bit */
+
+    mask = ((1 << WO_DT_BITS) - 1);
+    index &= mask;
+    //printf("mask: 0x%x index: 0x%x\n", mask, index);
+
+    return index;
+}
+
+/*---------------------------------------------------------------------------*\
+                                                       
+  FUNCTION....: decode_Wo_dt()      
+  AUTHOR......: David Rowe                           
+  DATE CREATED: 6 Nov 2011 
+
+  Decodes Wo using WO_DT_BITS difference from last frame.
+
+\*---------------------------------------------------------------------------*/
+
+float decode_Wo_dt(int index, float prev_Wo)
+{
+    float Wo_min = TWO_PI/P_MAX;
+    float Wo_max = TWO_PI/P_MIN;
+    float step;
+    float Wo;
+    int   mask;
+
+    /* sign extend index */
+    
+    //printf("DEC index: %d ");
+    if (index & (1 << (WO_DT_BITS-1))) {
+       mask = ~((1 << WO_DT_BITS) - 1);
+       index |= mask;
+    }
+    //printf("DEC mask: 0x%x  index: %d \n", mask, index);
+    
+    step = (Wo_max - Wo_min)/WO_LEVELS;
+    Wo   = prev_Wo + step*(index);
+
+    return Wo;
+}
+
 /*---------------------------------------------------------------------------*\
                                                        
   FUNCTION....: speech_to_uq_lsps()         
index c74d206c58fd9dc0f138bb025210c2c04ff1ca98..88b1ce39d5437cb70e49984b6ad5cbdd2c6134b5 100644 (file)
 #ifndef __QUANTISE__
 #define __QUANTISE__
 
-#define WO_BITS   7
-#define WO_LEVELS (1<<WO_BITS)
-#define E_BITS    5
-#define E_LEVELS  (1<<E_BITS)
-#define E_MIN_DB -10.0
-#define E_MAX_DB  40.0
+#define WO_BITS     7
+#define WO_LEVELS   (1<<WO_BITS)
+#define WO_DT_BITS  3
 
-#define LSPDT_ALL  0
-#define LSPDT_LOW  1
-#define LSPDT_HIGH 2
+#define E_BITS      5
+#define E_LEVELS    (1<<E_BITS)
+#define E_MIN_DB   -10.0
+#define E_MAX_DB    40.0
+
+#define LSPDT_ALL   0
+#define LSPDT_LOW   1
+#define LSPDT_HIGH  2
 
 void quantise_init();
 float lpc_model_amplitudes(float Sn[], float w[], MODEL *model, int order,
@@ -45,6 +47,8 @@ void aks_to_M2(float ak[], int order, MODEL *model, float E, float *snr,
 
 int   encode_Wo(float Wo);
 float decode_Wo(int index);
+int encode_Wo_dt(float Wo, float prev_Wo);
+float decode_Wo_dt(int index, float prev_Wo);
 
 void encode_lsps(int indexes[], float lsp[], int order);
 void decode_lsps(float lsp[], int indexes[], int order);
index c256e8d7040778670b561e9a089cce473074ba1c..39443514f7c0f7b124ce57f466ace856b3df3613 100644 (file)
@@ -22,33 +22,32 @@ vqtrain_SOURCES = vqtrain.c
 vqtrain_LDADD = $(lib_LTLIBRARIES) 
 vqtrain_LDFLAGS = $(LIBS)
 
+CODEBOOKS = ../src/codebook.c ../src/codebookd.c ../src/codebookvq.c ../src/codebookres.c ../src/codebookdt.c
+
 tnlp_SOURCES = tnlp.c ../src/sine.c ../src/nlp.c ../src/fft.c ../src/kiss_fft.c ../src/dump.c
 tnlp_LDADD = $(lib_LTLIBRARIES) 
 tnlp_LDFLAGS = $(LIBS)
 
-tinterp_SOURCES = tinterp.c ../src/sine.c ../src/fft.c ../src/kiss_fft.c ../src/interp.c ../src/lpc.c ../src/lsp.c ../src/quantise.c ../src/codebook.c ../src/codebookd.c ../src/codebookvq.c ../src/codebookres.c ../src/dump.c
+tinterp_SOURCES = tinterp.c ../src/sine.c ../src/fft.c ../src/kiss_fft.c ../src/interp.c ../src/lpc.c ../src/lsp.c ../src/quantise.c $(CODEBOOKS) ../src/dump.c
 tinterp_LDADD = $(lib_LTLIBRARIES) 
 tinterp_LDFLAGS = $(LIBS)
 
-tquant_SOURCES = tquant.c ../src/quantise.c ../src/lpc.c ../src/lsp.c ../src/dump.c ../src/fft.c ../src/kiss_fft.c ../src/codebook.c ../src/codebookd.c ../src/codebookvq.c ../src/codebookres.c 
+tquant_SOURCES = tquant.c ../src/quantise.c ../src/lpc.c ../src/lsp.c ../src/dump.c ../src/fft.c ../src/kiss_fft.c $(CODEBOOKS)
 tquant_LDADD = $(lib_LTLIBRARIES) 
 tquant_LDFLAGS = $(LIBS)
 
 tcodec2_SOURCES = tcodec2.c ../src/quantise.c ../src/lpc.c ../src/lsp.c ../src/dump.c ../src/fft.c ../src/kiss_fft.c \
-../src/codec2.c ../src/sine.c ../src/nlp.c ../src/postfilter.c ../src/phase.c ../src/interp.c \
-../src/codebook.c ../src/codebookd.c ../src/codebookvq.c ../src/codebookres.c ../src/pack.c
+../src/codec2.c ../src/sine.c ../src/nlp.c ../src/postfilter.c ../src/phase.c ../src/interp.c ../src/pack.c $(CODEBOOKS)
 tcodec2_LDADD = $(lib_LTLIBRARIES) 
 tcodec2_LDFLAGS = $(LIBS)
 
 genbands_SOURCES = genbands.c ../src/quantise.c ../src/lpc.c ../src/lsp.c ../src/dump.c ../src/fft.c ../src/kiss_fft.c \
-../src/codec2.c ../src/sine.c ../src/nlp.c ../src/postfilter.c ../src/phase.c ../src/interp.c \
-../src/codebook.c ../src/codebookd.c ../src/codebookvq.c ../src/pack.c
+../src/codec2.c ../src/sine.c ../src/nlp.c ../src/postfilter.c ../src/phase.c ../src/interp.c $(CODEBOOKS) ../src/pack.c
 genbands_LDADD = $(lib_LTLIBRARIES) 
 genbands_LDFLAGS = $(LIBS)
 
 vq_clip_test_SOURCES = vq_clip_test.c ../src/quantise.c ../src/lpc.c ../src/lsp.c ../src/dump.c ../src/fft.c ../src/kiss_fft.c \
-../src/codec2.c ../src/sine.c ../src/nlp.c ../src/postfilter.c ../src/phase.c ../src/interp.c \
-../src/codebook.c ../src/codebookd.c ../src/codebookvq.c ../src/codebookres.c ../src/pack.c
+../src/codec2.c ../src/sine.c ../src/nlp.c ../src/postfilter.c ../src/phase.c ../src/interp.c $(CODEBOOKS) ../src/pack.c
 vq_clip_test_LDADD = $(lib_LTLIBRARIES) 
 vq_clip_test_LDFLAGS = $(LIBS)
 
index f78295003438bbcc836f9ad4239c1addf257d311..7c5fff93236800e5208c36c55d2cfef06a909352 100644 (file)
@@ -59,18 +59,19 @@ genlsp_DEPENDENCIES =
 am_genres_OBJECTS = genres.$(OBJEXT) lpc.$(OBJEXT)
 genres_OBJECTS = $(am_genres_OBJECTS)
 genres_DEPENDENCIES =
+am__objects_1 = codebook.$(OBJEXT) codebookd.$(OBJEXT) \
+       codebookvq.$(OBJEXT) codebookres.$(OBJEXT) \
+       codebookdt.$(OBJEXT)
 am_tcodec2_OBJECTS = tcodec2.$(OBJEXT) quantise.$(OBJEXT) \
        lpc.$(OBJEXT) lsp.$(OBJEXT) dump.$(OBJEXT) fft.$(OBJEXT) \
        kiss_fft.$(OBJEXT) codec2.$(OBJEXT) sine.$(OBJEXT) \
        nlp.$(OBJEXT) postfilter.$(OBJEXT) phase.$(OBJEXT) \
-       interp.$(OBJEXT) codebook.$(OBJEXT) codebookd.$(OBJEXT) \
-       codebookvq.$(OBJEXT) codebookres.$(OBJEXT) pack.$(OBJEXT)
+       interp.$(OBJEXT) pack.$(OBJEXT) $(am__objects_1)
 tcodec2_OBJECTS = $(am_tcodec2_OBJECTS)
 tcodec2_DEPENDENCIES =
 am_tinterp_OBJECTS = tinterp.$(OBJEXT) sine.$(OBJEXT) fft.$(OBJEXT) \
        kiss_fft.$(OBJEXT) interp.$(OBJEXT) lpc.$(OBJEXT) \
-       lsp.$(OBJEXT) quantise.$(OBJEXT) codebook.$(OBJEXT) \
-       codebookd.$(OBJEXT) codebookvq.$(OBJEXT) codebookres.$(OBJEXT) \
+       lsp.$(OBJEXT) quantise.$(OBJEXT) $(am__objects_1) \
        dump.$(OBJEXT)
 tinterp_OBJECTS = $(am_tinterp_OBJECTS)
 tinterp_DEPENDENCIES =
@@ -80,8 +81,7 @@ tnlp_OBJECTS = $(am_tnlp_OBJECTS)
 tnlp_DEPENDENCIES =
 am_tquant_OBJECTS = tquant.$(OBJEXT) quantise.$(OBJEXT) lpc.$(OBJEXT) \
        lsp.$(OBJEXT) dump.$(OBJEXT) fft.$(OBJEXT) kiss_fft.$(OBJEXT) \
-       codebook.$(OBJEXT) codebookd.$(OBJEXT) codebookvq.$(OBJEXT) \
-       codebookres.$(OBJEXT)
+       $(am__objects_1)
 tquant_OBJECTS = $(am_tquant_OBJECTS)
 tquant_DEPENDENCIES =
 am_vqtrain_OBJECTS = vqtrain.$(OBJEXT)
@@ -227,30 +227,28 @@ extract_LDFLAGS = $(LIBS)
 vqtrain_SOURCES = vqtrain.c
 vqtrain_LDADD = $(lib_LTLIBRARIES) 
 vqtrain_LDFLAGS = $(LIBS)
+CODEBOOKS = ../src/codebook.c ../src/codebookd.c ../src/codebookvq.c ../src/codebookres.c ../src/codebookdt.c
 tnlp_SOURCES = tnlp.c ../src/sine.c ../src/nlp.c ../src/fft.c ../src/kiss_fft.c ../src/dump.c
 tnlp_LDADD = $(lib_LTLIBRARIES) 
 tnlp_LDFLAGS = $(LIBS)
-tinterp_SOURCES = tinterp.c ../src/sine.c ../src/fft.c ../src/kiss_fft.c ../src/interp.c ../src/lpc.c ../src/lsp.c ../src/quantise.c ../src/codebook.c ../src/codebookd.c ../src/codebookvq.c ../src/codebookres.c ../src/dump.c
+tinterp_SOURCES = tinterp.c ../src/sine.c ../src/fft.c ../src/kiss_fft.c ../src/interp.c ../src/lpc.c ../src/lsp.c ../src/quantise.c $(CODEBOOKS) ../src/dump.c
 tinterp_LDADD = $(lib_LTLIBRARIES) 
 tinterp_LDFLAGS = $(LIBS)
-tquant_SOURCES = tquant.c ../src/quantise.c ../src/lpc.c ../src/lsp.c ../src/dump.c ../src/fft.c ../src/kiss_fft.c ../src/codebook.c ../src/codebookd.c ../src/codebookvq.c ../src/codebookres.c 
+tquant_SOURCES = tquant.c ../src/quantise.c ../src/lpc.c ../src/lsp.c ../src/dump.c ../src/fft.c ../src/kiss_fft.c $(CODEBOOKS)
 tquant_LDADD = $(lib_LTLIBRARIES) 
 tquant_LDFLAGS = $(LIBS)
 tcodec2_SOURCES = tcodec2.c ../src/quantise.c ../src/lpc.c ../src/lsp.c ../src/dump.c ../src/fft.c ../src/kiss_fft.c \
-../src/codec2.c ../src/sine.c ../src/nlp.c ../src/postfilter.c ../src/phase.c ../src/interp.c \
-../src/codebook.c ../src/codebookd.c ../src/codebookvq.c ../src/codebookres.c ../src/pack.c
+../src/codec2.c ../src/sine.c ../src/nlp.c ../src/postfilter.c ../src/phase.c ../src/interp.c ../src/pack.c $(CODEBOOKS)
 
 tcodec2_LDADD = $(lib_LTLIBRARIES) 
 tcodec2_LDFLAGS = $(LIBS)
 genbands_SOURCES = genbands.c ../src/quantise.c ../src/lpc.c ../src/lsp.c ../src/dump.c ../src/fft.c ../src/kiss_fft.c \
-../src/codec2.c ../src/sine.c ../src/nlp.c ../src/postfilter.c ../src/phase.c ../src/interp.c \
-../src/codebook.c ../src/codebookd.c ../src/codebookvq.c ../src/pack.c
+../src/codec2.c ../src/sine.c ../src/nlp.c ../src/postfilter.c ../src/phase.c ../src/interp.c $(CODEBOOKS) ../src/pack.c
 
 genbands_LDADD = $(lib_LTLIBRARIES) 
 genbands_LDFLAGS = $(LIBS)
 vq_clip_test_SOURCES = vq_clip_test.c ../src/quantise.c ../src/lpc.c ../src/lsp.c ../src/dump.c ../src/fft.c ../src/kiss_fft.c \
-../src/codec2.c ../src/sine.c ../src/nlp.c ../src/postfilter.c ../src/phase.c ../src/interp.c \
-../src/codebook.c ../src/codebookd.c ../src/codebookvq.c ../src/codebookres.c ../src/pack.c
+../src/codec2.c ../src/sine.c ../src/nlp.c ../src/postfilter.c ../src/phase.c ../src/interp.c $(CODEBOOKS) ../src/pack.c
 
 vq_clip_test_LDADD = $(lib_LTLIBRARIES) 
 vq_clip_test_LDFLAGS = $(LIBS)
@@ -348,6 +346,7 @@ distclean-compile:
 
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/codebook.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/codebookd.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/codebookdt.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/codebookres.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/codebookvq.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/codec2.Po@am__quote@
@@ -561,6 +560,20 @@ interp.obj: ../src/interp.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o interp.obj `if test -f '../src/interp.c'; then $(CYGPATH_W) '../src/interp.c'; else $(CYGPATH_W) '$(srcdir)/../src/interp.c'; fi`
 
+pack.o: ../src/pack.c
+@am__fastdepCC_TRUE@   if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT pack.o -MD -MP -MF "$(DEPDIR)/pack.Tpo" -c -o pack.o `test -f '../src/pack.c' || echo '$(srcdir)/'`../src/pack.c; \
+@am__fastdepCC_TRUE@   then mv -f "$(DEPDIR)/pack.Tpo" "$(DEPDIR)/pack.Po"; else rm -f "$(DEPDIR)/pack.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='../src/pack.c' object='pack.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o pack.o `test -f '../src/pack.c' || echo '$(srcdir)/'`../src/pack.c
+
+pack.obj: ../src/pack.c
+@am__fastdepCC_TRUE@   if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT pack.obj -MD -MP -MF "$(DEPDIR)/pack.Tpo" -c -o pack.obj `if test -f '../src/pack.c'; then $(CYGPATH_W) '../src/pack.c'; else $(CYGPATH_W) '$(srcdir)/../src/pack.c'; fi`; \
+@am__fastdepCC_TRUE@   then mv -f "$(DEPDIR)/pack.Tpo" "$(DEPDIR)/pack.Po"; else rm -f "$(DEPDIR)/pack.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='../src/pack.c' object='pack.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@  $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o pack.obj `if test -f '../src/pack.c'; then $(CYGPATH_W) '../src/pack.c'; else $(CYGPATH_W) '$(srcdir)/../src/pack.c'; fi`
+
 codebook.o: ../src/codebook.c
 @am__fastdepCC_TRUE@   if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT codebook.o -MD -MP -MF "$(DEPDIR)/codebook.Tpo" -c -o codebook.o `test -f '../src/codebook.c' || echo '$(srcdir)/'`../src/codebook.c; \
 @am__fastdepCC_TRUE@   then mv -f "$(DEPDIR)/codebook.Tpo" "$(DEPDIR)/codebook.Po"; else rm -f "$(DEPDIR)/codebook.Tpo"; exit 1; fi
@@ -617,19 +630,19 @@ codebookres.obj: ../src/codebookres.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@  $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o codebookres.obj `if test -f '../src/codebookres.c'; then $(CYGPATH_W) '../src/codebookres.c'; else $(CYGPATH_W) '$(srcdir)/../src/codebookres.c'; fi`
 
-pack.o: ../src/pack.c
-@am__fastdepCC_TRUE@   if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT pack.o -MD -MP -MF "$(DEPDIR)/pack.Tpo" -c -o pack.o `test -f '../src/pack.c' || echo '$(srcdir)/'`../src/pack.c; \
-@am__fastdepCC_TRUE@   then mv -f "$(DEPDIR)/pack.Tpo" "$(DEPDIR)/pack.Po"; else rm -f "$(DEPDIR)/pack.Tpo"; exit 1; fi
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='../src/pack.c' object='pack.o' libtool=no @AMDEPBACKSLASH@
+codebookdt.o: ../src/codebookdt.c
+@am__fastdepCC_TRUE@   if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT codebookdt.o -MD -MP -MF "$(DEPDIR)/codebookdt.Tpo" -c -o codebookdt.o `test -f '../src/codebookdt.c' || echo '$(srcdir)/'`../src/codebookdt.c; \
+@am__fastdepCC_TRUE@   then mv -f "$(DEPDIR)/codebookdt.Tpo" "$(DEPDIR)/codebookdt.Po"; else rm -f "$(DEPDIR)/codebookdt.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='../src/codebookdt.c' object='codebookdt.o' libtool=no @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o pack.o `test -f '../src/pack.c' || echo '$(srcdir)/'`../src/pack.c
+@am__fastdepCC_FALSE@  $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o codebookdt.o `test -f '../src/codebookdt.c' || echo '$(srcdir)/'`../src/codebookdt.c
 
-pack.obj: ../src/pack.c
-@am__fastdepCC_TRUE@   if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT pack.obj -MD -MP -MF "$(DEPDIR)/pack.Tpo" -c -o pack.obj `if test -f '../src/pack.c'; then $(CYGPATH_W) '../src/pack.c'; else $(CYGPATH_W) '$(srcdir)/../src/pack.c'; fi`; \
-@am__fastdepCC_TRUE@   then mv -f "$(DEPDIR)/pack.Tpo" "$(DEPDIR)/pack.Po"; else rm -f "$(DEPDIR)/pack.Tpo"; exit 1; fi
-@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='../src/pack.c' object='pack.obj' libtool=no @AMDEPBACKSLASH@
+codebookdt.obj: ../src/codebookdt.c
+@am__fastdepCC_TRUE@   if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT codebookdt.obj -MD -MP -MF "$(DEPDIR)/codebookdt.Tpo" -c -o codebookdt.obj `if test -f '../src/codebookdt.c'; then $(CYGPATH_W) '../src/codebookdt.c'; else $(CYGPATH_W) '$(srcdir)/../src/codebookdt.c'; fi`; \
+@am__fastdepCC_TRUE@   then mv -f "$(DEPDIR)/codebookdt.Tpo" "$(DEPDIR)/codebookdt.Po"; else rm -f "$(DEPDIR)/codebookdt.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@      source='../src/codebookdt.c' object='codebookdt.obj' libtool=no @AMDEPBACKSLASH@
 @AMDEP_TRUE@@am__fastdepCC_FALSE@      DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@  $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o pack.obj `if test -f '../src/pack.c'; then $(CYGPATH_W) '../src/pack.c'; else $(CYGPATH_W) '$(srcdir)/../src/pack.c'; fi`
+@am__fastdepCC_FALSE@  $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o codebookdt.obj `if test -f '../src/codebookdt.c'; then $(CYGPATH_W) '../src/codebookdt.c'; else $(CYGPATH_W) '$(srcdir)/../src/codebookdt.c'; fi`
 
 mostlyclean-libtool:
        -rm -f *.lo
index c284a9e32e7b26da4aeba8d41e3a12c7fcc9f312..f4a3ddc4ce16d4f73849ae58f3aa53a3af539463 100644 (file)
@@ -61,6 +61,7 @@ int main(int argc, char *argv[]) {
     float  Sn[NW];     /* float input speech samples                   */
     float  ak[P+1];    /* LPCs for current frame                       */
     float  lsp[P];     /* LSPs for current frame                       */
+    float  lsp_prev[P];        /* LSPs for previous frame                      */
     float  E;          /* frame energy                                 */
     long   f;          /* number of frames                             */
     long   af;         /* number frames with "active" speech           */
@@ -68,13 +69,13 @@ int main(int argc, char *argv[]) {
     int    i;
     int    roots;
     int    unstables;
-    int    lspd, log;
+    int    lspd, log, lspdt;
     float  diff;
 
     /* Initialise ------------------------------------------------------*/
 
     if (argc < 3) {
-       printf("usage: gentest RawFile LSPTextFile [--lspd] [--log]\n");
+       printf("usage: gentest RawFile LSPTextFile [--lspd] [--log] [--lspdt] \n");
        exit(0);
     }
 
@@ -94,6 +95,7 @@ int main(int argc, char *argv[]) {
 
     lspd = switch_present("--lspd", argc, argv);
     log = switch_present("--log", argc, argv);
+    lspdt = switch_present("--lspdt", argc, argv);
 
     for(i=0; i<NW; i++)
        Sn[i] = 0.0;
@@ -146,11 +148,26 @@ int main(int argc, char *argv[]) {
                    fprintf(flsp,"\n");
                    
                }
-               else {
+               else if (lspdt) {
                    for(i=0; i<P; i++)
-                       fprintf(flsp,"%f ",lsp[i]);
+                       fprintf(flsp,"%f ",lsp[i]-lsp_prev[i]);
                    fprintf(flsp,"\n");
+                   
                }
+               else {
+                   if (log) {
+                       for(i=0; i<P; i++)
+                           fprintf(flsp,"%f ",log10(lsp[i]));
+                       fprintf(flsp,"\n");
+                   }
+                   else {
+                       for(i=0; i<P; i++)
+                           fprintf(flsp,"%f ",lsp[i]);
+                       fprintf(flsp,"\n");
+                   }
+
+               }               
+               memcpy(lsp_prev, lsp, sizeof(lsp));
            }
            else 
                unstables++;