added MBE pitch post processor to nlp.c, still debugging
authordrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 8 Sep 2009 04:43:03 +0000 (04:43 +0000)
committerdrowe67 <drowe67@01035d8c-6547-0410-b346-abe4f91aad63>
Tue, 8 Sep 2009 04:43:03 +0000 (04:43 +0000)
git-svn-id: https://svn.code.sf.net/p/freetel/code@44 01035d8c-6547-0410-b346-abe4f91aad63

codec2/unittest/Makefile
codec2/unittest/tnlp.c

index 0dd6d98b9227cc50ee6bff9af2e4ed5bb60c85e7..9ef936a43545ef6ad9d1c4d6e4df2b5f3dbd2348 100644 (file)
@@ -1,6 +1,6 @@
 CFLAGS = -I. -I../src -I../speex -Wall -g -DFLOATING_POINT -DVAR_ARRAYS
 
-all: genres lsptest genlsp extract vqtrain
+all: genres lsptest genlsp extract vqtrain tnlp
 
 genres: genres.o ../src/lpc.o
        gcc $(CFLAGS) -o genres genres.o ../src/lpc.o -lm
@@ -9,6 +9,9 @@ LSP_TEST_OBJ = lsptest.o ../src/lpc.o ../speex/lsp.o sd.o ../src/four1.o \
                ../speex/quant_lsp.o ../speex/bits.o ../speex/lsp_tables_nb.o \
                ../speex/high_lsp_tables.c
 
+TNLP_OBJ     = tnlp.o ../src/nlp.o ../src/four1.o ../src/initenc.o ../src/dump.o \
+               ../src/globals.o  ../src/refine.o
+
 lsptest: $(LSP_TEST_OBJ)
        gcc $(CFLAGS) -o lsptest $(LSP_TEST_OBJ) -lm
 
@@ -21,5 +24,8 @@ extract: extract.o
 vqtrain: vqtrain.o
        gcc $(CFLAGS) -o vqtrain vqtrain.o -lm
 
+tnlp: $(TNLP_OBJ)
+       gcc $(CFLAGS) -o tnlp $(TNLP_OBJ) -lm
+
 %.o : %.c
        $(CC) -c $(CFLAGS) $< -o $@
index cf582f9c8df2fc24097a4dc8d2ae16d575d1ad49..d4fedbbe1c24ddef3cd4b66065a3194b0e3d05f1 100644 (file)
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
 
-#define N 160          /* frame size */
+#define N 80           /* frame size */
 #define M 320          /* pitch analysis window size */
 #define PITCH_MIN 20
-#define PITCH_MAX 133
+#define PITCH_MAX 160
 #define TNLP
 
-int frames;
-
 #include <stdlib.h>
 #include <stdio.h>
 #include <math.h>
-#include "four1.c"
-#include "nlpl.c"
-
-/*---------------------------------------------------------------------------*\
+#include "nlp.h"
+#include "dump.h"
 
-                                    FUNCTIONS
+int   frames;
 
+/*---------------------------------------------------------------------------*\
+                                                                             
+ 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.                                                                       
+                                                                             
 \*---------------------------------------------------------------------------*/
 
-void swap(buf,n)
-short buf[];   /* array of speech samples */
-int n;         /* number of speech samples */
+int switch_present(sw,argc,argv)
+  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;
-  short a,b;
-  
-  for(i=0; i<n; i++) {
-    a = buf[i] & 0xff;
-    b = (buf[i] >> 8) & 0xff;
-    buf[i] = (a << 8) | b;
-  }
-}
+  int i;       /* loop variable */
 
-void short_to_float(b,s,n)
-short b[];     /* buffer of short speech samples */
-float s[];     /* buffer of float speech samples */
-int n;         /* number of speech samples */
-{
-  int i;
-  
-  for(i=0; i<n; i++)
-    s[i] = (float)b[i];
+  for(i=1; i<argc; i++)
+    if (!strcmp(sw,argv[i]))
+      return(i);
+
+  return 0;
 }
 
 /*---------------------------------------------------------------------------*\
@@ -77,18 +70,21 @@ int n;              /* number of speech samples */
 
 \*---------------------------------------------------------------------------*/
 
-void main(argc,argv)
+int main(argc,argv)
 int argc;
 char *argv[];
 {
-  FILE *fin,*fout;
-  short buf[N];
-  float Sn[N];
-  float pitch;
-  int i;
-  int pbin;
-
-  if (argc == 3) {
+    FILE *fin,*fout;
+    short buf[N];
+    float pitch;
+    int   i; 
+    int   dump;
+    
+    if (argc < 3) {
+       printf("\nusage: tnlp InputRawSpeechFile OutputPitchTextFile "
+              "[--dump DumpFile]\n");
+        exit(0);
+    }
 
     /* Input file */
 
@@ -104,28 +100,40 @@ char *argv[];
       exit(1);
     }
 
+    dump = switch_present("--dump",argc,argv);
+    if (dump) 
+      dump_on(argv[dump+1]);
+
+    init_encoder();
+    make_window(NW);
+
+    /* align with current version of sinenc.c, fix this later */
+
     frames = 0;
-    pbin = 102;
     while(fread(buf,sizeof(short),N,fin)) {
       frames++;
-      short_to_float(buf,Sn,N);
-      nlpl(Sn,N,M,N-NTAP/2,PITCH_MIN,PITCH_MAX,&pitch,&pbin);
 
-      /* Compensate for delay in C version compared to Matlab */
+      /* Update input speech buffers */
 
-      if (frames > 2)
-       fprintf(fout,"%f\n",pitch);
+      for(i=0; i<M-N; i++)
+        Sn[i] = Sn[i+N];
+      for(i=0; i<N; i++)
+        Sn[i+M-N] = buf[i];
+      dft_speech();
+      dump_Sn(Sn); dump_Sw(Sw); 
 
-      printf("frame: %d  pitch: %f\n",frames,pitch);
+      nlp(Sn,N,M,N-NLP_NTAP/2,PITCH_MIN,PITCH_MAX,&pitch,Sw);
+
+      fprintf(fout,"%f\n",pitch);
 
+      printf("frame: %d  pitch: %f\n",frames,pitch);
     }
-    fprintf(fout,"0\n0\n");
 
     fclose(fin);
     fclose(fout);
-  }
-  else
-    printf("\nusage: tnlp InputFile OutputFile\n");
+    if (dump) dump_off();
+
+    return 0;
 }