AM_CPPFLAGS = $(AM_CFLAGS)
D=codebook
+
+# lsp quantisers
+
CODEBOOKS= \
$D/lsp1.txt \
$D/lsp2.txt \
$D/lsp9.txt \
$D/lsp10.txt
+# lspd quantisers
+
+CODEBOOKSD= \
+ $D/dlsp1.txt \
+ $D/dlsp2.txt \
+ $D/dlsp3.txt \
+ $D/dlsp4.txt \
+ $D/dlsp5.txt \
+ $D/dlsp6.txt \
+ $D/dlsp7.txt \
+ $D/dlsp8.txt \
+ $D/dlsp9.txt \
+ $D/dlsp10.txt
+
noinst_PROGRAMS = generate_codebook
codebook.$(OBJEXT): codebook.c
+codebookd.$(OBJEXT): codebookd.c
codebook.lo: codebook.c
codebook.c: generate_codebook $(CODEBOOKS)
- ./generate_codebook $(CODEBOOKS) > codebook.c
+ ./generate_codebook lsp_cb $(CODEBOOKS) > codebook.c
+
+codebookd.c: generate_codebook $(CODEBOOKSD)
+ ./generate_codebook lsp_cbd $(CODEBOOKSD) > codebookd.c
clean-local:
- -rm -f codebook.c
+ -rm -f codebook.c codebookd.c
lib_LTLIBRARIES = libcodec2.la
libcodec2_la_SOURCES = dump.c \
phase.c \
quantise.c \
pack.c \
-codebook.c
+codebook.c \
+codebookd.c
libcodec2_la_CFLAGS = $(AM_CFLAGS)
libcodec2_la_LDFLAGS = $(LIBS)
libcodec2_la-four1.lo libcodec2_la-interp.lo \
libcodec2_la-lsp.lo libcodec2_la-phase.lo \
libcodec2_la-quantise.lo libcodec2_la-pack.lo \
- libcodec2_la-codebook.lo
+ libcodec2_la-codebook.lo libcodec2_la-codebookd.lo
libcodec2_la_OBJECTS = $(am_libcodec2_la_OBJECTS)
binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
PROGRAMS = $(bin_PROGRAMS) $(noinst_PROGRAMS)
NAME = codec2
AM_CPPFLAGS = $(AM_CFLAGS)
D = codebook
+
+# lsp quantisers
CODEBOOKS = \
$D/lsp1.txt \
$D/lsp2.txt \
$D/lsp9.txt \
$D/lsp10.txt
+
+# lspd quantisers
+CODEBOOKSD = \
+ $D/dlsp1.txt \
+ $D/dlsp2.txt \
+ $D/dlsp3.txt \
+ $D/dlsp4.txt \
+ $D/dlsp5.txt \
+ $D/dlsp6.txt \
+ $D/dlsp7.txt \
+ $D/dlsp8.txt \
+ $D/dlsp9.txt \
+ $D/dlsp10.txt
+
lib_LTLIBRARIES = libcodec2.la
libcodec2_la_SOURCES = dump.c \
lpc.c \
phase.c \
quantise.c \
pack.c \
-codebook.c
+codebook.c \
+codebookd.c
libcodec2_la_CFLAGS = $(AM_CFLAGS)
libcodec2_la_LDFLAGS = $(LIBS)
@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)/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-codec2.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-dump.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libcodec2_la-four1.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-codebook.lo `test -f 'codebook.c' || echo '$(srcdir)/'`codebook.c
+libcodec2_la-codebookd.lo: codebookd.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-codebookd.lo -MD -MP -MF "$(DEPDIR)/libcodec2_la-codebookd.Tpo" -c -o libcodec2_la-codebookd.lo `test -f 'codebookd.c' || echo '$(srcdir)/'`codebookd.c; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libcodec2_la-codebookd.Tpo" "$(DEPDIR)/libcodec2_la-codebookd.Plo"; else rm -f "$(DEPDIR)/libcodec2_la-codebookd.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='codebookd.c' object='libcodec2_la-codebookd.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-codebookd.lo `test -f 'codebookd.c' || echo '$(srcdir)/'`codebookd.c
+
mostlyclean-libtool:
-rm -f *.lo
codebook.$(OBJEXT): codebook.c
+codebookd.$(OBJEXT): codebookd.c
codebook.lo: codebook.c
codebook.c: generate_codebook $(CODEBOOKS)
- ./generate_codebook $(CODEBOOKS) > codebook.c
+ ./generate_codebook lsp_cb $(CODEBOOKS) > codebook.c
+
+codebookd.c: generate_codebook $(CODEBOOKSD)
+ ./generate_codebook lsp_cbd $(CODEBOOKSD) > codebookd.c
clean-local:
- -rm -f codebook.c
+ -rm -f codebook.c codebookd.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 = 0;
- int lsp, lsp_quantiser;
+ int lsp, dlsp, lsp_quantiser;
float ak[LPC_MAX];
COMP Sw_[FFT_ENC];
COMP Ew[FFT_ENC];
"usage: %s InputFile [-o OutputFile]\n"
"\t[--lpc Order]\n"
"\t[--lsp]\n"
+ "\t[--dlsp]\n"
"\t[--phase0]\n"
"\t[--postfilter]\n"
"\t[--hand_voicing]\n"
lsp = switch_present("--lsp",argc,argv);
lsp_quantiser = 0;
+ if (lsp)
+ assert(order == LPC_ORD);
+
+ dlsp = switch_present("--dlsp",argc,argv);
+ if (dlsp)
+ assert(order == LPC_ORD);
phase0 = switch_present("--phase0",argc,argv);
if (phase0) {
if (phase0) {
float Wn[M]; /* windowed speech samples */
- float Rk[LPC_ORD+1]; /* autocorrelation coeffs */
+ float Rk[LPC_MAX+1]; /* autocorrelation coeffs */
#ifdef DUMP
dump_phase(&model.phi[0], model.L);
for(i=0; i<M; i++)
Wn[i] = Sn[i]*w[i];
- autocorrelate(Wn,Rk,M,LPC_ORD);
- levinson_durbin(Rk,ak,LPC_ORD);
-
- if (lpc_model)
- assert(order == LPC_ORD);
+ autocorrelate(Wn,Rk,M,order);
+ levinson_durbin(Rk,ak,order);
#ifdef DUMP
dump_ak(ak, LPC_ORD);
/* optional LPC model amplitudes */
if (lpc_model) {
- int lsp_indexes[LPC_ORD];
+ int lsp_indexes[LPC_MAX];
e = speech_to_uq_lsps(lsps, ak, Sn, w, order);
- lpc_correction = need_lpc_correction(&model, ak, e);
+ lpc_correction = need_lpc_correction(&model, ak, e, order);
if (lsp) {
encode_lsps(lsp_indexes, lsps, LPC_ORD);
lsp_to_lpc(lsps, ak, LPC_ORD);
}
- e = decode_energy(encode_energy(e));
- model.Wo = decode_Wo(encode_Wo(model.Wo));
+ if (dlsp) {
+ float lsps_[LPC_ORD];
+
+ lspd_quantise(lsps, lsps_, LPC_ORD);
+ lsp_to_lpc(lsps_, ak, LPC_ORD);
+ }
+
+ //e = decode_energy(encode_energy(e));
+ //model.Wo = decode_Wo(encode_Wo(model.Wo));
aks_to_M2(ak, order, &model, e, &snr, 1);
apply_lpc_correction(&model, lpc_correction);
#endif
if (phase0)
- phase_synth_zero_order(&interp_model, ak_interp, ex_phase);
+ 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);
if (phase0)
- phase_synth_zero_order(&model, ak, ex_phase);
+ phase_synth_zero_order(&model, ak, ex_phase, order);
if (postfilt)
postfilter(&model, &bg_est);
synth_one_frame(buf, &model, Sn_, Pn);
}
else {
if (phase0)
- phase_synth_zero_order(&model, ak, ex_phase);
+ phase_synth_zero_order(&model, ak, ex_phase, order);
if (postfilt)
postfilter(&model, &bg_est);
synth_one_frame(buf, &model, Sn_, Pn);
--- /dev/null
+1 16
+225
+250
+275
+300
+325
+350
+375
+400
+425
+450
+475
+500
+525
+550
+575
+600
--- /dev/null
+1 8
+50
+100
+200
+300
+425
+550
+675
+800
--- /dev/null
+1 16
+25
+50
+75
+100
+125
+150
+175
+200
+225
+250
+275
+300
+325
+350
+375
+400
--- /dev/null
+1 8
+50
+75
+100
+120
+150
+250
+350
+450
--- /dev/null
+1 8
+50
+100
+200
+300
+425
+550
+675
+800
--- /dev/null
+1 8
+50
+100
+200
+300
+425
+550
+675
+800
--- /dev/null
+1 8
+50
+100
+200
+300
+425
+550
+675
+800
--- /dev/null
+1 8
+50
+100
+200
+300
+425
+550
+675
+800
--- /dev/null
+1 8
+50
+100
+200
+300
+425
+550
+675
+800
--- /dev/null
+1 8
+50
+100
+200
+300
+425
+550
+675
+800
const float * cb; /* The elements */
};
extern const struct lsp_codebook lsp_cb[];
+extern const struct lsp_codebook lsp_cbd[];
#endif
#include <math.h>
static const char usage[] =
-"Usage: %s filename [filename ...]\n"
+"Usage: %s filename array_name [filename ...]\n"
"\tCreate C code for codebook tables.\n";
static const char format[] =
exit(1);
}
- for ( i = 0; i < argc - 1; i++ ) {
- FILE * in = fopen(argv[i + 1], "r");
+ for ( i = 0; i < argc - 2; i++ ) {
+ FILE * in = fopen(argv[i + 2], "r");
if ( in == NULL ) {
- perror(argv[i + 1]);
+ perror(argv[i + 2]);
exit(1);
}
- cb[i] = load(in, argv[i + 1]);
+ cb[i] = load(in, argv[i + 2]);
fclose(in);
}
printf(header);
- for ( i = 0; i < argc - 1; i++ ) {
- printf(" /* %s */\n", argv[i + 1]);
+ for ( i = 0; i < argc - 2; i++ ) {
+ printf(" /* %s */\n", argv[i + 2]);
dump_array(cb[i], i);
}
- printf("\nconst struct lsp_codebook lsp_cb[] = {\n");
- for ( i = 0; i < argc - 1; i++ ) {
- printf(" /* %s */\n", argv[i + 1]);
+ printf("\nconst struct lsp_codebook %s[] = {\n", argv[1]);
+ for ( i = 0; i < argc - 2; i++ ) {
+ printf(" /* %s */\n", argv[i + 2]);
dump_structure(cb[i], i);
printf(",\n");
}
printf("index %d val_: %f\n", index, val[0]);
}
-/*---------------------------------------------------------------------------*\
-
- lspd_quantise
-
- Simulates differential lsp quantiser
-
-\*---------------------------------------------------------------------------*/
-
-void lsp_quantise(
- float lsp[],
- float lsp_[],
- int order
-)
-{
- int i;
- float dlsp[LPC_MAX];
- float dlsp_[LPC_MAX];
-
- dlsp[0] = lsp[0];
- for(i=1; i<order; i++)
- dlsp[i] = lsp[i] - lsp[i-1];
-
- for(i=0; i<order; i++)
- dlsp_[i] = dlsp[i];
-
- quantise_uniform(&dlsp_[0], 0.1, 0.5, 5);
-
- lsp_[0] = dlsp_[0];
- for(i=1; i<order; i++)
- lsp_[i] = lsp_[i-1] + dlsp_[i];
-}
#endif
/*---------------------------------------------------------------------------*\
return(besti);
}
+/*---------------------------------------------------------------------------*\
+
+ lspd_quantise
+
+ Differential lsp quantiser
+
+\*---------------------------------------------------------------------------*/
+
+void lspd_quantise(
+ float lsp[],
+ float lsp_[],
+ int order
+)
+{
+ int i,k,m;
+ float lsp_hz[LPC_MAX];
+ float lsp__hz[LPC_MAX];
+ float dlsp[LPC_MAX];
+ float dlsp_[LPC_MAX];
+ float wt[1];
+ const float *cb;
+ float se;
+ int indexes[LPC_MAX];
+
+ /* convert from radians to Hz so we can use human readable
+ frequencies */
+
+ for(i=0; i<order; i++)
+ lsp_hz[i] = (4000.0/PI)*lsp[i];
+
+ dlsp[0] = lsp_hz[0];
+ for(i=1; i<order; i++)
+ dlsp[i] = lsp_hz[i] - lsp_hz[i-1];
+
+ /* simple uniform scalar quantisers */
+
+ wt[0] = 1.0;
+ for(i=0; i<order; i++) {
+ if (i)
+ dlsp[i] = lsp_hz[i] - lsp__hz[i-1];
+ else
+ dlsp[0] = lsp_hz[0];
+
+ k = lsp_cbd[i].k;
+ m = lsp_cbd[i].m;
+ cb = lsp_cbd[i].cb;
+ indexes[i] = quantise(cb, &dlsp[i], wt, k, m, &se);
+ dlsp_[i] = cb[indexes[i]*k];
+
+ if (i)
+ lsp__hz[i] = lsp__hz[i-1] + dlsp_[i];
+ else
+ lsp__hz[0] = dlsp_[0];
+ }
+ for(; i<order; i++)
+ lsp__hz[i] = lsp__hz[i-1] + dlsp[i];
+
+ /* convert back to radians */
+
+ for(i=0; i<order; i++)
+ lsp_[i] = (PI/4000.0)*lsp__hz[i];
+}
+
void check_lsp_order(float lsp[], int lpc_order)
{
int i;
\*---------------------------------------------------------------------------*/
-int need_lpc_correction(MODEL *model, float ak[], float E)
+int need_lpc_correction(MODEL *model, float ak[], float E, int order)
{
MODEL tmp;
float snr,E1;
*/
memcpy(&tmp, model, sizeof(MODEL));
- aks_to_M2(ak, LPC_ORD, &tmp, E, &snr, 0);
+ aks_to_M2(ak, order, &tmp, E, &snr, 0);
/*
Attenuate fundamental by 30dB if F0 < 150 Hz and LPC modelling
e = speech_to_uq_lsps(lsps, ak, Sn, w, LPC_ORD);
encode_lsps(lsp_indexes, lsps, LPC_ORD);
- *lpc_correction = need_lpc_correction(model, ak, e);
+ *lpc_correction = need_lpc_correction(model, ak, e, LPC_ORD);
*energy_index = encode_energy(e);
}
void encode_lsps(int indexes[], float lsp[], int order);
void decode_lsps(float lsp[], int indexes[], int order);
+void lspd_quantise(float lsp[], float lsp_[], int order);
int encode_energy(float e);
float decode_energy(int index);
int lsp_bits(int i);
-int need_lpc_correction(MODEL *model, float ak[], float E);
+int need_lpc_correction(MODEL *model, float ak[], float E, int order);
void apply_lpc_correction(MODEL *model, int lpc_correction);
float speech_to_uq_lsps(float lsp[],
float ak[],