Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mumble-voip/speex.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjmvalin <jmvalin@0101bb08-14d6-0310-b084-bc0e0c8e3800>2002-03-22 08:03:30 +0300
committerjmvalin <jmvalin@0101bb08-14d6-0310-b084-bc0e0c8e3800>2002-03-22 08:03:30 +0300
commit8180ce8eddda4f31de0c64041b63d164478e09d6 (patch)
tree0c3886e13b54d63f6d5eb38e83131c7910604cdc /libspeex
parentd14aaf795c8336be2212c90d275d3a177c319e01 (diff)
Modified WB perceptual filter, starting a multi-pulse "branch"
git-svn-id: http://svn.xiph.org/trunk/speex@3171 0101bb08-14d6-0310-b084-bc0e0c8e3800
Diffstat (limited to 'libspeex')
-rw-r--r--libspeex/Makefile.am8
-rw-r--r--libspeex/cb_search.c2
-rw-r--r--libspeex/modes.c9
-rw-r--r--libspeex/mpulse.c100
-rw-r--r--libspeex/mpulse.h41
-rw-r--r--libspeex/speex.c24
-rw-r--r--libspeex/testenc.c2
7 files changed, 170 insertions, 16 deletions
diff --git a/libspeex/Makefile.am b/libspeex/Makefile.am
index 8a7e1f8..ce1d49b 100644
--- a/libspeex/Makefile.am
+++ b/libspeex/Makefile.am
@@ -1,6 +1,6 @@
## Process this file with automake to produce Makefile.in. -*-Makefile-*-
-# $Id: Makefile.am,v 1.16 2002/03/20 06:59:23 jmvalin Exp $
+# $Id: Makefile.am,v 1.17 2002/03/22 05:03:30 jmvalin Exp $
# Disable automatic dependency tracking if using other tools than gcc and gmake
#AUTOMAKE_OPTIONS = no-dependencies
@@ -27,7 +27,8 @@ libspeex_la_SOURCES = speex.c \
exc_gains_wb_table.c \
exc_gains_wb2_table.c \
vq.c \
- matrix.c
+ matrix.c \
+ mpulse.c
include_HEADERS = speex.h \
@@ -42,7 +43,8 @@ noinst_HEADERS = lsp.h \
filters.h \
stack_alloc.h \
vq.h \
- matrix.h
+ matrix.h \
+ mpulse.h
libspeex_la_LDFLAGS = -release $(LT_RELEASE)
diff --git a/libspeex/cb_search.c b/libspeex/cb_search.c
index 29d9a30..17427c5 100644
--- a/libspeex/cb_search.c
+++ b/libspeex/cb_search.c
@@ -487,7 +487,7 @@ float *stack
solve(&A[0][0],b,c, 10);
for (i=0;i<10;i++)
- gains[i]*=c[i];
+ gains[i]*=c[i];
for (i=0;i<10;i++)
gains[i]*=Ee[ind[i]];
diff --git a/libspeex/modes.c b/libspeex/modes.c
index e8679df..f41ea31 100644
--- a/libspeex/modes.c
+++ b/libspeex/modes.c
@@ -24,6 +24,7 @@
#include "ltp.h"
#include "quant_lsp.h"
#include "cb_search.h"
+#include "mpulse.h"
extern float gain_cdbk_nb[];
extern float exc_gains_table[];
@@ -82,7 +83,7 @@ SpeexMode nb_mode = {
pitch_unquant_3tap,
&ltp_params_nb,
/*Innovation quantization*/
- split_cb_search,
+ split_cb_search/*mpulse_search*/,
split_cb_unquant,
&split_cb_nb
};
@@ -97,10 +98,10 @@ SpeexMode wb_mode = {
35, /*pitchStart*/
290, /*pitchEnd*/
0.9, /*gamma1*/
- 0.6, /*gamma2*/
+ -1.0, /*gamma2*/
.002, /*lag_factor*/
- 1.00001,/*lpc_floor*/
- 0.0, /*preemph*/
+ 1.0001,/*lpc_floor*/
+ 0.7, /*preemph*/
/*LSP quantization*/
lsp_quant_wb,
diff --git a/libspeex/mpulse.c b/libspeex/mpulse.c
new file mode 100644
index 0000000..d6d1483
--- /dev/null
+++ b/libspeex/mpulse.c
@@ -0,0 +1,100 @@
+/* Copyright (C) 2002 Jean-Marc Valin
+ File: mpulse.c
+
+ Multi-pulse code
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+*/
+
+#include "mpulse.h"
+#include "stack_alloc.h"
+#include <stdio.h>
+#include "filters.h"
+
+void mpulse_search(
+float target[], /* target vector */
+float ak[], /* LPCs for this subframe */
+float awk1[], /* Weighted LPCs for this subframe */
+float awk2[], /* Weighted LPCs for this subframe */
+void *par, /* Codebook/search parameters*/
+int p, /* number of LPC coeffs */
+int nsf, /* number of samples in subframe */
+float *exc,
+FrameBits *bits,
+float *stack
+)
+{
+ int i,j, nb_pulse=12;
+ float *resp, *t, *e;
+
+ resp=PUSH(stack, nsf);
+ t=PUSH(stack, nsf);
+ e=PUSH(stack, nsf);
+
+ e[0]=1;
+ for (i=1;i<nsf;i++)
+ e[i]=0;
+
+ residue_zero(e, awk1, resp, nsf, p);
+ syn_filt_zero(resp, ak, resp, nsf, p);
+ syn_filt_zero(resp, awk2, resp, nsf, p);
+
+ for (i=0;i<nsf;i++)
+ e[i]=0;
+
+ for (i=0;i<nsf;i++)
+ t[i]=target[i];
+
+ /*For all pulses*/
+ for (i=0;i<nb_pulse;i++)
+ {
+ float best_score=0, best_gain=0;
+ int best_ind=0;
+ /*For all positions*/
+ for (j=0;j<nsf;j++)
+ {
+ float corr, energy, score;
+ corr=xcorr(t+j,resp,nsf-j);
+ /*This can be pre-calculated*/
+ energy=xcorr(resp,resp,nsf-j);
+ score=corr*corr/energy;
+ if (score>best_score)
+ {
+ best_score=score;
+ best_ind=j;
+ best_gain=corr/energy;
+ }
+ }
+
+ printf ("best pulse: %d %f\n", best_ind, best_gain);
+ /*Remove pulse contribution from target*/
+ for (j=best_ind;j<nsf;j++)
+ t[j] -= best_gain * resp[j-best_ind];
+ e[best_ind]+=best_gain;
+ }
+
+ for (i=0;i<nsf;i++)
+ printf ("%f ", e[i]);
+ printf ("\n");
+ for (i=0;i<nsf;i++)
+ exc[i]+=e[i];
+ for (i=0;i<nsf;i++)
+ target[i]+=t[i];
+
+ POP(stack);
+ POP(stack);
+ POP(stack);
+}
diff --git a/libspeex/mpulse.h b/libspeex/mpulse.h
new file mode 100644
index 0000000..08f30b3
--- /dev/null
+++ b/libspeex/mpulse.h
@@ -0,0 +1,41 @@
+/* Copyright (C) 2002 Jean-Marc Valin
+ File: mpulse.h
+
+ Multi-pulse code
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+*/
+
+#ifndef MPULSE_H
+#define MPULSE_H
+
+#include "bits.h"
+
+void mpulse_search(
+float target[], /* target vector */
+float ak[], /* LPCs for this subframe */
+float awk1[], /* Weighted LPCs for this subframe */
+float awk2[], /* Weighted LPCs for this subframe */
+void *par, /* Codebook/search parameters*/
+int p, /* number of LPC coeffs */
+int nsf, /* number of samples in subframe */
+float *exc,
+FrameBits *bits,
+float *stack
+);
+
+
+#endif
diff --git a/libspeex/speex.c b/libspeex/speex.c
index 42f1603..eef675e 100644
--- a/libspeex/speex.c
+++ b/libspeex/speex.c
@@ -269,8 +269,15 @@ void encode(EncState *st, float *in, FrameBits *bits)
/* Compute bandwidth-expanded (unquantized) LPCs for perceptual weighting */
bw_lpc(st->gamma1, st->interp_lpc, st->bw_lpc1, st->lpcSize);
- bw_lpc(st->gamma2, st->interp_lpc, st->bw_lpc2, st->lpcSize);
-
+ if (st->gamma2>=0)
+ bw_lpc(st->gamma2, st->interp_lpc, st->bw_lpc2, st->lpcSize);
+ else
+ {
+ st->bw_lpc2[0]=1;
+ st->bw_lpc2[1]=-st->preemph;
+ for (i=2;i<=st->lpcSize;i++)
+ st->bw_lpc2[i]=0;
+ }
printf ("\nlpc0 ");
for (i=0;i<=st->lpcSize;i++)
printf ("%f ", st->interp_lpc[i]);
@@ -281,9 +288,6 @@ void encode(EncState *st, float *in, FrameBits *bits)
for (i=0;i<=st->lpcSize;i++)
printf ("%f ", st->bw_lpc2[i]);
printf ("\n\n");
- /*for (i=1;i<=st->lpcSize;i++)
- st->bw_lpc2[i]=0;
- st->bw_lpc2[1]=-st->preemph;*/
/* Reset excitation */
for (i=0;i<st->subframeSize;i++)
@@ -320,10 +324,17 @@ void encode(EncState *st, float *in, FrameBits *bits)
exc[i]=0;
/* Long-term prediction */
+#if 1
st->ltp_quant(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2,
exc, st->ltp_params, st->min_pitch, st->max_pitch,
st->lpcSize, st->subframeSize, bits, st->stack);
-
+#else
+ {
+ float gain[3];
+ int pitch;
+ closed_loop_fractional_pitch(target, st->interp_qlpc, st->bw_lpc1, st->bw_lpc2, exc, st->os_filt, st->os_filt_ord2, st->os_fact, 35, 290, &gain[0], &pitch, st->lpcSize, st->subframeSize, st->stack);
+ }
+#endif
/* Update target for adaptive codebook contribution */
residue_zero(exc, st->bw_lpc1, res, st->subframeSize, st->lpcSize);
syn_filt_zero(res, st->interp_qlpc, res, st->subframeSize, st->lpcSize);
@@ -361,7 +372,6 @@ void encode(EncState *st, float *in, FrameBits *bits)
st->innovation_params, st->lpcSize,
st->subframeSize, exc, bits, st->stack);
-
#endif
/* Compute weighted noise energy and SNR */
enoise=0;
diff --git a/libspeex/testenc.c b/libspeex/testenc.c
index 7a00b67..be85d1c 100644
--- a/libspeex/testenc.c
+++ b/libspeex/testenc.c
@@ -59,7 +59,7 @@ int main(int argc, char **argv)
}
frame_bits_rewind(&bits);
- decode(&dec, &bits, input);
+ /*decode(&dec, &bits, input);*/
/* Save the bits here */
frame_bits_reset(&bits);