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-13 05:45:50 +0300
committerjmvalin <jmvalin@0101bb08-14d6-0310-b084-bc0e0c8e3800>2002-03-13 05:45:50 +0300
commit7186b82a0a13f3ca0d9e689953640c3e75267d85 (patch)
tree5830869cebf100724c9efc2e2ed930f1c927819f /libspeex
parent9db812ae2e2320a17a8716615b7460994c2321bd (diff)
More decoder work
git-svn-id: http://svn.xiph.org/trunk/speex@3136 0101bb08-14d6-0310-b084-bc0e0c8e3800
Diffstat (limited to 'libspeex')
-rw-r--r--libspeex/bits.c6
-rw-r--r--libspeex/bits.h2
-rw-r--r--libspeex/quant_lsp.c32
-rw-r--r--libspeex/speex.c60
-rw-r--r--libspeex/speex.h5
-rw-r--r--libspeex/testenc.c9
6 files changed, 92 insertions, 22 deletions
diff --git a/libspeex/bits.c b/libspeex/bits.c
index 0bfc768..42636d3 100644
--- a/libspeex/bits.c
+++ b/libspeex/bits.c
@@ -48,6 +48,12 @@ void frame_bits_reset(FrameBits *bits)
bits->bitPtr=0;
}
+void frame_bits_rewind(FrameBits *bits)
+{
+ bits->bytePtr=0;
+ bits->bitPtr=0;
+}
+
void frame_bits_init_from(FrameBits *bits, char *bytes, int len)
{
int i;
diff --git a/libspeex/bits.h b/libspeex/bits.h
index aa298c0..c5ed0bf 100644
--- a/libspeex/bits.h
+++ b/libspeex/bits.h
@@ -37,6 +37,8 @@ void frame_bits_destroy(FrameBits *bits);
void frame_bits_reset(FrameBits *bits);
+void frame_bits_rewind(FrameBits *bits);
+
void frame_bits_init_from(FrameBits *bits, char *bytes, int len);
int frame_bits_write(FrameBits *bits, char *bytes, int max_len);
diff --git a/libspeex/quant_lsp.c b/libspeex/quant_lsp.c
index a8d8052..8d32d56 100644
--- a/libspeex/quant_lsp.c
+++ b/libspeex/quant_lsp.c
@@ -99,22 +99,27 @@ void lsp_quant_nb(float *lsp, float *qlsp, int order, FrameBits *bits)
quant_weight[i] = tmp1 > tmp2 ? tmp1 : tmp2;
}
id = lsp_quant(qlsp, cdbk_nb, NB_CDBK_SIZE, order);
- frame_bits_pack(bits, id, 5);
+ printf ("qid = %d\n", id);
+ frame_bits_pack(bits, id, 6);
id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low1, NB_CDBK_SIZE_LOW1, 5);
- frame_bits_pack(bits, id, 5);
+ printf ("qid = %d\n", id);
+ frame_bits_pack(bits, id, 6);
id = lsp_weight_quant(qlsp, quant_weight, cdbk_nb_low2, NB_CDBK_SIZE_LOW2, 5);
- frame_bits_pack(bits, id, 5);
+ printf ("qid = %d\n", id);
+ frame_bits_pack(bits, id, 6);
id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high1, NB_CDBK_SIZE_HIGH1, 5);
- frame_bits_pack(bits, id, 5);
+ printf ("qid = %d\n", id);
+ frame_bits_pack(bits, id, 6);
id = lsp_weight_quant(qlsp+5, quant_weight+5, cdbk_nb_high2, NB_CDBK_SIZE_HIGH2, 5);
- frame_bits_pack(bits, id, 5);
+ printf ("qid = %d\n", id);
+ frame_bits_pack(bits, id, 6);
for (i=0;i<order;i++)
- qlsp[i]=qlsp[i]-lsp[i];
+ qlsp[i]=lsp[i]-qlsp[i];
}
void lsp_unquant_nb(float *lsp, int order, FrameBits *bits)
@@ -124,23 +129,28 @@ void lsp_unquant_nb(float *lsp, int order, FrameBits *bits)
lsp[i]=0;
- id=frame_bits_unpack_unsigned(bits, 5);
+ id=frame_bits_unpack_unsigned(bits, 6);
+ printf ("did = %d\n", id);
for (i=0;i<10;i++)
lsp[i] += cdbk_nb[id*10+i];
- id=frame_bits_unpack_unsigned(bits, 5);
+ id=frame_bits_unpack_unsigned(bits, 6);
+ printf ("did = %d\n", id);
for (i=0;i<5;i++)
lsp[i] += cdbk_nb_low1[id*5+i];
- id=frame_bits_unpack_unsigned(bits, 5);
+ id=frame_bits_unpack_unsigned(bits, 6);
+ printf ("did = %d\n", id);
for (i=0;i<5;i++)
lsp[i] += cdbk_nb_low2[id*5+i];
- id=frame_bits_unpack_unsigned(bits, 5);
+ id=frame_bits_unpack_unsigned(bits, 6);
+ printf ("did = %d\n", id);
for (i=0;i<5;i++)
lsp[i+5] += cdbk_nb_high1[id*5+i];
- id=frame_bits_unpack_unsigned(bits, 5);
+ id=frame_bits_unpack_unsigned(bits, 6);
+ printf ("did = %d\n", id);
for (i=0;i<5;i++)
lsp[i+5] += cdbk_nb_high2[id*5+i];
}
diff --git a/libspeex/speex.c b/libspeex/speex.c
index d66acb1..8c0742c 100644
--- a/libspeex/speex.c
+++ b/libspeex/speex.c
@@ -202,6 +202,10 @@ void encode(EncState *st, float *in, FrameBits *bits)
for (i=0;i<st->lpcSize;i++)
st->old_qlsp[i] = st->qlsp[i];
}
+ printf ("encode LSPs: ");
+ for (i=0;i<st->lpcSize;i++)
+ printf ("%f ", st->qlsp[i]);
+ printf ("\n");
/*Find open-loop pitch for the whole frame*/
if (0) {
@@ -466,6 +470,7 @@ void decoder_init(DecState *st, SpeexMode *mode)
st->min_pitch=mode->pitchStart;
st->max_pitch=mode->pitchEnd;
+ st->stack = calloc(10000, sizeof(float));
st->inBuf = malloc(st->bufSize*sizeof(float));
st->frame = st->inBuf + st->bufSize - st->windowSize;
@@ -477,12 +482,10 @@ void decoder_init(DecState *st, SpeexMode *mode)
st->excBuf[i]=0;
st->interp_qlpc = malloc((st->lpcSize+1)*sizeof(float));
- st->bw_lpc1 = malloc((st->lpcSize+1)*sizeof(float));
- st->bw_lpc2 = malloc((st->lpcSize+1)*sizeof(float));
-
st->qlsp = malloc(st->lpcSize*sizeof(float));
st->old_qlsp = malloc(st->lpcSize*sizeof(float));
st->interp_qlsp = malloc(st->lpcSize*sizeof(float));
+ st->mem_sp = calloc(st->lpcSize, sizeof(float));
}
@@ -491,17 +494,16 @@ void decoder_destroy(DecState *st)
free(st->inBuf);
free(st->excBuf);
free(st->interp_qlpc);
- free(st->bw_lpc1);
- free(st->bw_lpc2);
free(st->qlsp);
free(st->old_qlsp);
free(st->interp_qlsp);
-
+ free(st->stack);
+ free(st->mem_sp);
}
void decode(DecState *st, FrameBits *bits, float *out)
{
- int i;
+ int i, sub;
lsp_unquant_nb(st->qlsp, st->lpcSize, bits);
if (st->first)
@@ -510,6 +512,50 @@ void decode(DecState *st, FrameBits *bits, float *out)
st->old_qlsp[i] = st->qlsp[i];
}
+ printf ("decode LSPs: ");
+ for (i=0;i<st->lpcSize;i++)
+ printf ("%f ", st->qlsp[i]);
+ printf ("\n");
+
+ /*Loop on subframes */
+ for (sub=0;sub<st->nbSubframes;sub++)
+ {
+ int offset;
+ float *sp, *exc, tmp;
+
+ /* Offset relative to start of frame */
+ offset = st->subframeSize*sub;
+ /* Original signal */
+ sp=st->frame+offset;
+ /* Excitation */
+ exc=st->exc+offset;
+
+ /* LSP interpolation (quantized and unquantized) */
+ tmp = (.5 + sub)/st->nbSubframes;
+ for (i=0;i<st->lpcSize;i++)
+ st->interp_qlsp[i] = (1-tmp)*st->old_qlsp[i] + tmp*st->qlsp[i];
+
+ /* Compute interpolated LPCs (unquantized) */
+ for (i=0;i<st->lpcSize;i++)
+ st->interp_qlsp[i] = cos(st->interp_qlsp[i]);
+ lsp_to_lpc(st->interp_qlsp, st->interp_qlpc, st->lpcSize, st->stack);
+
+ /* Reset excitation */
+ for (i=0;i<st->subframeSize;i++)
+ exc[i]=0;
+
+ /*Adaptive codebook contribution*/
+
+ /*Fixed codebook contribution*/
+
+ /*Compute decoded signal*/
+ syn_filt_mem(exc, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, st->mem_sp);
+
+ }
+
+ /*Copy output signal*/
+ for (i=0;i<st->frameSize;i++)
+ out[i]=st->frame[i];
/* Store the LSPs for interpolation in the next frame */
for (i=0;i<st->lpcSize;i++)
diff --git a/libspeex/speex.h b/libspeex/speex.h
index 1e625bf..b714bb1 100644
--- a/libspeex/speex.h
+++ b/libspeex/speex.h
@@ -81,6 +81,7 @@ typedef struct DecState {
int max_pitch; /* Maximum pitch value allowed */
float gamma1; /* Perceptual filter: A(z/gamma1) */
float gamma2; /* Perceptual filter: A(z/gamma2) */
+ float *stack;
float *inBuf; /* Input buffer (original signal) */
float *frame; /* Start of original frame */
float *excBuf; /* Excitation buffer */
@@ -89,9 +90,7 @@ typedef struct DecState {
float *old_qlsp; /* Quantized LSPs for previous frame */
float *interp_qlsp; /* Interpolated quantized LSPs */
float *interp_qlpc; /* Interpolated quantized LPCs */
- float *bw_lpc1; /* LPCs after bandwidth expansion by gamma1 for perceptual weighting*/
- float *bw_lpc2; /* LPCs after bandwidth expansion by gamma2 for perceptual weighting*/
-
+ float *mem_sp;
} DecState;
/**Initializes encoder state*/
diff --git a/libspeex/testenc.c b/libspeex/testenc.c
index 23f57ef..3085621 100644
--- a/libspeex/testenc.c
+++ b/libspeex/testenc.c
@@ -9,16 +9,18 @@ int main(int argc, char **argv)
char *inFile, *outFile, *bitsFile;
FILE *fin, *fout, *fbits=NULL;
short in[FRAME_SIZE];
- float input[FRAME_SIZE], bak[FRAME_SIZE], bak2[FRAME_SIZE];
+ float input[FRAME_SIZE], bak[FRAME_SIZE], bak2[FRAME_SIZE], decbuf[FRAME_SIZE];
char cbits[200];
int nbBits;
int i;
EncState st;
+ DecState dec;
FrameBits bits;
for (i=0;i<FRAME_SIZE;i++)
bak2[i]=0;
encoder_init(&st, &nb_mode);
+ decoder_init(&dec, &nb_mode);
if (argc != 4 && argc != 3)
{
fprintf (stderr, "Usage: encode [in file] [out file] [bits file]\nargc = %d", argc);
@@ -55,6 +57,10 @@ int main(int argc, char **argv)
snr = 10*log10((esig+1)/(enoise+1));
printf ("real SNR = %f\n", snr);
}
+ frame_bits_rewind(&bits);
+
+ decode(&dec, &bits, decbuf);
+
/* Save the bits here */
frame_bits_reset(&bits);
for (i=0;i<FRAME_SIZE;i++)
@@ -65,5 +71,6 @@ int main(int argc, char **argv)
}
encoder_destroy(&st);
+ decoder_destroy(&dec);
return 1;
}