From 58595d5268ca7619422187e25ab68a70dc7d207a Mon Sep 17 00:00:00 2001 From: drowe67 Date: Fri, 1 Apr 2011 00:22:44 +0000 Subject: [PATCH] support for new ampl VQ experiments, aplogies if this breaks anything git-svn-id: https://svn.code.sf.net/p/freetel/code@284 01035d8c-6547-0410-b346-abe4f91aad63 --- codec2/unittest/Makefile.am | 18 +- codec2/unittest/Makefile.in | 94 +++++-- codec2/unittest/dvdongle2.c | 3 +- codec2/unittest/genbands.c | 229 +++++++++++++++++ codec2/unittest/tcodec2.c | 6 +- codec2/unittest/vq_clip_test.c | 450 +++++++++++++++++++++++++++++++++ codec2/unittest/vqtrain_clip.c | 309 ++++++++++++++++++++++ 7 files changed, 1082 insertions(+), 27 deletions(-) create mode 100644 codec2/unittest/genbands.c create mode 100644 codec2/unittest/vq_clip_test.c create mode 100644 codec2/unittest/vqtrain_clip.c diff --git a/codec2/unittest/Makefile.am b/codec2/unittest/Makefile.am index 817e6a78..310436d2 100644 --- a/codec2/unittest/Makefile.am +++ b/codec2/unittest/Makefile.am @@ -3,7 +3,7 @@ AUTOMAKE_OPTS = gnu NAME = libcodec2 AM_CPPFLAGS = $(AM_CFLAGS) -bin_PROGRAMS = genres genlsp extract vqtrain tnlp tinterp tquant tcodec2 +bin_PROGRAMS = genres genlsp extract vqtrain vqtrain_clip tnlp tinterp tquant tcodec2 genbands vq_clip_test genres_SOURCES = genres.c ../src/lpc.c @@ -22,6 +22,10 @@ vqtrain_SOURCES = vqtrain.c vqtrain_LDADD = $(lib_LTLIBRARIES) vqtrain_LDFLAGS = $(LIBS) +vqtrain_clip_SOURCES = vqtrain_clip.c +vqtrain_clip_LDADD = $(lib_LTLIBRARIES) +vqtrain_clip_LDFLAGS = $(LIBS) + 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) @@ -40,3 +44,15 @@ tcodec2_SOURCES = tcodec2.c ../src/quantise.c ../src/lpc.c ../src/lsp.c ../src/d 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/codebookdvq.c ../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/codebookdvq.c ../src/pack.c +vq_clip_test_LDADD = $(lib_LTLIBRARIES) +vq_clip_test_LDFLAGS = $(LIBS) + diff --git a/codec2/unittest/Makefile.in b/codec2/unittest/Makefile.in index 21d19fea..810b2ccd 100644 --- a/codec2/unittest/Makefile.in +++ b/codec2/unittest/Makefile.in @@ -37,8 +37,9 @@ POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ bin_PROGRAMS = genres$(EXEEXT) genlsp$(EXEEXT) extract$(EXEEXT) \ - vqtrain$(EXEEXT) tnlp$(EXEEXT) tinterp$(EXEEXT) \ - tquant$(EXEEXT) tcodec2$(EXEEXT) + vqtrain$(EXEEXT) vqtrain_clip$(EXEEXT) tnlp$(EXEEXT) \ + tinterp$(EXEEXT) tquant$(EXEEXT) tcodec2$(EXEEXT) \ + genbands$(EXEEXT) vq_clip_test$(EXEEXT) subdir = unittest DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 @@ -53,6 +54,14 @@ PROGRAMS = $(bin_PROGRAMS) am_extract_OBJECTS = extract.$(OBJEXT) extract_OBJECTS = $(am_extract_OBJECTS) extract_DEPENDENCIES = +am_genbands_OBJECTS = genbands.$(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) \ + codebookdvq.$(OBJEXT) pack.$(OBJEXT) +genbands_OBJECTS = $(am_genbands_OBJECTS) +genbands_DEPENDENCIES = am_genlsp_OBJECTS = genlsp.$(OBJEXT) lpc.$(OBJEXT) lsp.$(OBJEXT) genlsp_OBJECTS = $(am_genlsp_OBJECTS) genlsp_DEPENDENCIES = @@ -82,9 +91,20 @@ am_tquant_OBJECTS = tquant.$(OBJEXT) quantise.$(OBJEXT) lpc.$(OBJEXT) \ codebook.$(OBJEXT) codebookd.$(OBJEXT) codebookdvq.$(OBJEXT) tquant_OBJECTS = $(am_tquant_OBJECTS) tquant_DEPENDENCIES = +am_vq_clip_test_OBJECTS = vq_clip_test.$(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) \ + codebookdvq.$(OBJEXT) pack.$(OBJEXT) +vq_clip_test_OBJECTS = $(am_vq_clip_test_OBJECTS) +vq_clip_test_DEPENDENCIES = am_vqtrain_OBJECTS = vqtrain.$(OBJEXT) vqtrain_OBJECTS = $(am_vqtrain_OBJECTS) vqtrain_DEPENDENCIES = +am_vqtrain_clip_OBJECTS = vqtrain_clip.$(OBJEXT) +vqtrain_clip_OBJECTS = $(am_vqtrain_clip_OBJECTS) +vqtrain_clip_DEPENDENCIES = DEFAULT_INCLUDES = -I. -I$(srcdir) depcomp = $(SHELL) $(top_srcdir)/depcomp am__depfiles_maybe = depfiles @@ -96,12 +116,15 @@ LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \ CCLD = $(CC) LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ $(AM_LDFLAGS) $(LDFLAGS) -o $@ -SOURCES = $(extract_SOURCES) $(genlsp_SOURCES) $(genres_SOURCES) \ - $(tcodec2_SOURCES) $(tinterp_SOURCES) $(tnlp_SOURCES) \ - $(tquant_SOURCES) $(vqtrain_SOURCES) -DIST_SOURCES = $(extract_SOURCES) $(genlsp_SOURCES) $(genres_SOURCES) \ - $(tcodec2_SOURCES) $(tinterp_SOURCES) $(tnlp_SOURCES) \ - $(tquant_SOURCES) $(vqtrain_SOURCES) +SOURCES = $(extract_SOURCES) $(genbands_SOURCES) $(genlsp_SOURCES) \ + $(genres_SOURCES) $(tcodec2_SOURCES) $(tinterp_SOURCES) \ + $(tnlp_SOURCES) $(tquant_SOURCES) $(vq_clip_test_SOURCES) \ + $(vqtrain_SOURCES) $(vqtrain_clip_SOURCES) +DIST_SOURCES = $(extract_SOURCES) $(genbands_SOURCES) \ + $(genlsp_SOURCES) $(genres_SOURCES) $(tcodec2_SOURCES) \ + $(tinterp_SOURCES) $(tnlp_SOURCES) $(tquant_SOURCES) \ + $(vq_clip_test_SOURCES) $(vqtrain_SOURCES) \ + $(vqtrain_clip_SOURCES) ETAGS = etags CTAGS = ctags DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) @@ -225,6 +248,9 @@ extract_LDFLAGS = $(LIBS) vqtrain_SOURCES = vqtrain.c vqtrain_LDADD = $(lib_LTLIBRARIES) vqtrain_LDFLAGS = $(LIBS) +vqtrain_clip_SOURCES = vqtrain_clip.c +vqtrain_clip_LDADD = $(lib_LTLIBRARIES) +vqtrain_clip_LDFLAGS = $(LIBS) 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) @@ -240,6 +266,18 @@ tcodec2_SOURCES = tcodec2.c ../src/quantise.c ../src/lpc.c ../src/lsp.c ../src/d 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/codebookdvq.c ../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/codebookdvq.c ../src/pack.c + +vq_clip_test_LDADD = $(lib_LTLIBRARIES) +vq_clip_test_LDFLAGS = $(LIBS) all: all-am .SUFFIXES: @@ -304,6 +342,9 @@ clean-binPROGRAMS: extract$(EXEEXT): $(extract_OBJECTS) $(extract_DEPENDENCIES) @rm -f extract$(EXEEXT) $(LINK) $(extract_LDFLAGS) $(extract_OBJECTS) $(extract_LDADD) $(LIBS) +genbands$(EXEEXT): $(genbands_OBJECTS) $(genbands_DEPENDENCIES) + @rm -f genbands$(EXEEXT) + $(LINK) $(genbands_LDFLAGS) $(genbands_OBJECTS) $(genbands_LDADD) $(LIBS) genlsp$(EXEEXT): $(genlsp_OBJECTS) $(genlsp_DEPENDENCIES) @rm -f genlsp$(EXEEXT) $(LINK) $(genlsp_LDFLAGS) $(genlsp_OBJECTS) $(genlsp_LDADD) $(LIBS) @@ -322,9 +363,15 @@ tnlp$(EXEEXT): $(tnlp_OBJECTS) $(tnlp_DEPENDENCIES) tquant$(EXEEXT): $(tquant_OBJECTS) $(tquant_DEPENDENCIES) @rm -f tquant$(EXEEXT) $(LINK) $(tquant_LDFLAGS) $(tquant_OBJECTS) $(tquant_LDADD) $(LIBS) +vq_clip_test$(EXEEXT): $(vq_clip_test_OBJECTS) $(vq_clip_test_DEPENDENCIES) + @rm -f vq_clip_test$(EXEEXT) + $(LINK) $(vq_clip_test_LDFLAGS) $(vq_clip_test_OBJECTS) $(vq_clip_test_LDADD) $(LIBS) vqtrain$(EXEEXT): $(vqtrain_OBJECTS) $(vqtrain_DEPENDENCIES) @rm -f vqtrain$(EXEEXT) $(LINK) $(vqtrain_LDFLAGS) $(vqtrain_OBJECTS) $(vqtrain_LDADD) $(LIBS) +vqtrain_clip$(EXEEXT): $(vqtrain_clip_OBJECTS) $(vqtrain_clip_DEPENDENCIES) + @rm -f vqtrain_clip$(EXEEXT) + $(LINK) $(vqtrain_clip_LDFLAGS) $(vqtrain_clip_OBJECTS) $(vqtrain_clip_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) @@ -339,6 +386,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dump.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/extract.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/fft.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/genbands.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/genlsp.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/genres.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/interp.Po@am__quote@ @@ -355,7 +403,9 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tinterp.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tnlp.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/tquant.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vq_clip_test.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vqtrain.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vqtrain_clip.Po@am__quote@ .c.o: @am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \ @@ -378,6 +428,20 @@ distclean-compile: @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@ @am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $< +quantise.o: ../src/quantise.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT quantise.o -MD -MP -MF "$(DEPDIR)/quantise.Tpo" -c -o quantise.o `test -f '../src/quantise.c' || echo '$(srcdir)/'`../src/quantise.c; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/quantise.Tpo" "$(DEPDIR)/quantise.Po"; else rm -f "$(DEPDIR)/quantise.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='../src/quantise.c' object='quantise.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 quantise.o `test -f '../src/quantise.c' || echo '$(srcdir)/'`../src/quantise.c + +quantise.obj: ../src/quantise.c +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT quantise.obj -MD -MP -MF "$(DEPDIR)/quantise.Tpo" -c -o quantise.obj `if test -f '../src/quantise.c'; then $(CYGPATH_W) '../src/quantise.c'; else $(CYGPATH_W) '$(srcdir)/../src/quantise.c'; fi`; \ +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/quantise.Tpo" "$(DEPDIR)/quantise.Po"; else rm -f "$(DEPDIR)/quantise.Tpo"; exit 1; fi +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='../src/quantise.c' object='quantise.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 quantise.obj `if test -f '../src/quantise.c'; then $(CYGPATH_W) '../src/quantise.c'; else $(CYGPATH_W) '$(srcdir)/../src/quantise.c'; fi` + lpc.o: ../src/lpc.c @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT lpc.o -MD -MP -MF "$(DEPDIR)/lpc.Tpo" -c -o lpc.o `test -f '../src/lpc.c' || echo '$(srcdir)/'`../src/lpc.c; \ @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/lpc.Tpo" "$(DEPDIR)/lpc.Po"; else rm -f "$(DEPDIR)/lpc.Tpo"; exit 1; fi @@ -406,20 +470,6 @@ lsp.obj: ../src/lsp.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 lsp.obj `if test -f '../src/lsp.c'; then $(CYGPATH_W) '../src/lsp.c'; else $(CYGPATH_W) '$(srcdir)/../src/lsp.c'; fi` -quantise.o: ../src/quantise.c -@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT quantise.o -MD -MP -MF "$(DEPDIR)/quantise.Tpo" -c -o quantise.o `test -f '../src/quantise.c' || echo '$(srcdir)/'`../src/quantise.c; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/quantise.Tpo" "$(DEPDIR)/quantise.Po"; else rm -f "$(DEPDIR)/quantise.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='../src/quantise.c' object='quantise.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 quantise.o `test -f '../src/quantise.c' || echo '$(srcdir)/'`../src/quantise.c - -quantise.obj: ../src/quantise.c -@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT quantise.obj -MD -MP -MF "$(DEPDIR)/quantise.Tpo" -c -o quantise.obj `if test -f '../src/quantise.c'; then $(CYGPATH_W) '../src/quantise.c'; else $(CYGPATH_W) '$(srcdir)/../src/quantise.c'; fi`; \ -@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/quantise.Tpo" "$(DEPDIR)/quantise.Po"; else rm -f "$(DEPDIR)/quantise.Tpo"; exit 1; fi -@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='../src/quantise.c' object='quantise.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 quantise.obj `if test -f '../src/quantise.c'; then $(CYGPATH_W) '../src/quantise.c'; else $(CYGPATH_W) '$(srcdir)/../src/quantise.c'; fi` - dump.o: ../src/dump.c @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT dump.o -MD -MP -MF "$(DEPDIR)/dump.Tpo" -c -o dump.o `test -f '../src/dump.c' || echo '$(srcdir)/'`../src/dump.c; \ @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/dump.Tpo" "$(DEPDIR)/dump.Po"; else rm -f "$(DEPDIR)/dump.Tpo"; exit 1; fi diff --git a/codec2/unittest/dvdongle2.c b/codec2/unittest/dvdongle2.c index 792b3fc1..f39ef53a 100644 --- a/codec2/unittest/dvdongle2.c +++ b/codec2/unittest/dvdongle2.c @@ -288,7 +288,7 @@ int main(int argc, char **argv) { c_in.power = 0x0; c_in.control1 = 0x0; -#define RATE2000 + //#define RATE2000 #ifdef RATE2000 c_in.rate[0] = 0x0028; /* 2000 bit/s, no FEC */ c_in.rate[1] = 0x0000; @@ -297,6 +297,7 @@ int main(int argc, char **argv) { c_in.rate[4] = 0x6248; #endif +#define RATE3600_1200 #ifdef RATE3600_1200 c_in.rate[0] = 0x5048; /* 3600 bit/s, 1200 bit/s FEC */ c_in.rate[1] = 0x0001; diff --git a/codec2/unittest/genbands.c b/codec2/unittest/genbands.c new file mode 100644 index 00000000..e57655e8 --- /dev/null +++ b/codec2/unittest/genbands.c @@ -0,0 +1,229 @@ +/*--------------------------------------------------------------------------*\ + + FILE........: genbands.c + AUTHOR......: David Rowe + DATE CREATED: 22 March 2011 + + This program generates a text file of resampled band data from + an input speech file. Note: choose a better name and reword + this some time. + +\*--------------------------------------------------------------------------*/ + +/* + Copyright (C) 2009 David Rowe + + 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, 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 . +*/ + +#define P 10 /* LP order */ +#define LSP_DELTA1 0.01 /* grid spacing for LSP root searches */ +#define NW 279 /* frame size in samples */ +#define N 80 /* frame to frame shift */ +#define THRESH 40.0 /* threshold energy/sample for frame inclusion */ + +#include +#include +#include +#include +#include "defines.h" +#include "comp.h" +#include "codec2_internal.h" +#include "codec2.h" +#include "interp.h" + +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; /* loop variable */ + + for(i=1; i THRESH) { + af++; + printf("Active Frame: %ld\n", af); + + resample_amp_fixed(&model, w, A, wres, Ares, + AresdB_prev, AresdB, deltat); + for(i=0; i THRESH) { + af++; + printf("Active Frame: %ld unstables: %d\n",af, unstables); + + find_aks(Sn, ak, NW, P, &Eres); + roots = lpc_to_lsp(ak, P , lsp, 5, LSP_DELTA1); + if (roots == P) { + if (lspd) { + fprintf(flsp,"%f ",lsp[0]); + for(i=1; i. +*/ + +#define THRESH 40.0 /* threshold energy/sample for frame inclusion */ + +#include +#include +#include +#include +#include "defines.h" +#include "comp.h" +#include "codec2_internal.h" +#include "codec2.h" +#include "interp.h" +#include "lpc.h" + +long quantise_clip(float cb[], float vec[], int k, int m, float clip, float *se, + int *less_than_clip); + +float sample_log_amp_quad_nl( + float w[], /* frequency points */ + float A[], /* for these amplitude samples */ + int np, /* number of frequency points */ + float w_sample /* frequency of new 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; /* loop variable */ + + for(i=1; ik = (int)get_float(file, name, &cursor, line, sizeof(line)); + b->m = (int)get_float(file, name ,&cursor, line, sizeof(line)); + size = b->k * b->m; + + b->cb = (float *)malloc(size * sizeof(float)); + + for ( i = 0; i < size; i++ ) + b->cb[i] = get_float(file, name, &cursor, line, sizeof(line)); + + return b; +} + +/*---------------------------------------------------------------------------*\ + + FUNCTION....: synthesise_one_frame_orig_phase() + AUTHOR......: David Rowe + DATE CREATED: 23/8/2010 + + Synthesise 80 speech samples (10ms) from model parameters. + +\*---------------------------------------------------------------------------*/ + +void synthesise_one_frame_orig_phase(CODEC2 *c2, short speech[], MODEL *model) +{ + int i; + + postfilter(model, &c2->bg_est); + synthesise(c2->Sn_, model, c2->Pn, 1); + + for(i=0; iSn_[i] > 32767.0) + speech[i] = 32767; + else if (c2->Sn_[i] < -32767.0) + speech[i] = -32767; + else + speech[i] = c2->Sn_[i]; + } +} + +#define PHASE_POINTS 50 + +int main(int argc, char *argv[]) { + FILE *fraw, *fvq, *fout; + short buf[N]; + void *c2; + CODEC2 *c3; + MODEL model; + float w[MAX_AMP], A[MAX_AMP]; + float wres[MAX_AMP], Ares[MAX_AMP], AresdB[MAX_AMP], AresdB_q[MAX_AMP], AresdB_prev[MAX_AMP]; + float deltat[MAX_AMP]; + float sam, E; + long f, af; + int i, j, err_less_than_clip_low, err_less_than_clip_high, k, m, besti_low, besti_high; + float av_err_low, av_err_high; + float clip; + struct codebook *cblow = malloc(sizeof(struct codebook)); + struct codebook *cbhigh = malloc(sizeof(struct codebook)); + float sum_av_err_low, sum_av_err_high; + int sum_err_less_than_clip_low,sum_err_less_than_clip_high; + float signal, noise, snr, new_A, sum_snr; + float wph[PHASE_POINTS], Pph[PHASE_POINTS], R[LPC_ORD+1], aks[LPC_ORD+1]; + int phase_model; + + if (argc < 5) { + printf("usage: vq_clip_test RawFileIn LowVQFile HighVQFile clip [RawFileOut] --phase\n"); + exit(0); + } + + f = af = 0; + + c2 = codec2_create(); + c3 = (CODEC2*)c2; + + for(i=0; i= 6) { + fout = fopen(argv[5],"wb"); + if (fout == NULL) { + printf("Error opening output .raw file: %s",argv[4]); + exit(1); + } + } + else + fout = NULL; + + if (switch_present("--phase",argc, argv)) { + phase_model = 1; + } + else + phase_model = 0; + + dump_on("test"); + + sum_av_err_low = sum_av_err_high = 0; + sum_err_less_than_clip_low = sum_err_less_than_clip_high = 0; + sum_snr = 0; + + while(fread(buf, sizeof(short), N, fraw) == N) { + analyse_one_frame(c3, &model, buf); + + E = 0.0; + for(i=0; icb, deltat, cblow->k, cblow->m, clip, + &av_err_low, + &err_less_than_clip_low); + printf("LOW av_err: %3.2f err_less_than_clip: %d besti: %d\n\n", + av_err_low, err_less_than_clip_low, besti_low ); + + besti_high = quantise_clip(cbhigh->cb, &deltat[cblow->k], cbhigh->k, cbhigh->m, clip, + &av_err_high, + &err_less_than_clip_high); + printf("HIGH av_err: %3.2f err_less_than_clip: %d besti: %d\n\n", + av_err_high, err_less_than_clip_high, besti_high ); + + /* recover Ares vector */ + + for(i=0; ik; i++) { + AresdB_q[i] = AresdB_prev[i] + cblow->cb[besti_low*cblow->k+i]; + Ares[i] = pow(10.0, AresdB_q[i]/20.0); + //printf("%d %f 2%f\n", i, AresdB[i], AresdB_q[i]); + } + for(i=0,j=cblow->k; ik; i++,j++) { + AresdB_q[j] = AresdB_prev[j] + cbhigh->cb[besti_high*cbhigh->k+i]; + Ares[j] = pow(10.0, AresdB_q[j]/20.0); + // printf("%d %f %f\n", j, AresdB[j], AresdB_q[j]); + } +#endif + + //#define ART_NOISE +#ifdef ART_NOISE + // add some artificial noise to test effect on phase model + + for(i=0; iSn, c3->w); + + dump_Sn(c3->Sn); dump_Sw(Sw); dump_model(&model); + } + + // #define TIME_DOM +#ifdef TIME_DOM + { + float Wn[M]; + for(i=0; iSn[i]*c3->w[i]; + autocorrelate(Wn,R,M,LPC_ORD); + } + levinson_durbin(R, aks, LPC_ORD); + dump_ak(aks, LPC_ORD); +#else + autocorrelate_freq(Pph, wph, R, PHASE_POINTS, LPC_ORD); + levinson_durbin(R, aks, LPC_ORD); + dump_ak(aks, LPC_ORD); +#endif + + for(i=0; i<=LPC_ORD; i++) + printf("%d R: %f aks: %f\n", i, R[i], aks[i]); + //if (f==30) + // exit(0); + synthesise_one_frame(c3, buf, &model, aks); + } + else { + synthesise_one_frame_orig_phase(c3, buf, &model); + } + + if (fout != NULL) fwrite(buf, sizeof(short), N, fout); + + /* If energy high enough, include this frame in stats */ + + if (E > THRESH) { + af++; + sum_av_err_low += av_err_low; + if (err_less_than_clip_low) + sum_err_less_than_clip_low++; + sum_av_err_high += av_err_high; + if (err_less_than_clip_high) + sum_err_less_than_clip_high++; + sum_snr += snr; + } + for(i=0; i clip) { + e += fabs(element_e); + } + } + if (e < beste) { + beste = e; + besti = j; + } + } + + *av_err = 0; + *less_than_clip = 1; + for(i=0; i clip) { + *less_than_clip = 0; + } + } + for(i=0; i. +*/ + +/*-----------------------------------------------------------------------*\ + + INCLUDES + +\*-----------------------------------------------------------------------*/ + +#include +#include +#include +#include +#include + +/*-----------------------------------------------------------------------*\ + + DEFINES + +\*-----------------------------------------------------------------------*/ + +#define DELTAQ 0.001 /* quiting distortion */ +#define MAX_STR 80 /* maximum string length */ + +/*-----------------------------------------------------------------------*\ + + FUNCTION PROTOTYPES + +\*-----------------------------------------------------------------------*/ + +void zero(float v[], int k); +void acc(float v1[], float v2[], int k); +void norm(float v[], int k, long n); +long quantise(float cb[], float vec[], int k, int m, float clip, float *se); + +/*-----------------------------------------------------------------------*\ + + MAIN + +\*-----------------------------------------------------------------------*/ + +int main(int argc, char *argv[]) { + long k,m; /* dimension and codebook size */ + float *vec; /* current vector */ + float *cb; /* vector codebook */ + float *cent; /* centroids for each codebook entry */ + long *n; /* number of vectors in this interval */ + long J; /* number of vectors in training set */ + long i,j; + long ind; /* index of current vector */ + float se; /* squared error for this iteration */ + float Dn,Dn_1; /* current and previous iterations distortion */ + float delta; /* improvement in distortion */ + FILE *ftrain; /* file containing training set */ + FILE *fvq; /* file containing vector quantiser */ + float clip; + + /* Interpret command line arguments */ + + if (argc != 6) { + printf("usage: vqtrain TrainFile K M VQFile clip\n"); + exit(0); + } + + /* Open training file */ + + ftrain = fopen(argv[1],"rb"); + if (ftrain == NULL) { + printf("Error opening training database file: %s\n",argv[1]); + exit(1); + } + + /* determine k and m, and allocate arrays */ + + k = atol(argv[2]); + m = atol(argv[3]); + clip = atof(argv[5]); + printf("dimension K=%ld number of entries M=%ld clip = %f\n", k,m,clip); + vec = (float*)malloc(sizeof(float)*k); + cb = (float*)malloc(sizeof(float)*k*m); + cent = (float*)malloc(sizeof(float)*k*m); + n = (long*)malloc(sizeof(long)*m); + if (cb == NULL || cb == NULL || cent == NULL || vec == NULL) { + printf("Error in malloc.\n"); + exit(1); + } + + /* determine size of training set */ + + J = 0; + while(fread(vec, sizeof(float), k, ftrain) == k) + J++; + printf("J=%ld entries in training set\n", J); + + /* set up initial codebook state from samples of training set */ + + rewind(ftrain); + fread(cb, sizeof(float), k*m, ftrain); + + /* main loop */ + + Dn = 1E32; + j = 1; + do { + Dn_1 = Dn; + + /* zero centroids */ + + for(i=0; i DELTAQ) + for(i=0; i DELTAQ); + + /* save codebook to disk */ + + fvq = fopen(argv[4],"wt"); + if (fvq == NULL) { + printf("Error opening VQ file: %s\n",argv[4]); + exit(1); + } + + fprintf(fvq,"%ld %ld\n",k,m); + for(j=0; j clip) { + e += element_e*element_e; + } + } + if (e < beste) { + beste = e; + besti = j; + } + } + + *se += beste; + + return(besti); +} + -- 2.25.1