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-04-09 11:23:14 +0400
committerjmvalin <jmvalin@0101bb08-14d6-0310-b084-bc0e0c8e3800>2002-04-09 11:23:14 +0400
commit8779e5efb32b9dd232e4f3911153b041aa8ded36 (patch)
tree4fccc36e277b61ff21765ed730429973e850a86d /libspeex
parent4a4ab086e40fad73c8222988efc5413bd2e14aab (diff)
More decoder work
git-svn-id: http://svn.xiph.org/trunk/speex@3231 0101bb08-14d6-0310-b084-bc0e0c8e3800
Diffstat (limited to 'libspeex')
-rw-r--r--libspeex/cb_search.c43
-rw-r--r--libspeex/sb_celp.c104
-rw-r--r--libspeex/sb_celp.h40
3 files changed, 126 insertions, 61 deletions
diff --git a/libspeex/cb_search.c b/libspeex/cb_search.c
index 7b7e9e9..2a3e766 100644
--- a/libspeex/cb_search.c
+++ b/libspeex/cb_search.c
@@ -187,12 +187,15 @@ float *stack
/* Quantize global (average) gain */
{
float q;
+ int id;
q=log(exc_energy+.1);
q=floor(.5+2*(q-2));
if (q<0)
q=0;
if (q>15)
q=15;
+ id = (int)q;
+ frame_bits_pack(bits, id, 4);
exc_energy=exp(.5*q+2);
}
@@ -229,6 +232,7 @@ float *stack
best_gain=corr/(.001+E[j]);
}
}
+ frame_bits_pack(bits,best_index,params->shape_bits);
{
int s=0, best_id, j;
float best_dist;
@@ -251,16 +255,13 @@ float *stack
}
}
best_gain=scal_gains4[best_id];
- printf ("gain_quant: %f %d %f\n", best_gain, best_id, scal_gains4[best_id]);
+ /*printf ("gain_quant: %f %d %f\n", best_gain, best_id, scal_gains4[best_id]);*/
if (s)
best_gain=-best_gain;
best_gain *= exc_energy;
+ frame_bits_pack(bits,s,1);
+ frame_bits_pack(bits,best_id,3);
}
- frame_bits_pack(bits,best_index,params->shape_bits);
- if (best_gain>0)
- frame_bits_pack(bits,0,1);
- else
- frame_bits_pack(bits,1,1);
ind[i]=best_index;
gains[i]=best_gain;
@@ -275,27 +276,21 @@ float *stack
tresp[i*nsf+j]=r[j];
for (j=0;j<nsf;j++)
t[j]-=r[j];
- /*for (j=0;j<nsf;j++)
- exc[j]+=e[j];*/
}
- {
- printf ("exc_gains");
- for (i=0;i<nb_subvect;i++)
- printf (" %f", gains[i]/(.01f+exc_energy));
- printf ("\n");
- for (i=0;i<nb_subvect;i++)
- for (j=0;j<subvect_size;j++)
- e[subvect_size*i+j]=gains[i]*shape_cb[ind[i]*subvect_size+j];
+
+ for (i=0;i<nb_subvect;i++)
+ for (j=0;j<subvect_size;j++)
+ e[subvect_size*i+j]=gains[i]*shape_cb[ind[i]*subvect_size+j];
- for (j=0;j<nsf;j++)
- exc[j]+=e[j];
- residue_zero(e, awk1, r, nsf, p);
- syn_filt_zero(r, ak, r, nsf, p);
- syn_filt_zero(r, awk2, r, nsf,p);
- for (j=0;j<nsf;j++)
- target[j]-=r[j];
+ for (j=0;j<nsf;j++)
+ exc[j]+=e[j];
+ residue_zero(e, awk1, r, nsf, p);
+ syn_filt_zero(r, ak, r, nsf, p);
+ syn_filt_zero(r, awk2, r, nsf,p);
+ for (j=0;j<nsf;j++)
+ target[j]-=r[j];
- }
+
POP(stack);
diff --git a/libspeex/sb_celp.c b/libspeex/sb_celp.c
index 112ed6b..dfcf456 100644
--- a/libspeex/sb_celp.c
+++ b/libspeex/sb_celp.c
@@ -214,7 +214,6 @@ void sb_encoder_init(SBEncState *st, SpeexMode *mode)
st->buf=calloc(st->windowSize, sizeof(float));
st->excBuf=calloc(2*st->frame_size, sizeof(float));
st->exc=st->excBuf+st->frame_size;
- st->exc_alias=calloc(st->frame_size, sizeof(float));
st->res=calloc(st->frame_size, sizeof(float));
st->sw=calloc(st->frame_size, sizeof(float));
@@ -223,10 +222,6 @@ void sb_encoder_init(SBEncState *st, SpeexMode *mode)
for (i=0;i<st->windowSize;i++)
st->window[i]=.5*(1-cos(2*M_PI*i/st->windowSize));
- st->exc_window=calloc(st->frame_size, sizeof(float));
- for (i=0;i<st->frame_size;i++)
- st->exc_window[i]=.5*(1-cos(2*M_PI*i/st->frame_size));
-
st->lagWindow = malloc((st->lpcSize+1)*sizeof(float));
for (i=0;i<st->lpcSize+1;i++)
st->lagWindow[i]=exp(-.5*sqr(2*M_PI*st->lag_factor*i));
@@ -248,7 +243,6 @@ void sb_encoder_init(SBEncState *st, SpeexMode *mode)
st->mem_sp = calloc(st->lpcSize, sizeof(float));
st->mem_sp2 = calloc(st->lpcSize, sizeof(float));
st->mem_sw = calloc(st->lpcSize, sizeof(float));
- st->mem_exc = calloc(st->lpcSize, sizeof(float));
}
@@ -289,6 +283,7 @@ void sb_encoder_destroy(SBEncState *st)
free(st->interp_qlpc);
free(st->mem_sp);
+ free(st->mem_sp2);
free(st->mem_sw);
free(st->stack);
@@ -345,30 +340,6 @@ void sb_encode(SBEncState *st, float *in, FrameBits *bits)
exit(1);
}
- {
- for (i=0;i<st->frame_size;i++)
- st->buf[i] = st->st_low.exc[i] * st->exc_window[i];
-
- /* Compute auto-correlation */
- autocorr(st->buf, st->autocorr, st->lpcSize+1, st->frame_size);
-
- st->autocorr[0] += 1; /* prevents NANs */
- st->autocorr[0] *= st->lpc_floor; /* Noise floor in auto-correlation domain */
- /* Lag windowing: equivalent to filtering in the power-spectrum domain */
- for (i=0;i<st->lpcSize+1;i++)
- st->autocorr[i] *= st->lagWindow[i];
-
- /* Levinson-Durbin */
- wld(st->lpc+1, st->autocorr, st->rc, st->lpcSize);
- st->lpc[0]=1;
- printf ("exc_lpc: ");
- for(i=0;i<=st->lpcSize;i++)
- printf ("%f ", st->lpc[i]);
- printf ("\n");
- residue_mem(st->st_low.exc, st->lpc, st->exc_alias, st->frame_size, st->lpcSize, st->mem_exc);
- }
-
-
/* x-domain to angle domain*/
for (i=0;i<st->lpcSize;i++)
st->lsp[i] = acos(st->lsp[i]);
@@ -447,8 +418,6 @@ void sb_encode(SBEncState *st, float *in, FrameBits *bits)
float el=0,eh=0,g;
for (i=0;i<st->subframeSize;i++)
eh+=sqr(exc[i]);
- /*for (i=0;i<st->subframeSize;i++)
- el+=sqr(st->exc_alias[offset+i]);*/
for (i=0;i<st->subframeSize;i++)
el+=sqr(st->st_low.exc[offset+i]);
g=eh/(.01+el);
@@ -456,8 +425,6 @@ void sb_encode(SBEncState *st, float *in, FrameBits *bits)
g=sqrt(g);
for (i=0;i<st->subframeSize;i++)
exc[i]=g*st->st_low.exc[offset+i];
- /*for (i=0;i<st->subframeSize;i++)
- exc[i]=g*st->exc_alias[offset+i];*/
}
syn_filt_mem(exc, st->interp_qlpc, sp, st->subframeSize, st->lpcSize, mem);
@@ -628,3 +595,72 @@ void sb_encode(SBEncState *st, float *in, FrameBits *bits)
st->first=0;
}
+
+
+
+
+
+void sb_decoder_init(SBDecState *st, SpeexMode *mode)
+{
+ decoder_init(&st->st_low, mode);
+ st->full_frame_size = 2*st->st_low.frameSize;
+ st->frame_size = st->st_low.frameSize;
+ st->subframeSize = 40;
+ st->nbSubframes = 4;
+ st->lpcSize=8;
+
+ st->first=1;
+ st->stack = calloc(10000, sizeof(float));
+
+ st->x0=calloc(st->full_frame_size, sizeof(float));
+ st->x1=calloc(st->full_frame_size, sizeof(float));
+ st->x0d=calloc(st->frame_size, sizeof(float));
+ st->x1d=calloc(st->frame_size, sizeof(float));
+ st->high=calloc(st->full_frame_size, sizeof(float));
+ st->y0=calloc(st->full_frame_size, sizeof(float));
+ st->y1=calloc(st->full_frame_size, sizeof(float));
+
+ st->h0_mem=calloc(QMF_ORDER, sizeof(float));
+ st->h1_mem=calloc(QMF_ORDER, sizeof(float));
+ st->g0_mem=calloc(QMF_ORDER, sizeof(float));
+ st->g1_mem=calloc(QMF_ORDER, sizeof(float));
+
+ st->exc=calloc(st->frame_size, 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->interp_qlpc = malloc((st->lpcSize+1)*sizeof(float));
+
+ st->mem_sp = calloc(st->lpcSize, sizeof(float));
+ st->mem_sw = calloc(st->lpcSize, sizeof(float));
+
+}
+
+void sb_decoder_destroy(SBDecState *st)
+{
+ decoder_destroy(&st->st_low);
+ free(st->x0);
+ free(st->x0d);
+ free(st->x1);
+ free(st->x1d);
+ free(st->high);
+ free(st->y0);
+ free(st->y1);
+ free(st->h0_mem);
+ free(st->h1_mem);
+ free(st->g0_mem);
+ free(st->g1_mem);
+
+ free(st->exc);
+ free(st->qlsp);
+ free(st->old_qlsp);
+ free(st->interp_qlsp);
+ free(st->interp_qlpc);
+
+ free(st->mem_sp);
+ free(st->mem_sw);
+
+ free(st->stack);
+
+}
diff --git a/libspeex/sb_celp.h b/libspeex/sb_celp.h
index 7068c3e..020b31d 100644
--- a/libspeex/sb_celp.h
+++ b/libspeex/sb_celp.h
@@ -47,13 +47,11 @@ typedef struct SBEncState {
float *excBuf;
float *exc;
- float *exc_alias;
float *buf;
float *res;
float *sw;
float *target;
float *window;
- float *exc_window;
float *lagWindow;
float *autocorr;
float *rc;
@@ -72,10 +70,36 @@ typedef struct SBEncState {
float *mem_sp;
float *mem_sp2;
float *mem_sw;
- float *mem_exc;
} SBEncState;
+/**Structure representing the full state of the decoder*/
+typedef struct SBDecState {
+ DecState st_low;
+ int full_frame_size;
+ int frame_size;
+ int subframeSize;
+ int nbSubframes;
+ int lpcSize;
+ int first;
+
+ float *stack;
+ float *x0, *x0d, *x1, *x1d;
+ float *high;
+ float *y0, *y1;
+ float *h0_mem, *h1_mem, *g0_mem, *g1_mem;
+
+ float *exc;
+ float *qlsp;
+ float *old_qlsp;
+ float *interp_qlsp;
+ float *interp_qlpc;
+
+ float *mem_sp;
+ float *mem_sw;
+} SBDecState;
+
+
/**Initializes encoder state*/
void sb_encoder_init(SBEncState *st, SpeexMode *mode);
@@ -86,4 +110,14 @@ void sb_encoder_destroy(SBEncState *st);
void sb_encode(SBEncState *st, float *in, FrameBits *bits);
+/**Initializes decoder state*/
+void sb_decoder_init(SBDecState *st, SpeexMode *mode);
+
+/**De-allocates decoder state resources*/
+void sb_decoder_destroy(SBDecState *st);
+
+/**Decodes one frame*/
+void sb_decode(SBDecState *st, FrameBits *bits, float *out);
+
+
#endif