Commit 6008abea authored by Jean-Marc Valin's avatar Jean-Marc Valin
Browse files

Making it possible to disable either the encoder or the decoder using macros

parent 8d225323
......@@ -49,6 +49,8 @@
#include "cb_search_bfin.h"
#endif
#ifndef DISABLE_ENCODER
#ifndef OVERRIDE_COMPUTE_WEIGHTED_CODEBOOK
static void compute_weighted_codebook(const signed char *shape_cb, const spx_word16_t *r, spx_word16_t *resp, spx_word16_t *resp2, spx_word32_t *E, int shape_cb_size, int subvect_size, char *stack)
{
......@@ -509,8 +511,9 @@ int update_target
target[j]=SUB16(target[j],PSHR16(r2[j],2));
}
}
#endif /* DISABLE_ENCODER */
#ifndef DISABLE_DECODER
void split_cb_shape_sign_unquant(
spx_sig_t *exc,
const void *par, /* non-overlapping codebook */
......@@ -568,7 +571,9 @@ spx_int32_t *seed
#endif
}
}
#endif /* DISABLE_DECODER */
#ifndef DISABLE_ENCODER
void noise_codebook_quant(
spx_word16_t target[], /* target vector */
spx_coef_t ak[], /* LPCs for this subframe */
......@@ -594,8 +599,9 @@ int update_target
exc[i]+=SHL32(EXTEND32(tmp[i]),8);
SPEEX_MEMSET(target, 0, nsf);
}
#endif /* DISABLE_ENCODER */
#ifndef DISABLE_DECODER
void noise_codebook_unquant(
spx_sig_t *exc,
const void *par, /* non-overlapping codebook */
......@@ -610,3 +616,4 @@ spx_int32_t *seed
for (i=0;i<nsf;i++)
exc[i]=SHL32(EXTEND32(speex_rand(1, seed)),SIG_SHIFT);
}
#endif /* DISABLE_DECODER */
......@@ -119,6 +119,7 @@ void signal_mul(const spx_sig_t *x, spx_sig_t *y, spx_word32_t scale, int len)
}
}
#ifndef DISABLE_ENCODER
void signal_div(const spx_word16_t *x, spx_word16_t *y, spx_word32_t scale, int len)
{
int i;
......@@ -151,8 +152,9 @@ void signal_div(const spx_word16_t *x, spx_word16_t *y, spx_word32_t scale, int
}
}
}
#endif /* DISABLE_ENCODER */
#else
#else /* FIXED_POINT */
void signal_mul(const spx_sig_t *x, spx_sig_t *y, spx_word32_t scale, int len)
{
......@@ -161,6 +163,7 @@ void signal_mul(const spx_sig_t *x, spx_sig_t *y, spx_word32_t scale, int len)
y[i] = scale*x[i];
}
#ifndef DISABLE_ENCODER
void signal_div(const spx_sig_t *x, spx_sig_t *y, spx_word32_t scale, int len)
{
int i;
......@@ -168,7 +171,9 @@ void signal_div(const spx_sig_t *x, spx_sig_t *y, spx_word32_t scale, int len)
for (i=0;i<len;i++)
y[i] = scale_1*x[i];
}
#endif
#endif /* DISABLE_ENCODER */
#endif /* !FIXED_POINT */
......@@ -176,6 +181,7 @@ void signal_div(const spx_sig_t *x, spx_sig_t *y, spx_word32_t scale, int len)
#if !defined (DISABLE_WIDEBAND) && !defined (DISABLE_ENCODER)
spx_word16_t compute_rms(const spx_sig_t *x, int len)
{
int i;
......@@ -216,6 +222,7 @@ spx_word16_t compute_rms(const spx_sig_t *x, int len)
return EXTRACT16(PSHR32(SHL32(EXTEND32(spx_sqrt(DIV32(sum,len))),(sig_shift+3)),SIG_SHIFT));
}
#endif /* !defined (DISABLE_WIDEBAND) && !defined (DISABLE_ENCODER) */
spx_word16_t compute_rms16(const spx_word16_t *x, int len)
{
......@@ -315,7 +322,7 @@ spx_word16_t compute_rms16(const spx_word16_t *x, int len)
#ifndef OVERRIDE_FILTER_MEM16
#if !defined(OVERRIDE_FILTER_MEM16) && !defined(DISABLE_ENCODER)
void filter_mem16(const spx_word16_t *x, const spx_coef_t *num, const spx_coef_t *den, spx_word16_t *y, int N, int ord, spx_mem_t *mem, char *stack)
{
int i,j;
......@@ -333,7 +340,7 @@ void filter_mem16(const spx_word16_t *x, const spx_coef_t *num, const spx_coef_t
y[i] = yi;
}
}
#endif
#endif /* !defined(OVERRIDE_FILTER_MEM16) && !defined(DISABLE_ENCODER) */
#ifndef OVERRIDE_IIR_MEM16
void iir_mem16(const spx_word16_t *x, const spx_coef_t *den, spx_word16_t *y, int N, int ord, spx_mem_t *mem, char *stack)
......@@ -355,7 +362,7 @@ void iir_mem16(const spx_word16_t *x, const spx_coef_t *den, spx_word16_t *y, in
}
#endif
#ifndef OVERRIDE_FIR_MEM16
#if !defined(OVERRIDE_FIR_MEM16) && !defined(DISABLE_ENCODER)
void fir_mem16(const spx_word16_t *x, const spx_coef_t *num, spx_word16_t *y, int N, int ord, spx_mem_t *mem, char *stack)
{
int i,j;
......@@ -373,9 +380,9 @@ void fir_mem16(const spx_word16_t *x, const spx_coef_t *num, spx_word16_t *y, in
y[i] = yi;
}
}
#endif
#endif /* !defined(OVERRIDE_FIR_MEM16) && !defined(DISABLE_ENCODER) */
#ifndef DISABLE_ENCODER
void syn_percep_zero16(const spx_word16_t *xx, const spx_coef_t *ak, const spx_coef_t *awk1, const spx_coef_t *awk2, spx_word16_t *y, int N, int ord, char *stack)
{
int i;
......@@ -400,9 +407,9 @@ void residue_percep_zero16(const spx_word16_t *xx, const spx_coef_t *ak, const s
mem[i]=0;
fir_mem16(y, awk2, y, N, ord, mem, stack);
}
#endif /* DISABLE_ENCODER */
#ifndef OVERRIDE_COMPUTE_IMPULSE_RESPONSE
#if !defined(OVERRIDE_COMPUTE_IMPULSE_RESPONSE) && !defined(DISABLE_ENCODER)
void compute_impulse_response(const spx_coef_t *ak, const spx_coef_t *awk1, const spx_coef_t *awk2, spx_word16_t *y, int N, int ord, char *stack)
{
int i,j;
......@@ -435,8 +442,9 @@ void compute_impulse_response(const spx_coef_t *ak, const spx_coef_t *awk1, cons
mem2[ord-1] = MULT16_16(ak[ord-1],ny2i);
}
}
#endif
#endif /* !defined(OVERRIDE_COMPUTE_IMPULSE_RESPONSE) && !defined(DISABLE_ENCODER) */
#ifndef DISABLE_WIDEBAND
/* Decomposes a signal into low-band and high-band using a QMF */
void qmf_decomp(const spx_word16_t *xx, const spx_word16_t *aa, spx_word16_t *y1, spx_word16_t *y2, int N, int M, spx_word16_t *mem, char *stack)
{
......@@ -564,6 +572,10 @@ void qmf_synth(const spx_word16_t *x1, const spx_word16_t *x2, const spx_word16_
for (i = 0; i < M2; i++)
mem2[2*i+1] = xx2[i];
}
#endif /* DISABLE_WIDEBAND */
#ifndef DISABLE_DECODER
#ifdef FIXED_POINT
#if 0
......@@ -819,3 +831,4 @@ char *stack
#endif
}
#endif /* DISABLE_DECODER */
......@@ -53,6 +53,8 @@
#include "config.h"
#endif
#ifndef DISABLE_ENCODER
#include "lpc.h"
#ifdef BFIN_ASM
......@@ -199,3 +201,4 @@ int n
#endif
#endif /* DISABLE_ENCODER */
......@@ -122,6 +122,7 @@ Heavily modified by Jean-Marc Valin (c) 2002-2006 (fixed-point,
#endif
#ifndef DISABLE_ENCODER
/*---------------------------------------------------------------------------*\
......@@ -387,6 +388,7 @@ int lpc_to_lsp (spx_coef_t *a,int lpcrdr,spx_lsp_t *freq,int nb,spx_word16_t del
return(roots);
}
#endif /* DISABLE_ENCODER */
/*---------------------------------------------------------------------------*\
FUNCTION....: lsp_to_lpc()
......
......@@ -74,6 +74,8 @@ spx_word32_t inner_prod(const spx_word16_t *x, const spx_word16_t *y, int len)
}
#endif
#ifndef DISABLE_ENCODER
#ifndef OVERRIDE_PITCH_XCORR
#if 0 /* HINT: Enable this for machines with enough registers (i.e. not x86) */
void pitch_xcorr(const spx_word16_t *_x, const spx_word16_t *_y, spx_word32_t *corr, int len, int nb_pitch, char *stack)
......@@ -651,7 +653,9 @@ spx_word32_t *cumul_gain
#endif
return pitch;
}
#endif /* DISABLE_ENCODER */
#ifndef DISABLE_DECODER
void pitch_unquant_3tap(
spx_word16_t exc[], /* Input excitation */
spx_word32_t exc_out[], /* Output excitation */
......@@ -749,8 +753,9 @@ int cdbk_offset
/*for (i=0;i<nsf;i++)
exc[i]=PSHR32(exc32[i],13);*/
}
#endif /* DISABLE_DECODER */
#ifndef DISABLE_ENCODER
/** Forced pitch delay and gain */
int forced_pitch_quant(
spx_word16_t target[], /* Target vector */
......@@ -800,7 +805,9 @@ spx_word32_t *cumul_gain
target[i]=EXTRACT16(SATURATE(SUB32(EXTEND32(target[i]),EXTEND32(res[i])),32700));
return start;
}
#endif /* DISABLE_ENCODER */
#ifndef DISABLE_DECODER
/** Unquantize forced pitch delay and gain */
void forced_pitch_unquant(
spx_word16_t exc[], /* Input excitation */
......@@ -837,3 +844,4 @@ int cdbk_offset
gain_val[0]=gain_val[2]=0;
gain_val[1] = pitch_coef;
}
#endif /* DISABLE_DECODER */
......@@ -42,7 +42,7 @@
Valin, J.-M., On Adjusting the Learning Rate in Frequency Domain Echo
Cancellation With Double-Talk. IEEE Transactions on Audio,
Speech and Language Processing, V<ol. 15, No. 3, pp. 1030-1034, 2007.
Speech and Language Processing, Vol. 15, No. 3, pp. 1030-1034, 2007.
http://people.xiph.org/~jm/papers/valin_taslp2006.pdf
There is no explicit double-talk detection, but a continuous variation
......
......@@ -50,6 +50,33 @@
#define NULL 0
#endif
#ifdef DISABLE_ENCODER
#define nb_encoder_init NULL
#define nb_encoder_destroy NULL
#define nb_encode NULL
#define nb_encoder_ctl NULL
#define split_cb_search_shape_sign NULL
#define noise_codebook_quant NULL
#define pitch_search_3tap NULL
#define forced_pitch_quant NULL
#define lsp_quant_nb NULL
#define lsp_quant_lbr NULL
#endif /* DISABLE_ENCODER */
#ifdef DISABLE_DECODER
#define nb_decoder_init NULL
#define nb_decoder_destroy NULL
#define nb_decode NULL
#define nb_decoder_ctl NULL
#define noise_codebook_unquant NULL
#define split_cb_shape_sign_unquant NULL
#define lsp_unquant_nb NULL
#define lsp_unquant_lbr NULL
#define pitch_unquant_3tap NULL
#define forced_pitch_unquant NULL
#endif /* DISABLE_DECODER */
/* Extern declarations for all codebooks we use here */
extern const signed char gain_cdbk_nb[];
......@@ -343,14 +370,14 @@ EXPORT const SpeexMode speex_nb_mode = {
"narrowband",
0,
4,
&nb_encoder_init,
&nb_encoder_destroy,
&nb_encode,
&nb_decoder_init,
&nb_decoder_destroy,
&nb_decode,
&nb_encoder_ctl,
&nb_decoder_ctl,
nb_encoder_init,
nb_encoder_destroy,
nb_encode,
nb_decoder_init,
nb_decoder_destroy,
nb_decode,
nb_encoder_ctl,
nb_decoder_ctl,
};
......
......@@ -52,6 +52,28 @@
#define NULL 0
#endif
#if defined(DISABLE_ENCODER) || defined(DISABLE_WIDEBAND)
#define split_cb_search_shape_sign NULL
#define noise_codebook_quant NULL
#define pitch_search_3tap NULL
#define forced_pitch_quant NULL
#define sb_encoder_init NULL
#define sb_encoder_destroy NULL
#define sb_encode NULL
#define sb_encoder_ctl NULL
#define lsp_quant_high NULL
#endif /* DISABLE_ENCODER */
#if defined(DISABLE_DECODER) || defined(DISABLE_WIDEBAND)
#define noise_codebook_unquant NULL
#define split_cb_shape_sign_unquant NULL
#define lsp_unquant_high NULL
#define sb_decoder_init NULL
#define sb_decoder_destroy NULL
#define sb_decode NULL
#define sb_decoder_ctl NULL
#endif /* DISABLE_DECODER */
EXPORT const SpeexMode * const speex_mode_list[SPEEX_NB_MODES] = {&speex_nb_mode, &speex_wb_mode, &speex_uwb_mode};
extern const signed char hexc_table[];
......@@ -206,14 +228,14 @@ EXPORT const SpeexMode speex_wb_mode = {
"wideband (sub-band CELP)",
1,
4,
&sb_encoder_init,
&sb_encoder_destroy,
&sb_encode,
&sb_decoder_init,
&sb_decoder_destroy,
&sb_decode,
&sb_encoder_ctl,
&sb_decoder_ctl,
sb_encoder_init,
sb_encoder_destroy,
sb_encode,
sb_decoder_init,
sb_decoder_destroy,
sb_decode,
sb_encoder_ctl,
sb_decoder_ctl,
};
......@@ -276,14 +298,14 @@ EXPORT const SpeexMode speex_uwb_mode = {
"ultra-wideband (sub-band CELP)",
2,
4,
&sb_encoder_init,
&sb_encoder_destroy,
&sb_encode,
&sb_decoder_init,
&sb_decoder_destroy,
&sb_decode,
&sb_encoder_ctl,
&sb_decoder_ctl,
sb_encoder_init,
sb_encoder_destroy,
sb_encode,
sb_decoder_init,
sb_decoder_destroy,
sb_decode,
sb_encoder_ctl,
sb_decoder_ctl,
};
/* We have defined speex_lib_get_mode() as a macro in speex.h */
......
This diff is collapsed.
......@@ -68,6 +68,7 @@
#endif
#ifndef DISABLE_ENCODER
static void compute_quant_weights(spx_lsp_t *qlsp, spx_word16_t *quant_weight, int order)
{
int i;
......@@ -209,7 +210,9 @@ void lsp_quant_nb(spx_lsp_t *lsp, spx_lsp_t *qlsp, int order, SpeexBits *bits)
for (i=0;i<order;i++)
qlsp[i]=lsp[i]-qlsp[i];
}
#endif /* DISABLE_ENCODER */
#ifndef DISABLE_DECODER
void lsp_unquant_nb(spx_lsp_t *lsp, int order, SpeexBits *bits)
{
int i, id;
......@@ -237,8 +240,9 @@ void lsp_unquant_nb(spx_lsp_t *lsp, int order, SpeexBits *bits)
for (i=0;i<5;i++)
lsp[i+5] = ADD32(lsp[i+5], LSP_DIV_1024(cdbk_nb_high2[id*5+i]));
}
#endif /* DISABLE_DECODER */
#ifndef DISABLE_ENCODER
void lsp_quant_lbr(spx_lsp_t *lsp, spx_lsp_t *qlsp, int order, SpeexBits *bits)
{
int i;
......@@ -279,7 +283,9 @@ void lsp_quant_lbr(spx_lsp_t *lsp, spx_lsp_t *qlsp, int order, SpeexBits *bits)
for (i=0;i<order;i++)
qlsp[i]=lsp[i]-qlsp[i];
}
#endif /* DISABLE_ENCODER */
#ifndef DISABLE_DECODER
void lsp_unquant_lbr(spx_lsp_t *lsp, int order, SpeexBits *bits)
{
int i, id;
......@@ -300,22 +306,13 @@ void lsp_unquant_lbr(spx_lsp_t *lsp, int order, SpeexBits *bits)
lsp[i+5] += LSP_DIV_512(cdbk_nb_high1[id*5+i]);
}
#endif /* DISABLE_DECODER */
#ifdef DISABLE_WIDEBAND
void lsp_quant_high(spx_lsp_t *lsp, spx_lsp_t *qlsp, int order, SpeexBits *bits)
{
speex_fatal("Wideband and Ultra-wideband are disabled");
}
void lsp_unquant_high(spx_lsp_t *lsp, int order, SpeexBits *bits)
{
speex_fatal("Wideband and Ultra-wideband are disabled");
}
#else
#ifndef DISABLE_WIDEBAND
extern const signed char high_lsp_cdbk[];
extern const signed char high_lsp_cdbk2[];
#ifndef DISABLE_ENCODER
void lsp_quant_high(spx_lsp_t *lsp, spx_lsp_t *qlsp, int order, SpeexBits *bits)
{
int i;
......@@ -362,7 +359,10 @@ void lsp_quant_high(spx_lsp_t *lsp, spx_lsp_t *qlsp, int order, SpeexBits *bits)
for (i=0;i<order;i++)
qlsp[i]=lsp[i]-qlsp[i];
}
#endif /* DISABLE_ENCODER */
#ifndef DISABLE_DECODER
void lsp_unquant_high(spx_lsp_t *lsp, int order, SpeexBits *bits)
{
......@@ -380,6 +380,7 @@ void lsp_unquant_high(spx_lsp_t *lsp, int order, SpeexBits *bits)
for (i=0;i<order;i++)
lsp[i] += LSP_DIV_512(high_lsp_cdbk2[id*order+i]);
}
#endif /* DISABLE_DECODER */
#endif
#endif /* DISABLE_WIDEBAND */
This diff is collapsed.
......@@ -104,6 +104,7 @@ EXPORT void speex_stereo_state_destroy(SpeexStereoState *stereo)
speex_free(stereo);
}
#ifndef DISABLE_ENCODER
#ifndef DISABLE_FLOAT_API
EXPORT void speex_encode_stereo(float *data, int frame_size, SpeexBits *bits)
{
......@@ -216,6 +217,12 @@ EXPORT void speex_encode_stereo_int(spx_int16_t *data, int frame_size, SpeexBits
/*fprintf (stderr, "%d %d %d %d\n", largest, smallest, balance_id, e_ratio);*/
speex_bits_pack(bits, tmp, 2);
}
#else /* DISABLE_ENCODER */
EXPORT void speex_encode_stereo_int(spx_int16_t *data, int frame_size, SpeexBits *bits)
{
}
#endif /* DISABLE_ENCODER */
#ifndef DISABLE_FLOAT_API
EXPORT void speex_decode_stereo(float *data, int frame_size, SpeexStereoState *_stereo)
......
......@@ -47,7 +47,7 @@
#include "vq_bfin.h"
#endif
#ifndef DISABLE_ENCODER
int scal_quant(spx_word16_t in, const spx_word16_t *boundary, int entries)
{
int i=0;
......@@ -69,9 +69,9 @@ int scal_quant32(spx_word32_t in, const spx_word32_t *boundary, int entries)
}
return i;
}
#endif /* DISABLE_ENCODER */
#ifndef OVERRIDE_VQ_NBEST
#if !defined(OVERRIDE_VQ_NBEST) && !defined(DISABLE_ENCODER)
/*Finds the indices of the n-best entries in a codebook*/
void vq_nbest(spx_word16_t *in, const spx_word16_t *codebook, int len, int entries, spx_word32_t *E, int N, int *nbest, spx_word32_t *best_dist, char *stack)
{
......@@ -100,12 +100,12 @@ void vq_nbest(spx_word16_t *in, const spx_word16_t *codebook, int len, int entri
}
}
}
#endif
#endif /* !defined(OVERRIDE_VQ_NBEST) && !defined(DISABLE_ENCODER) */
#ifndef OVERRIDE_VQ_NBEST_SIGN
#if !defined(OVERRIDE_VQ_NBEST_SIGN) && !defined(DISABLE_WIDEBAND) && !defined(DISABLE_ENCODER)
/*Finds the indices of the n-best entries in a codebook with sign*/
void vq_nbest_sign(spx_word16_t *in, const spx_word16_t *codebook, int len, int entries, spx_word32_t *E, int N, int *nbest, spx_word32_t *best_dist, char *stack)
{
......@@ -144,4 +144,4 @@ void vq_nbest_sign(spx_word16_t *in, const spx_word16_t *codebook, int len, int
}
}
}
#endif
#endif /* !defined(OVERRIDE_VQ_NBEST_SIGN) && !defined(DISABLE_WIDEBAND) && !defined(DISABLE_ENCODER) */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment