$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)
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 \
codebook.c \
codebookd.c \
codebookvq.c \
-codebookres.c
+codebookres.c \
+codebookdt.c
libcodec2_la_CFLAGS = $(AM_CFLAGS)
libcodec2_la_LDFLAGS = $(LIBS)
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
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)
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
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
$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 \
codebook.c \
codebookd.c \
codebookvq.c \
-codebookres.c
+codebookres.c \
+codebookdt.c
libcodec2_la_CFLAGS = $(AM_CFLAGS)
libcodec2_la_LDFLAGS = $(LIBS)
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)
@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@
@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
codebookvq.$(OBJEXT): codebookvq.c
codebookres.$(OBJEXT): codebookres.c
+$(CODEBOOKSDT): genlspdtcb
+ ./genlspdtcb
+
codebook.lo: codebook.c
codebook.c: generate_codebook $(CODEBOOKS)
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:
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];
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];
}
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;
"\t[--lspd]\n"
"\t[--lspvq]\n"
"\t[--lspres]\n"
+ "\t[--lspdt]\n"
"\t[--phase0]\n"
"\t[--postfilter]\n"
"\t[--hand_voicing]\n"
assert(order == LPC_ORD);
lspres = switch_present("--lspres",argc,argv);
+ lspdt = switch_present("--lspdt",argc,argv);
phase0 = switch_present("--phase0",argc,argv);
if (phase0) {
/* 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);
}
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);
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
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
--- /dev/null
+/*---------------------------------------------------------------------------*\
+
+ 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);
+}
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;
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;
}
+/*---------------------------------------------------------------------------*\
+
+ 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;
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++)
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);