diff options
author | Jean-Marc Valin <jeval@station513.(none)> | 2008-08-06 19:30:45 +0400 |
---|---|---|
committer | Jean-Marc Valin <jeval@station513.(none)> | 2008-08-06 19:30:45 +0400 |
commit | 6008abea50f28f4e89a46c357952e2253072c494 (patch) | |
tree | f23f48076204442516c4823f634cab04dec800f5 | |
parent | 8d225323179a4642c58df0466beb960b0b367f29 (diff) |
Making it possible to disable either the encoder or the decoder using macros
-rw-r--r-- | libspeex/cb_search.c | 11 | ||||
-rw-r--r-- | libspeex/filters.c | 33 | ||||
-rw-r--r-- | libspeex/lpc.c | 3 | ||||
-rw-r--r-- | libspeex/lsp.c | 2 | ||||
-rw-r--r-- | libspeex/ltp.c | 10 | ||||
-rw-r--r-- | libspeex/mdf.c | 2 | ||||
-rw-r--r-- | libspeex/modes.c | 43 | ||||
-rw-r--r-- | libspeex/modes_wb.c | 54 | ||||
-rw-r--r-- | libspeex/nb_celp.c | 671 | ||||
-rw-r--r-- | libspeex/quant_lsp.c | 29 | ||||
-rw-r--r-- | libspeex/sb_celp.c | 822 | ||||
-rw-r--r-- | libspeex/stereo.c | 7 | ||||
-rw-r--r-- | libspeex/vq.c | 12 |
13 files changed, 881 insertions, 818 deletions
diff --git a/libspeex/cb_search.c b/libspeex/cb_search.c index 63f4c6a..fa96dac 100644 --- a/libspeex/cb_search.c +++ b/libspeex/cb_search.c @@ -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 */ diff --git a/libspeex/filters.c b/libspeex/filters.c index 36ef4f6..d7c950e 100644 --- a/libspeex/filters.c +++ b/libspeex/filters.c @@ -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 */ diff --git a/libspeex/lpc.c b/libspeex/lpc.c index fd5d382..46cdd21 100644 --- a/libspeex/lpc.c +++ b/libspeex/lpc.c @@ -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 */ diff --git a/libspeex/lsp.c b/libspeex/lsp.c index a73d883..7e63dbc 100644 --- a/libspeex/lsp.c +++ b/libspeex/lsp.c @@ -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() diff --git a/libspeex/ltp.c b/libspeex/ltp.c index 551ae0b..d07ade1 100644 --- a/libspeex/ltp.c +++ b/libspeex/ltp.c @@ -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 */ diff --git a/libspeex/mdf.c b/libspeex/mdf.c index 04c1df9..8a5c031 100644 --- a/libspeex/mdf.c +++ b/libspeex/mdf.c @@ -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 diff --git a/libspeex/modes.c b/libspeex/modes.c index c873b0e..91dc535 100644 --- a/libspeex/modes.c +++ b/libspeex/modes.c @@ -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, }; diff --git a/libspeex/modes_wb.c b/libspeex/modes_wb.c index e3b4842..cfbcdf6 100644 --- a/libspeex/modes_wb.c +++ b/libspeex/modes_wb.c @@ -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 */ diff --git a/libspeex/nb_celp.c b/libspeex/nb_celp.c index 98537c6..228c2fc 100644 --- a/libspeex/nb_celp.c +++ b/libspeex/nb_celp.c @@ -106,11 +106,10 @@ const float exc_gain_quant_scal1[2]={0.70469f, 1.05127f}; #endif -#define sqr(x) ((x)*(x)) - extern const spx_word16_t lag_window[]; extern const spx_word16_t lpc_window[]; +#ifndef DISABLE_ENCODER void *nb_encoder_init(const SpeexMode *m) { EncState *st; @@ -214,6 +213,212 @@ void nb_encoder_destroy(void *state) speex_free(st); } + +int nb_encoder_ctl(void *state, int request, void *ptr) +{ + EncState *st; + st=(EncState*)state; + switch(request) + { + case SPEEX_GET_FRAME_SIZE: + (*(spx_int32_t*)ptr) = st->frameSize; + break; + case SPEEX_SET_LOW_MODE: + case SPEEX_SET_MODE: + st->submodeSelect = st->submodeID = (*(spx_int32_t*)ptr); + break; + case SPEEX_GET_LOW_MODE: + case SPEEX_GET_MODE: + (*(spx_int32_t*)ptr) = st->submodeID; + break; +#ifndef DISABLE_VBR + case SPEEX_SET_VBR: + st->vbr_enabled = (*(spx_int32_t*)ptr); + break; + case SPEEX_GET_VBR: + (*(spx_int32_t*)ptr) = st->vbr_enabled; + break; + case SPEEX_SET_VAD: + st->vad_enabled = (*(spx_int32_t*)ptr); + break; + case SPEEX_GET_VAD: + (*(spx_int32_t*)ptr) = st->vad_enabled; + break; + case SPEEX_SET_DTX: + st->dtx_enabled = (*(spx_int32_t*)ptr); + break; + case SPEEX_GET_DTX: + (*(spx_int32_t*)ptr) = st->dtx_enabled; + break; + case SPEEX_SET_ABR: + st->abr_enabled = (*(spx_int32_t*)ptr); + st->vbr_enabled = st->abr_enabled!=0; + if (st->vbr_enabled) + { + spx_int32_t i=10; + spx_int32_t rate, target; + float vbr_qual; + target = (*(spx_int32_t*)ptr); + while (i>=0) + { + speex_encoder_ctl(st, SPEEX_SET_QUALITY, &i); + speex_encoder_ctl(st, SPEEX_GET_BITRATE, &rate); + if (rate <= target) + break; + i--; + } + vbr_qual=i; + if (vbr_qual<0) + vbr_qual=0; + speex_encoder_ctl(st, SPEEX_SET_VBR_QUALITY, &vbr_qual); + st->abr_count=0; + st->abr_drift=0; + st->abr_drift2=0; + } + + break; + case SPEEX_GET_ABR: + (*(spx_int32_t*)ptr) = st->abr_enabled; + break; +#endif /* #ifndef DISABLE_VBR */ +#if !defined(DISABLE_VBR) && !defined(DISABLE_FLOAT_API) + case SPEEX_SET_VBR_QUALITY: + st->vbr_quality = (*(float*)ptr); + break; + case SPEEX_GET_VBR_QUALITY: + (*(float*)ptr) = st->vbr_quality; + break; +#endif /* !defined(DISABLE_VBR) && !defined(DISABLE_FLOAT_API) */ + case SPEEX_SET_QUALITY: + { + int quality = (*(spx_int32_t*)ptr); + if (quality < 0) + quality = 0; + if (quality > 10) + quality = 10; + st->submodeSelect = st->submodeID = ((const SpeexNBMode*)(st->mode->mode))->quality_map[quality]; + } + break; + case SPEEX_SET_COMPLEXITY: + st->complexity = (*(spx_int32_t*)ptr); + if (st->complexity<0) + st->complexity=0; + break; + case SPEEX_GET_COMPLEXITY: + (*(spx_int32_t*)ptr) = st->complexity; + break; + case SPEEX_SET_BITRATE: + { + spx_int32_t i=10; + spx_int32_t rate, target; + target = (*(spx_int32_t*)ptr); + while (i>=0) + { + speex_encoder_ctl(st, SPEEX_SET_QUALITY, &i); + speex_encoder_ctl(st, SPEEX_GET_BITRATE, &rate); + if (rate <= target) + break; + i--; + } + } + break; + case SPEEX_GET_BITRATE: + if (st->submodes[st->submodeID]) + (*(spx_int32_t*)ptr) = st->sampling_rate*SUBMODE(bits_per_frame)/st->frameSize; + else + (*(spx_int32_t*)ptr) = st->sampling_rate*(NB_SUBMODE_BITS+1)/st->frameSize; + break; + case SPEEX_SET_SAMPLING_RATE: + st->sampling_rate = (*(spx_int32_t*)ptr); + break; + case SPEEX_GET_SAMPLING_RATE: + (*(spx_int32_t*)ptr)=st->sampling_rate; + break; + case SPEEX_RESET_STATE: + { + int i; + st->bounded_pitch = 1; + st->first = 1; + for (i=0;i<st->lpcSize;i++) + st->old_lsp[i]= DIV32(MULT16_16(QCONST16(3.1415927f, LSP_SHIFT), i+1), st->lpcSize+1); + for (i=0;i<st->lpcSize;i++) + st->mem_sw[i]=st->mem_sw_whole[i]=st->mem_sp[i]=st->mem_exc[i]=0; + for (i=0;i<st->frameSize+st->max_pitch+1;i++) + st->excBuf[i]=st->swBuf[i]=0; + for (i=0;i<st->windowSize-st->frameSize;i++) + st->winBuf[i]=0; + } + break; + case SPEEX_SET_SUBMODE_ENCODING: + st->encode_submode = (*(spx_int32_t*)ptr); + break; + case SPEEX_GET_SUBMODE_ENCODING: + (*(spx_int32_t*)ptr) = st->encode_submode; + break; + case SPEEX_GET_LOOKAHEAD: + (*(spx_int32_t*)ptr)=(st->windowSize-st->frameSize); + break; + case SPEEX_SET_PLC_TUNING: + st->plc_tuning = (*(spx_int32_t*)ptr); + if (st->plc_tuning>100) + st->plc_tuning=100; + break; + case SPEEX_GET_PLC_TUNING: + (*(spx_int32_t*)ptr)=(st->plc_tuning); + break; +#ifndef DISABLE_VBR + case SPEEX_SET_VBR_MAX_BITRATE: + st->vbr_max = (*(spx_int32_t*)ptr); + break; + case SPEEX_GET_VBR_MAX_BITRATE: + (*(spx_int32_t*)ptr) = st->vbr_max; + break; +#endif /* #ifndef DISABLE_VBR */ + case SPEEX_SET_HIGHPASS: + st->highpass_enabled = (*(spx_int32_t*)ptr); + break; + case SPEEX_GET_HIGHPASS: + (*(spx_int32_t*)ptr) = st->highpass_enabled; + break; + + /* This is all internal stuff past this point */ + case SPEEX_GET_PI_GAIN: + { + int i; + spx_word32_t *g = (spx_word32_t*)ptr; + for (i=0;i<st->nbSubframes;i++) + g[i]=st->pi_gain[i]; + } + break; + case SPEEX_GET_EXC: + { + int i; + for (i=0;i<st->nbSubframes;i++) + ((spx_word16_t*)ptr)[i] = compute_rms16(st->exc+i*st->subframeSize, st->subframeSize); + } + break; +#ifndef DISABLE_VBR + case SPEEX_GET_RELATIVE_QUALITY: + (*(float*)ptr)=st->relative_quality; + break; +#endif /* #ifndef DISABLE_VBR */ + case SPEEX_SET_INNOVATION_SAVE: + st->innov_rms_save = (spx_word16_t*)ptr; + break; + case SPEEX_SET_WIDEBAND: + st->isWideband = *((spx_int32_t*)ptr); + break; + case SPEEX_GET_STACK: + *((char**)ptr) = st->stack; + break; + default: + speex_warning_int("Unknown nb_ctl request: ", request); + return -1; + } + return 0; +} + + int nb_encode(void *state, void *vin, SpeexBits *bits) { EncState *st; @@ -837,10 +1042,10 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) } for (i=0;i<st->subframeSize;i++) exc[i] = EXTRACT16(SATURATE32(PSHR32(ADD32(SHL32(exc32[i],1),innov[i]),SIG_SHIFT),32767)); +#ifndef DISABLE_WIDEBAND if (st->innov_rms_save) - { st->innov_rms_save[sub] = compute_rms(innov, st->subframeSize); - } +#endif } /* Final signal synthesis from excitation */ @@ -887,7 +1092,10 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) return 1; } +#endif /* DISABLE_ENCODER */ + +#ifndef DISABLE_DECODER void *nb_decoder_init(const SpeexMode *m) { DecState *st; @@ -963,6 +1171,132 @@ void nb_decoder_destroy(void *state) speex_free(state); } +int nb_decoder_ctl(void *state, int request, void *ptr) +{ + DecState *st; + st=(DecState*)state; + switch(request) + { + case SPEEX_SET_LOW_MODE: + case SPEEX_SET_MODE: + st->submodeID = (*(spx_int32_t*)ptr); + break; + case SPEEX_GET_LOW_MODE: + case SPEEX_GET_MODE: + (*(spx_int32_t*)ptr) = st->submodeID; + break; + case SPEEX_SET_ENH: + st->lpc_enh_enabled = *((spx_int32_t*)ptr); + break; + case SPEEX_GET_ENH: + *((spx_int32_t*)ptr) = st->lpc_enh_enabled; + break; + case SPEEX_GET_FRAME_SIZE: + (*(spx_int32_t*)ptr) = st->frameSize; + break; + case SPEEX_GET_BITRATE: + if (st->submodes[st->submodeID]) + (*(spx_int32_t*)ptr) = st->sampling_rate*SUBMODE(bits_per_frame)/st->frameSize; + else + (*(spx_int32_t*)ptr) = st->sampling_rate*(NB_SUBMODE_BITS+1)/st->frameSize; + break; + case SPEEX_SET_SAMPLING_RATE: + st->sampling_rate = (*(spx_int32_t*)ptr); + break; + case SPEEX_GET_SAMPLING_RATE: + (*(spx_int32_t*)ptr)=st->sampling_rate; + break; + case SPEEX_SET_HANDLER: + { + SpeexCallback *c = (SpeexCallback*)ptr; + st->speex_callbacks[c->callback_id].func=c->func; + st->speex_callbacks[c->callback_id].data=c->data; + st->speex_callbacks[c->callback_id].callback_id=c->callback_id; + } + break; + case SPEEX_SET_USER_HANDLER: + { + SpeexCallback *c = (SpeexCallback*)ptr; + st->user_callback.func=c->func; + st->user_callback.data=c->data; + st->user_callback.callback_id=c->callback_id; + } + break; + case SPEEX_RESET_STATE: + { + int i; + for (i=0;i<st->lpcSize;i++) + st->mem_sp[i]=0; + for (i=0;i<st->frameSize + st->max_pitch + 1;i++) + st->excBuf[i]=0; + } + break; + case SPEEX_SET_SUBMODE_ENCODING: + st->encode_submode = (*(spx_int32_t*)ptr); + break; + case SPEEX_GET_SUBMODE_ENCODING: + (*(spx_int32_t*)ptr) = st->encode_submode; + break; + case SPEEX_GET_LOOKAHEAD: + (*(spx_int32_t*)ptr)=st->subframeSize; + break; + case SPEEX_SET_HIGHPASS: + st->highpass_enabled = (*(spx_int32_t*)ptr); + break; + case SPEEX_GET_HIGHPASS: + (*(spx_int32_t*)ptr) = st->highpass_enabled; + break; + /* FIXME: Convert to fixed-point and re-enable even when float API is disabled */ +#ifndef DISABLE_FLOAT_API + case SPEEX_GET_ACTIVITY: + { + float ret; + ret = log(st->level/st->min_level)/log(st->max_level/st->min_level); + if (ret>1) + ret = 1; + /* Done in a strange way to catch NaNs as well */ + if (!(ret > 0)) + ret = 0; + /*printf ("%f %f %f %f\n", st->level, st->min_level, st->max_level, ret);*/ + (*(spx_int32_t*)ptr) = (int)(100*ret); + } + break; +#endif + case SPEEX_GET_PI_GAIN: + { + int i; + spx_word32_t *g = (spx_word32_t*)ptr; + for (i=0;i<st->nbSubframes;i++) + g[i]=st->pi_gain[i]; + } + break; + case SPEEX_GET_EXC: + { + int i; + for (i=0;i<st->nbSubframes;i++) + ((spx_word16_t*)ptr)[i] = compute_rms16(st->exc+i*st->subframeSize, st->subframeSize); + } + break; + case SPEEX_GET_DTX_STATUS: + *((spx_int32_t*)ptr) = st->dtx_enabled; + break; + case SPEEX_SET_INNOVATION_SAVE: + st->innov_save = (spx_word16_t*)ptr; + break; + case SPEEX_SET_WIDEBAND: + st->isWideband = *((spx_int32_t*)ptr); + break; + case SPEEX_GET_STACK: + *((char**)ptr) = st->stack; + break; + default: + speex_warning_int("Unknown nb_ctl request: ", request); + return -1; + } + return 0; +} + + #define median3(a, b, c) ((a) < (b) ? ((b) < (c) ? (b) : ((a) < (c) ? (c) : (a))) : ((c) < (b) ? (b) : ((c) < (a) ? (c) : (a)))) #ifdef FIXED_POINT @@ -1531,332 +1865,5 @@ int nb_decode(void *state, SpeexBits *bits, void *vout) return 0; } +#endif /* DISABLE_DECODER */ -int nb_encoder_ctl(void *state, int request, void *ptr) -{ - EncState *st; - st=(EncState*)state; - switch(request) - { - case SPEEX_GET_FRAME_SIZE: - (*(spx_int32_t*)ptr) = st->frameSize; - break; - case SPEEX_SET_LOW_MODE: - case SPEEX_SET_MODE: - st->submodeSelect = st->submodeID = (*(spx_int32_t*)ptr); - break; - case SPEEX_GET_LOW_MODE: - case SPEEX_GET_MODE: - (*(spx_int32_t*)ptr) = st->submodeID; - break; -#ifndef DISABLE_VBR - case SPEEX_SET_VBR: - st->vbr_enabled = (*(spx_int32_t*)ptr); - break; - case SPEEX_GET_VBR: - (*(spx_int32_t*)ptr) = st->vbr_enabled; - break; - case SPEEX_SET_VAD: - st->vad_enabled = (*(spx_int32_t*)ptr); - break; - case SPEEX_GET_VAD: - (*(spx_int32_t*)ptr) = st->vad_enabled; - break; - case SPEEX_SET_DTX: - st->dtx_enabled = (*(spx_int32_t*)ptr); - break; - case SPEEX_GET_DTX: - (*(spx_int32_t*)ptr) = st->dtx_enabled; - break; - case SPEEX_SET_ABR: - st->abr_enabled = (*(spx_int32_t*)ptr); - st->vbr_enabled = st->abr_enabled!=0; - if (st->vbr_enabled) - { - spx_int32_t i=10; - spx_int32_t rate, target; - float vbr_qual; - target = (*(spx_int32_t*)ptr); - while (i>=0) - { - speex_encoder_ctl(st, SPEEX_SET_QUALITY, &i); - speex_encoder_ctl(st, SPEEX_GET_BITRATE, &rate); - if (rate <= target) - break; - i--; - } - vbr_qual=i; - if (vbr_qual<0) - vbr_qual=0; - speex_encoder_ctl(st, SPEEX_SET_VBR_QUALITY, &vbr_qual); - st->abr_count=0; - st->abr_drift=0; - st->abr_drift2=0; - } - - break; - case SPEEX_GET_ABR: - (*(spx_int32_t*)ptr) = st->abr_enabled; - break; -#endif /* #ifndef DISABLE_VBR */ -#if !defined(DISABLE_VBR) && !defined(DISABLE_FLOAT_API) - case SPEEX_SET_VBR_QUALITY: - st->vbr_quality = (*(float*)ptr); - break; - case SPEEX_GET_VBR_QUALITY: - (*(float*)ptr) = st->vbr_quality; - break; -#endif /* !defined(DISABLE_VBR) && !defined(DISABLE_FLOAT_API) */ - case SPEEX_SET_QUALITY: - { - int quality = (*(spx_int32_t*)ptr); - if (quality < 0) - quality = 0; - if (quality > 10) - quality = 10; - st->submodeSelect = st->submodeID = ((const SpeexNBMode*)(st->mode->mode))->quality_map[quality]; - } - break; - case SPEEX_SET_COMPLEXITY: - st->complexity = (*(spx_int32_t*)ptr); - if (st->complexity<0) - st->complexity=0; - break; - case SPEEX_GET_COMPLEXITY: - (*(spx_int32_t*)ptr) = st->complexity; - break; - case SPEEX_SET_BITRATE: - { - spx_int32_t i=10; - spx_int32_t rate, target; - target = (*(spx_int32_t*)ptr); - while (i>=0) - { - speex_encoder_ctl(st, SPEEX_SET_QUALITY, &i); - speex_encoder_ctl(st, SPEEX_GET_BITRATE, &rate); - if (rate <= target) - break; - i--; - } - } - break; - case SPEEX_GET_BITRATE: - if (st->submodes[st->submodeID]) - (*(spx_int32_t*)ptr) = st->sampling_rate*SUBMODE(bits_per_frame)/st->frameSize; - else - (*(spx_int32_t*)ptr) = st->sampling_rate*(NB_SUBMODE_BITS+1)/st->frameSize; - break; - case SPEEX_SET_SAMPLING_RATE: - st->sampling_rate = (*(spx_int32_t*)ptr); - break; - case SPEEX_GET_SAMPLING_RATE: - (*(spx_int32_t*)ptr)=st->sampling_rate; - break; - case SPEEX_RESET_STATE: - { - int i; - st->bounded_pitch = 1; - st->first = 1; - for (i=0;i<st->lpcSize;i++) - st->old_lsp[i]= DIV32(MULT16_16(QCONST16(3.1415927f, LSP_SHIFT), i+1), st->lpcSize+1); - for (i=0;i<st->lpcSize;i++) - st->mem_sw[i]=st->mem_sw_whole[i]=st->mem_sp[i]=st->mem_exc[i]=0; - for (i=0;i<st->frameSize+st->max_pitch+1;i++) - st->excBuf[i]=st->swBuf[i]=0; - for (i=0;i<st->windowSize-st->frameSize;i++) - st->winBuf[i]=0; - } - break; - case SPEEX_SET_SUBMODE_ENCODING: - st->encode_submode = (*(spx_int32_t*)ptr); - break; - case SPEEX_GET_SUBMODE_ENCODING: - (*(spx_int32_t*)ptr) = st->encode_submode; - break; - case SPEEX_GET_LOOKAHEAD: - (*(spx_int32_t*)ptr)=(st->windowSize-st->frameSize); - break; - case SPEEX_SET_PLC_TUNING: - st->plc_tuning = (*(spx_int32_t*)ptr); - if (st->plc_tuning>100) - st->plc_tuning=100; - break; - case SPEEX_GET_PLC_TUNING: - (*(spx_int32_t*)ptr)=(st->plc_tuning); - break; -#ifndef DISABLE_VBR - case SPEEX_SET_VBR_MAX_BITRATE: - st->vbr_max = (*(spx_int32_t*)ptr); - break; - case SPEEX_GET_VBR_MAX_BITRATE: - (*(spx_int32_t*)ptr) = st->vbr_max; - break; -#endif /* #ifndef DISABLE_VBR */ - case SPEEX_SET_HIGHPASS: - st->highpass_enabled = (*(spx_int32_t*)ptr); - break; - case SPEEX_GET_HIGHPASS: - (*(spx_int32_t*)ptr) = st->highpass_enabled; - break; - - /* This is all internal stuff past this point */ - case SPEEX_GET_PI_GAIN: - { - int i; - spx_word32_t *g = (spx_word32_t*)ptr; - for (i=0;i<st->nbSubframes;i++) - g[i]=st->pi_gain[i]; - } - break; - case SPEEX_GET_EXC: - { - int i; - for (i=0;i<st->nbSubframes;i++) - ((spx_word16_t*)ptr)[i] = compute_rms16(st->exc+i*st->subframeSize, st->subframeSize); - } - break; -#ifndef DISABLE_VBR - case SPEEX_GET_RELATIVE_QUALITY: - (*(float*)ptr)=st->relative_quality; - break; -#endif /* #ifndef DISABLE_VBR */ - case SPEEX_SET_INNOVATION_SAVE: - st->innov_rms_save = (spx_word16_t*)ptr; - break; - case SPEEX_SET_WIDEBAND: - st->isWideband = *((spx_int32_t*)ptr); - break; - case SPEEX_GET_STACK: - *((char**)ptr) = st->stack; - break; - default: - speex_warning_int("Unknown nb_ctl request: ", request); - return -1; - } - return 0; -} - -int nb_decoder_ctl(void *state, int request, void *ptr) -{ - DecState *st; - st=(DecState*)state; - switch(request) - { - case SPEEX_SET_LOW_MODE: - case SPEEX_SET_MODE: - st->submodeID = (*(spx_int32_t*)ptr); - break; - case SPEEX_GET_LOW_MODE: - case SPEEX_GET_MODE: - (*(spx_int32_t*)ptr) = st->submodeID; - break; - case SPEEX_SET_ENH: - st->lpc_enh_enabled = *((spx_int32_t*)ptr); - break; - case SPEEX_GET_ENH: - *((spx_int32_t*)ptr) = st->lpc_enh_enabled; - break; - case SPEEX_GET_FRAME_SIZE: - (*(spx_int32_t*)ptr) = st->frameSize; - break; - case SPEEX_GET_BITRATE: - if (st->submodes[st->submodeID]) - (*(spx_int32_t*)ptr) = st->sampling_rate*SUBMODE(bits_per_frame)/st->frameSize; - else - (*(spx_int32_t*)ptr) = st->sampling_rate*(NB_SUBMODE_BITS+1)/st->frameSize; - break; - case SPEEX_SET_SAMPLING_RATE: - st->sampling_rate = (*(spx_int32_t*)ptr); - break; - case SPEEX_GET_SAMPLING_RATE: - (*(spx_int32_t*)ptr)=st->sampling_rate; - break; - case SPEEX_SET_HANDLER: - { - SpeexCallback *c = (SpeexCallback*)ptr; - st->speex_callbacks[c->callback_id].func=c->func; - st->speex_callbacks[c->callback_id].data=c->data; - st->speex_callbacks[c->callback_id].callback_id=c->callback_id; - } - break; - case SPEEX_SET_USER_HANDLER: - { - SpeexCallback *c = (SpeexCallback*)ptr; - st->user_callback.func=c->func; - st->user_callback.data=c->data; - st->user_callback.callback_id=c->callback_id; - } - break; - case SPEEX_RESET_STATE: - { - int i; - for (i=0;i<st->lpcSize;i++) - st->mem_sp[i]=0; - for (i=0;i<st->frameSize + st->max_pitch + 1;i++) - st->excBuf[i]=0; - } - break; - case SPEEX_SET_SUBMODE_ENCODING: - st->encode_submode = (*(spx_int32_t*)ptr); - break; - case SPEEX_GET_SUBMODE_ENCODING: - (*(spx_int32_t*)ptr) = st->encode_submode; - break; - case SPEEX_GET_LOOKAHEAD: - (*(spx_int32_t*)ptr)=st->subframeSize; - break; - case SPEEX_SET_HIGHPASS: - st->highpass_enabled = (*(spx_int32_t*)ptr); - break; - case SPEEX_GET_HIGHPASS: - (*(spx_int32_t*)ptr) = st->highpass_enabled; - break; - /* FIXME: Convert to fixed-point and re-enable even when float API is disabled */ -#ifndef DISABLE_FLOAT_API - case SPEEX_GET_ACTIVITY: - { - float ret; - ret = log(st->level/st->min_level)/log(st->max_level/st->min_level); - if (ret>1) - ret = 1; - /* Done in a strange way to catch NaNs as well */ - if (!(ret > 0)) - ret = 0; - /*printf ("%f %f %f %f\n", st->level, st->min_level, st->max_level, ret);*/ - (*(spx_int32_t*)ptr) = (int)(100*ret); - } - break; -#endif - case SPEEX_GET_PI_GAIN: - { - int i; - spx_word32_t *g = (spx_word32_t*)ptr; - for (i=0;i<st->nbSubframes;i++) - g[i]=st->pi_gain[i]; - } - break; - case SPEEX_GET_EXC: - { - int i; - for (i=0;i<st->nbSubframes;i++) - ((spx_word16_t*)ptr)[i] = compute_rms16(st->exc+i*st->subframeSize, st->subframeSize); - } - break; - case SPEEX_GET_DTX_STATUS: - *((spx_int32_t*)ptr) = st->dtx_enabled; - break; - case SPEEX_SET_INNOVATION_SAVE: - st->innov_save = (spx_word16_t*)ptr; - break; - case SPEEX_SET_WIDEBAND: - st->isWideband = *((spx_int32_t*)ptr); - break; - case SPEEX_GET_STACK: - *((char**)ptr) = st->stack; - break; - default: - speex_warning_int("Unknown nb_ctl request: ", request); - return -1; - } - return 0; -} diff --git a/libspeex/quant_lsp.c b/libspeex/quant_lsp.c index e624d1a..699716b 100644 --- a/libspeex/quant_lsp.c +++ b/libspeex/quant_lsp.c @@ -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 */ diff --git a/libspeex/sb_celp.c b/libspeex/sb_celp.c index 6c19ff8..a8e95f2 100644 --- a/libspeex/sb_celp.c +++ b/libspeex/sb_celp.c @@ -62,46 +62,7 @@ #endif -#ifdef DISABLE_WIDEBAND -void *sb_encoder_init(const SpeexMode *m) -{ - speex_fatal("Wideband and Ultra-wideband are disabled"); - return NULL; -} -void sb_encoder_destroy(void *state) -{ - speex_fatal("Wideband and Ultra-wideband are disabled"); -} -int sb_encode(void *state, void *vin, SpeexBits *bits) -{ - speex_fatal("Wideband and Ultra-wideband are disabled"); - return -2; -} -void *sb_decoder_init(const SpeexMode *m) -{ - speex_fatal("Wideband and Ultra-wideband are disabled"); - return NULL; -} -void sb_decoder_destroy(void *state) -{ - speex_fatal("Wideband and Ultra-wideband are disabled"); -} -int sb_decode(void *state, SpeexBits *bits, void *vout) -{ - speex_fatal("Wideband and Ultra-wideband are disabled"); - return -2; -} -int sb_encoder_ctl(void *state, int request, void *ptr) -{ - speex_fatal("Wideband and Ultra-wideband are disabled"); - return -2; -} -int sb_decoder_ctl(void *state, int request, void *ptr) -{ - speex_fatal("Wideband and Ultra-wideband are disabled"); - return -2; -} -#else +#ifndef DISABLE_WIDEBAND #ifndef M_PI @@ -186,7 +147,7 @@ static const float h0[64] = { extern const spx_word16_t lag_window[]; extern const spx_word16_t lpc_window[]; - +#ifndef DISABLE_ENCODER void *sb_encoder_init(const SpeexMode *m) { int i; @@ -300,6 +261,265 @@ void sb_encoder_destroy(void *state) speex_free(st); } +int sb_encoder_ctl(void *state, int request, void *ptr) +{ + SBEncState *st; + st=(SBEncState*)state; + switch(request) + { + case SPEEX_GET_FRAME_SIZE: + (*(spx_int32_t*)ptr) = st->full_frame_size; + break; + case SPEEX_SET_HIGH_MODE: + st->submodeSelect = st->submodeID = (*(spx_int32_t*)ptr); + break; + case SPEEX_SET_LOW_MODE: + speex_encoder_ctl(st->st_low, SPEEX_SET_LOW_MODE, ptr); + break; + case SPEEX_SET_DTX: + speex_encoder_ctl(st->st_low, SPEEX_SET_DTX, ptr); + break; + case SPEEX_GET_DTX: + speex_encoder_ctl(st->st_low, SPEEX_GET_DTX, ptr); + break; + case SPEEX_GET_LOW_MODE: + speex_encoder_ctl(st->st_low, SPEEX_GET_LOW_MODE, ptr); + break; + case SPEEX_SET_MODE: + speex_encoder_ctl(st, SPEEX_SET_QUALITY, ptr); + break; +#ifndef DISABLE_VBR + case SPEEX_SET_VBR: + st->vbr_enabled = (*(spx_int32_t*)ptr); + speex_encoder_ctl(st->st_low, SPEEX_SET_VBR, ptr); + break; + case SPEEX_GET_VBR: + (*(spx_int32_t*)ptr) = st->vbr_enabled; + break; + case SPEEX_SET_VAD: + st->vad_enabled = (*(spx_int32_t*)ptr); + speex_encoder_ctl(st->st_low, SPEEX_SET_VAD, ptr); + break; + case SPEEX_GET_VAD: + (*(spx_int32_t*)ptr) = st->vad_enabled; + break; +#endif /* #ifndef DISABLE_VBR */ +#if !defined(DISABLE_VBR) && !defined(DISABLE_FLOAT_API) + case SPEEX_SET_VBR_QUALITY: + { + spx_int32_t q; + float qual = (*(float*)ptr)+.6; + st->vbr_quality = (*(float*)ptr); + if (qual>10) + qual=10; + q=(int)floor(.5+*(float*)ptr); + if (q>10) + q=10; + speex_encoder_ctl(st->st_low, SPEEX_SET_VBR_QUALITY, &qual); + speex_encoder_ctl(state, SPEEX_SET_QUALITY, &q); + break; + } + case SPEEX_GET_VBR_QUALITY: + (*(float*)ptr) = st->vbr_quality; + break; +#endif /* #if !defined(DISABLE_VBR) && !defined(DISABLE_FLOAT_API) */ +#ifndef DISABLE_VBR + case SPEEX_SET_ABR: + st->abr_enabled = (*(spx_int32_t*)ptr); + st->vbr_enabled = st->abr_enabled!=0; + speex_encoder_ctl(st->st_low, SPEEX_SET_VBR, &st->vbr_enabled); + if (st->vbr_enabled) + { + spx_int32_t i=10, rate, target; + float vbr_qual; + target = (*(spx_int32_t*)ptr); + while (i>=0) + { + speex_encoder_ctl(st, SPEEX_SET_QUALITY, &i); + speex_encoder_ctl(st, SPEEX_GET_BITRATE, &rate); + if (rate <= target) + break; + i--; + } + vbr_qual=i; + if (vbr_qual<0) + vbr_qual=0; + speex_encoder_ctl(st, SPEEX_SET_VBR_QUALITY, &vbr_qual); + st->abr_count=0; + st->abr_drift=0; + st->abr_drift2=0; + } + + break; + case SPEEX_GET_ABR: + (*(spx_int32_t*)ptr) = st->abr_enabled; + break; +#endif /* #ifndef DISABLE_VBR */ + + case SPEEX_SET_QUALITY: + { + spx_int32_t nb_qual; + int quality = (*(spx_int32_t*)ptr); + if (quality < 0) + quality = 0; + if (quality > 10) + quality = 10; + st->submodeSelect = st->submodeID = ((const SpeexSBMode*)(st->mode->mode))->quality_map[quality]; + nb_qual = ((const SpeexSBMode*)(st->mode->mode))->low_quality_map[quality]; + speex_encoder_ctl(st->st_low, SPEEX_SET_MODE, &nb_qual); + } + break; + case SPEEX_SET_COMPLEXITY: + speex_encoder_ctl(st->st_low, SPEEX_SET_COMPLEXITY, ptr); + st->complexity = (*(spx_int32_t*)ptr); + if (st->complexity<1) + st->complexity=1; + break; + case SPEEX_GET_COMPLEXITY: + (*(spx_int32_t*)ptr) = st->complexity; + break; + case SPEEX_SET_BITRATE: + { + spx_int32_t i=10; + spx_int32_t rate, target; + target = (*(spx_int32_t*)ptr); + while (i>=0) + { + speex_encoder_ctl(st, SPEEX_SET_QUALITY, &i); + speex_encoder_ctl(st, SPEEX_GET_BITRATE, &rate); + if (rate <= target) + break; + i--; + } + } + break; + case SPEEX_GET_BITRATE: + speex_encoder_ctl(st->st_low, request, ptr); + /*fprintf (stderr, "before: %d\n", (*(int*)ptr));*/ + if (st->submodes[st->submodeID]) + (*(spx_int32_t*)ptr) += st->sampling_rate*SUBMODE(bits_per_frame)/st->full_frame_size; + else + (*(spx_int32_t*)ptr) += st->sampling_rate*(SB_SUBMODE_BITS+1)/st->full_frame_size; + /*fprintf (stderr, "after: %d\n", (*(int*)ptr));*/ + break; + case SPEEX_SET_SAMPLING_RATE: + { + spx_int32_t tmp=(*(spx_int32_t*)ptr); + st->sampling_rate = tmp; + tmp>>=1; + speex_encoder_ctl(st->st_low, SPEEX_SET_SAMPLING_RATE, &tmp); + } + break; + case SPEEX_GET_SAMPLING_RATE: + (*(spx_int32_t*)ptr)=st->sampling_rate; + break; + case SPEEX_RESET_STATE: + { + int i; + st->first = 1; + for (i=0;i<st->lpcSize;i++) + st->old_lsp[i]= DIV32(MULT16_16(QCONST16(3.1415927f, LSP_SHIFT), i+1), st->lpcSize+1); + for (i=0;i<st->lpcSize;i++) + st->mem_sw[i]=st->mem_sp[i]=st->mem_sp2[i]=0; + for (i=0;i<QMF_ORDER;i++) + st->h0_mem[i]=st->h1_mem[i]=0; + } + break; + case SPEEX_SET_SUBMODE_ENCODING: + st->encode_submode = (*(spx_int32_t*)ptr); + speex_encoder_ctl(st->st_low, SPEEX_SET_SUBMODE_ENCODING, ptr); + break; + case SPEEX_GET_SUBMODE_ENCODING: + (*(spx_int32_t*)ptr) = st->encode_submode; + break; + case SPEEX_GET_LOOKAHEAD: + speex_encoder_ctl(st->st_low, SPEEX_GET_LOOKAHEAD, ptr); + (*(spx_int32_t*)ptr) = 2*(*(spx_int32_t*)ptr) + QMF_ORDER - 1; + break; + case SPEEX_SET_PLC_TUNING: + speex_encoder_ctl(st->st_low, SPEEX_SET_PLC_TUNING, ptr); + break; + case SPEEX_GET_PLC_TUNING: + speex_encoder_ctl(st->st_low, SPEEX_GET_PLC_TUNING, ptr); + break; +#ifndef DISABLE_VBR + case SPEEX_SET_VBR_MAX_BITRATE: + { + st->vbr_max = (*(spx_int32_t*)ptr); + if (SPEEX_SET_VBR_MAX_BITRATE<1) + { + speex_encoder_ctl(st->st_low, SPEEX_SET_VBR_MAX_BITRATE, &st->vbr_max); + st->vbr_max_high = 17600; + } else { + spx_int32_t low_rate; + if (st->vbr_max >= 42200) + { + st->vbr_max_high = 17600; + } else if (st->vbr_max >= 27800) + { + st->vbr_max_high = 9600; + } else if (st->vbr_max > 20600) + { + st->vbr_max_high = 5600; + } else { + st->vbr_max_high = 1800; + } + if (st->subframeSize==80) + st->vbr_max_high = 1800; + low_rate = st->vbr_max - st->vbr_max_high; + speex_encoder_ctl(st->st_low, SPEEX_SET_VBR_MAX_BITRATE, &low_rate); + } + } + break; + case SPEEX_GET_VBR_MAX_BITRATE: + (*(spx_int32_t*)ptr) = st->vbr_max; + break; +#endif /* #ifndef DISABLE_VBR */ + case SPEEX_SET_HIGHPASS: + speex_encoder_ctl(st->st_low, SPEEX_SET_HIGHPASS, ptr); + break; + case SPEEX_GET_HIGHPASS: + speex_encoder_ctl(st->st_low, SPEEX_GET_HIGHPASS, ptr); + break; + + + /* This is all internal stuff past this point */ + case SPEEX_GET_PI_GAIN: + { + int i; + spx_word32_t *g = (spx_word32_t*)ptr; + for (i=0;i<st->nbSubframes;i++) + g[i]=st->pi_gain[i]; + } + break; + case SPEEX_GET_EXC: + { + int i; + for (i=0;i<st->nbSubframes;i++) + ((spx_word16_t*)ptr)[i] = st->exc_rms[i]; + } + break; +#ifndef DISABLE_VBR + case SPEEX_GET_RELATIVE_QUALITY: + (*(float*)ptr)=st->relative_quality; + break; +#endif /* #ifndef DISABLE_VBR */ + case SPEEX_SET_INNOVATION_SAVE: + st->innov_rms_save = (spx_word16_t*)ptr; + break; + case SPEEX_SET_WIDEBAND: + speex_encoder_ctl(st->st_low, SPEEX_SET_WIDEBAND, ptr); + break; + case SPEEX_GET_STACK: + *((char**)ptr) = st->stack; + break; + default: + speex_warning_int("Unknown nb_ctl request: ", request); + return -1; + } + return 0; +} + int sb_encode(void *state, void *vin, SpeexBits *bits) { @@ -748,10 +968,10 @@ int sb_encode(void *state, void *vin, SpeexBits *bits) return 1; } +#endif /* DISABLE_ENCODER */ - - +#ifndef DISABLE_DECODER void *sb_decoder_init(const SpeexMode *m) { spx_int32_t tmp; @@ -832,6 +1052,136 @@ void sb_decoder_destroy(void *state) speex_free(state); } + + +int sb_decoder_ctl(void *state, int request, void *ptr) +{ + SBDecState *st; + st=(SBDecState*)state; + switch(request) + { + case SPEEX_SET_HIGH_MODE: + st->submodeID = (*(spx_int32_t*)ptr); + break; + case SPEEX_SET_LOW_MODE: + speex_decoder_ctl(st->st_low, SPEEX_SET_LOW_MODE, ptr); + break; + case SPEEX_GET_LOW_MODE: + speex_decoder_ctl(st->st_low, SPEEX_GET_LOW_MODE, ptr); + break; + case SPEEX_GET_FRAME_SIZE: + (*(spx_int32_t*)ptr) = st->full_frame_size; + break; + case SPEEX_SET_ENH: + speex_decoder_ctl(st->st_low, request, ptr); + st->lpc_enh_enabled = *((spx_int32_t*)ptr); + break; + case SPEEX_GET_ENH: + *((spx_int32_t*)ptr) = st->lpc_enh_enabled; + break; + case SPEEX_SET_MODE: + case SPEEX_SET_QUALITY: + { + spx_int32_t nb_qual; + int quality = (*(spx_int32_t*)ptr); + if (quality < 0) + quality = 0; + if (quality > 10) + quality = 10; + st->submodeID = ((const SpeexSBMode*)(st->mode->mode))->quality_map[quality]; + nb_qual = ((const SpeexSBMode*)(st->mode->mode))->low_quality_map[quality]; + speex_decoder_ctl(st->st_low, SPEEX_SET_MODE, &nb_qual); + } + break; + case SPEEX_GET_BITRATE: + speex_decoder_ctl(st->st_low, request, ptr); + if (st->submodes[st->submodeID]) + (*(spx_int32_t*)ptr) += st->sampling_rate*SUBMODE(bits_per_frame)/st->full_frame_size; + else + (*(spx_int32_t*)ptr) += st->sampling_rate*(SB_SUBMODE_BITS+1)/st->full_frame_size; + break; + case SPEEX_SET_SAMPLING_RATE: + { + spx_int32_t tmp=(*(spx_int32_t*)ptr); + st->sampling_rate = tmp; + tmp>>=1; + speex_decoder_ctl(st->st_low, SPEEX_SET_SAMPLING_RATE, &tmp); + } + break; + case SPEEX_GET_SAMPLING_RATE: + (*(spx_int32_t*)ptr)=st->sampling_rate; + break; + case SPEEX_SET_HANDLER: + speex_decoder_ctl(st->st_low, SPEEX_SET_HANDLER, ptr); + break; + case SPEEX_SET_USER_HANDLER: + speex_decoder_ctl(st->st_low, SPEEX_SET_USER_HANDLER, ptr); + break; + case SPEEX_RESET_STATE: + { + int i; + for (i=0;i<2*st->lpcSize;i++) + st->mem_sp[i]=0; + for (i=0;i<QMF_ORDER;i++) + st->g0_mem[i]=st->g1_mem[i]=0; + st->last_ener=0; + } + break; + case SPEEX_SET_SUBMODE_ENCODING: + st->encode_submode = (*(spx_int32_t*)ptr); + speex_decoder_ctl(st->st_low, SPEEX_SET_SUBMODE_ENCODING, ptr); + break; + case SPEEX_GET_SUBMODE_ENCODING: + (*(spx_int32_t*)ptr) = st->encode_submode; + break; + case SPEEX_GET_LOOKAHEAD: + speex_decoder_ctl(st->st_low, SPEEX_GET_LOOKAHEAD, ptr); + (*(spx_int32_t*)ptr) = 2*(*(spx_int32_t*)ptr); + break; + case SPEEX_SET_HIGHPASS: + speex_decoder_ctl(st->st_low, SPEEX_SET_HIGHPASS, ptr); + break; + case SPEEX_GET_HIGHPASS: + speex_decoder_ctl(st->st_low, SPEEX_GET_HIGHPASS, ptr); + break; + case SPEEX_GET_ACTIVITY: + speex_decoder_ctl(st->st_low, SPEEX_GET_ACTIVITY, ptr); + break; + case SPEEX_GET_PI_GAIN: + { + int i; + spx_word32_t *g = (spx_word32_t*)ptr; + for (i=0;i<st->nbSubframes;i++) + g[i]=st->pi_gain[i]; + } + break; + case SPEEX_GET_EXC: + { + int i; + for (i=0;i<st->nbSubframes;i++) + ((spx_word16_t*)ptr)[i] = st->exc_rms[i]; + } + break; + case SPEEX_GET_DTX_STATUS: + speex_decoder_ctl(st->st_low, SPEEX_GET_DTX_STATUS, ptr); + break; + case SPEEX_SET_INNOVATION_SAVE: + st->innov_save = (spx_word16_t*)ptr; + break; + case SPEEX_SET_WIDEBAND: + speex_decoder_ctl(st->st_low, SPEEX_SET_WIDEBAND, ptr); + break; + case SPEEX_GET_STACK: + *((char**)ptr) = st->stack; + break; + default: + speex_warning_int("Unknown nb_ctl request: ", request); + return -1; + } + return 0; +} + + static void sb_decode_lost(SBDecState *st, spx_word16_t *out, int dtx, char *stack) { int i; @@ -1096,393 +1446,9 @@ int sb_decode(void *state, SpeexBits *bits, void *vout) return 0; } +#endif /* DISABLE_DECODER */ -int sb_encoder_ctl(void *state, int request, void *ptr) -{ - SBEncState *st; - st=(SBEncState*)state; - switch(request) - { - case SPEEX_GET_FRAME_SIZE: - (*(spx_int32_t*)ptr) = st->full_frame_size; - break; - case SPEEX_SET_HIGH_MODE: - st->submodeSelect = st->submodeID = (*(spx_int32_t*)ptr); - break; - case SPEEX_SET_LOW_MODE: - speex_encoder_ctl(st->st_low, SPEEX_SET_LOW_MODE, ptr); - break; - case SPEEX_SET_DTX: - speex_encoder_ctl(st->st_low, SPEEX_SET_DTX, ptr); - break; - case SPEEX_GET_DTX: - speex_encoder_ctl(st->st_low, SPEEX_GET_DTX, ptr); - break; - case SPEEX_GET_LOW_MODE: - speex_encoder_ctl(st->st_low, SPEEX_GET_LOW_MODE, ptr); - break; - case SPEEX_SET_MODE: - speex_encoder_ctl(st, SPEEX_SET_QUALITY, ptr); - break; -#ifndef DISABLE_VBR - case SPEEX_SET_VBR: - st->vbr_enabled = (*(spx_int32_t*)ptr); - speex_encoder_ctl(st->st_low, SPEEX_SET_VBR, ptr); - break; - case SPEEX_GET_VBR: - (*(spx_int32_t*)ptr) = st->vbr_enabled; - break; - case SPEEX_SET_VAD: - st->vad_enabled = (*(spx_int32_t*)ptr); - speex_encoder_ctl(st->st_low, SPEEX_SET_VAD, ptr); - break; - case SPEEX_GET_VAD: - (*(spx_int32_t*)ptr) = st->vad_enabled; - break; -#endif /* #ifndef DISABLE_VBR */ -#if !defined(DISABLE_VBR) && !defined(DISABLE_FLOAT_API) - case SPEEX_SET_VBR_QUALITY: - { - spx_int32_t q; - float qual = (*(float*)ptr)+.6; - st->vbr_quality = (*(float*)ptr); - if (qual>10) - qual=10; - q=(int)floor(.5+*(float*)ptr); - if (q>10) - q=10; - speex_encoder_ctl(st->st_low, SPEEX_SET_VBR_QUALITY, &qual); - speex_encoder_ctl(state, SPEEX_SET_QUALITY, &q); - break; - } - case SPEEX_GET_VBR_QUALITY: - (*(float*)ptr) = st->vbr_quality; - break; -#endif /* #if !defined(DISABLE_VBR) && !defined(DISABLE_FLOAT_API) */ -#ifndef DISABLE_VBR - case SPEEX_SET_ABR: - st->abr_enabled = (*(spx_int32_t*)ptr); - st->vbr_enabled = st->abr_enabled!=0; - speex_encoder_ctl(st->st_low, SPEEX_SET_VBR, &st->vbr_enabled); - if (st->vbr_enabled) - { - spx_int32_t i=10, rate, target; - float vbr_qual; - target = (*(spx_int32_t*)ptr); - while (i>=0) - { - speex_encoder_ctl(st, SPEEX_SET_QUALITY, &i); - speex_encoder_ctl(st, SPEEX_GET_BITRATE, &rate); - if (rate <= target) - break; - i--; - } - vbr_qual=i; - if (vbr_qual<0) - vbr_qual=0; - speex_encoder_ctl(st, SPEEX_SET_VBR_QUALITY, &vbr_qual); - st->abr_count=0; - st->abr_drift=0; - st->abr_drift2=0; - } - - break; - case SPEEX_GET_ABR: - (*(spx_int32_t*)ptr) = st->abr_enabled; - break; -#endif /* #ifndef DISABLE_VBR */ - - case SPEEX_SET_QUALITY: - { - spx_int32_t nb_qual; - int quality = (*(spx_int32_t*)ptr); - if (quality < 0) - quality = 0; - if (quality > 10) - quality = 10; - st->submodeSelect = st->submodeID = ((const SpeexSBMode*)(st->mode->mode))->quality_map[quality]; - nb_qual = ((const SpeexSBMode*)(st->mode->mode))->low_quality_map[quality]; - speex_encoder_ctl(st->st_low, SPEEX_SET_MODE, &nb_qual); - } - break; - case SPEEX_SET_COMPLEXITY: - speex_encoder_ctl(st->st_low, SPEEX_SET_COMPLEXITY, ptr); - st->complexity = (*(spx_int32_t*)ptr); - if (st->complexity<1) - st->complexity=1; - break; - case SPEEX_GET_COMPLEXITY: - (*(spx_int32_t*)ptr) = st->complexity; - break; - case SPEEX_SET_BITRATE: - { - spx_int32_t i=10; - spx_int32_t rate, target; - target = (*(spx_int32_t*)ptr); - while (i>=0) - { - speex_encoder_ctl(st, SPEEX_SET_QUALITY, &i); - speex_encoder_ctl(st, SPEEX_GET_BITRATE, &rate); - if (rate <= target) - break; - i--; - } - } - break; - case SPEEX_GET_BITRATE: - speex_encoder_ctl(st->st_low, request, ptr); - /*fprintf (stderr, "before: %d\n", (*(int*)ptr));*/ - if (st->submodes[st->submodeID]) - (*(spx_int32_t*)ptr) += st->sampling_rate*SUBMODE(bits_per_frame)/st->full_frame_size; - else - (*(spx_int32_t*)ptr) += st->sampling_rate*(SB_SUBMODE_BITS+1)/st->full_frame_size; - /*fprintf (stderr, "after: %d\n", (*(int*)ptr));*/ - break; - case SPEEX_SET_SAMPLING_RATE: - { - spx_int32_t tmp=(*(spx_int32_t*)ptr); - st->sampling_rate = tmp; - tmp>>=1; - speex_encoder_ctl(st->st_low, SPEEX_SET_SAMPLING_RATE, &tmp); - } - break; - case SPEEX_GET_SAMPLING_RATE: - (*(spx_int32_t*)ptr)=st->sampling_rate; - break; - case SPEEX_RESET_STATE: - { - int i; - st->first = 1; - for (i=0;i<st->lpcSize;i++) - st->old_lsp[i]= DIV32(MULT16_16(QCONST16(3.1415927f, LSP_SHIFT), i+1), st->lpcSize+1); - for (i=0;i<st->lpcSize;i++) - st->mem_sw[i]=st->mem_sp[i]=st->mem_sp2[i]=0; - for (i=0;i<QMF_ORDER;i++) - st->h0_mem[i]=st->h1_mem[i]=0; - } - break; - case SPEEX_SET_SUBMODE_ENCODING: - st->encode_submode = (*(spx_int32_t*)ptr); - speex_encoder_ctl(st->st_low, SPEEX_SET_SUBMODE_ENCODING, ptr); - break; - case SPEEX_GET_SUBMODE_ENCODING: - (*(spx_int32_t*)ptr) = st->encode_submode; - break; - case SPEEX_GET_LOOKAHEAD: - speex_encoder_ctl(st->st_low, SPEEX_GET_LOOKAHEAD, ptr); - (*(spx_int32_t*)ptr) = 2*(*(spx_int32_t*)ptr) + QMF_ORDER - 1; - break; - case SPEEX_SET_PLC_TUNING: - speex_encoder_ctl(st->st_low, SPEEX_SET_PLC_TUNING, ptr); - break; - case SPEEX_GET_PLC_TUNING: - speex_encoder_ctl(st->st_low, SPEEX_GET_PLC_TUNING, ptr); - break; -#ifndef DISABLE_VBR - case SPEEX_SET_VBR_MAX_BITRATE: - { - st->vbr_max = (*(spx_int32_t*)ptr); - if (SPEEX_SET_VBR_MAX_BITRATE<1) - { - speex_encoder_ctl(st->st_low, SPEEX_SET_VBR_MAX_BITRATE, &st->vbr_max); - st->vbr_max_high = 17600; - } else { - spx_int32_t low_rate; - if (st->vbr_max >= 42200) - { - st->vbr_max_high = 17600; - } else if (st->vbr_max >= 27800) - { - st->vbr_max_high = 9600; - } else if (st->vbr_max > 20600) - { - st->vbr_max_high = 5600; - } else { - st->vbr_max_high = 1800; - } - if (st->subframeSize==80) - st->vbr_max_high = 1800; - low_rate = st->vbr_max - st->vbr_max_high; - speex_encoder_ctl(st->st_low, SPEEX_SET_VBR_MAX_BITRATE, &low_rate); - } - } - break; - case SPEEX_GET_VBR_MAX_BITRATE: - (*(spx_int32_t*)ptr) = st->vbr_max; - break; -#endif /* #ifndef DISABLE_VBR */ - case SPEEX_SET_HIGHPASS: - speex_encoder_ctl(st->st_low, SPEEX_SET_HIGHPASS, ptr); - break; - case SPEEX_GET_HIGHPASS: - speex_encoder_ctl(st->st_low, SPEEX_GET_HIGHPASS, ptr); - break; - - - /* This is all internal stuff past this point */ - case SPEEX_GET_PI_GAIN: - { - int i; - spx_word32_t *g = (spx_word32_t*)ptr; - for (i=0;i<st->nbSubframes;i++) - g[i]=st->pi_gain[i]; - } - break; - case SPEEX_GET_EXC: - { - int i; - for (i=0;i<st->nbSubframes;i++) - ((spx_word16_t*)ptr)[i] = st->exc_rms[i]; - } - break; -#ifndef DISABLE_VBR - case SPEEX_GET_RELATIVE_QUALITY: - (*(float*)ptr)=st->relative_quality; - break; -#endif /* #ifndef DISABLE_VBR */ - case SPEEX_SET_INNOVATION_SAVE: - st->innov_rms_save = (spx_word16_t*)ptr; - break; - case SPEEX_SET_WIDEBAND: - speex_encoder_ctl(st->st_low, SPEEX_SET_WIDEBAND, ptr); - break; - case SPEEX_GET_STACK: - *((char**)ptr) = st->stack; - break; - default: - speex_warning_int("Unknown nb_ctl request: ", request); - return -1; - } - return 0; -} - -int sb_decoder_ctl(void *state, int request, void *ptr) -{ - SBDecState *st; - st=(SBDecState*)state; - switch(request) - { - case SPEEX_SET_HIGH_MODE: - st->submodeID = (*(spx_int32_t*)ptr); - break; - case SPEEX_SET_LOW_MODE: - speex_decoder_ctl(st->st_low, SPEEX_SET_LOW_MODE, ptr); - break; - case SPEEX_GET_LOW_MODE: - speex_decoder_ctl(st->st_low, SPEEX_GET_LOW_MODE, ptr); - break; - case SPEEX_GET_FRAME_SIZE: - (*(spx_int32_t*)ptr) = st->full_frame_size; - break; - case SPEEX_SET_ENH: - speex_decoder_ctl(st->st_low, request, ptr); - st->lpc_enh_enabled = *((spx_int32_t*)ptr); - break; - case SPEEX_GET_ENH: - *((spx_int32_t*)ptr) = st->lpc_enh_enabled; - break; - case SPEEX_SET_MODE: - case SPEEX_SET_QUALITY: - { - spx_int32_t nb_qual; - int quality = (*(spx_int32_t*)ptr); - if (quality < 0) - quality = 0; - if (quality > 10) - quality = 10; - st->submodeID = ((const SpeexSBMode*)(st->mode->mode))->quality_map[quality]; - nb_qual = ((const SpeexSBMode*)(st->mode->mode))->low_quality_map[quality]; - speex_decoder_ctl(st->st_low, SPEEX_SET_MODE, &nb_qual); - } - break; - case SPEEX_GET_BITRATE: - speex_decoder_ctl(st->st_low, request, ptr); - if (st->submodes[st->submodeID]) - (*(spx_int32_t*)ptr) += st->sampling_rate*SUBMODE(bits_per_frame)/st->full_frame_size; - else - (*(spx_int32_t*)ptr) += st->sampling_rate*(SB_SUBMODE_BITS+1)/st->full_frame_size; - break; - case SPEEX_SET_SAMPLING_RATE: - { - spx_int32_t tmp=(*(spx_int32_t*)ptr); - st->sampling_rate = tmp; - tmp>>=1; - speex_decoder_ctl(st->st_low, SPEEX_SET_SAMPLING_RATE, &tmp); - } - break; - case SPEEX_GET_SAMPLING_RATE: - (*(spx_int32_t*)ptr)=st->sampling_rate; - break; - case SPEEX_SET_HANDLER: - speex_decoder_ctl(st->st_low, SPEEX_SET_HANDLER, ptr); - break; - case SPEEX_SET_USER_HANDLER: - speex_decoder_ctl(st->st_low, SPEEX_SET_USER_HANDLER, ptr); - break; - case SPEEX_RESET_STATE: - { - int i; - for (i=0;i<2*st->lpcSize;i++) - st->mem_sp[i]=0; - for (i=0;i<QMF_ORDER;i++) - st->g0_mem[i]=st->g1_mem[i]=0; - st->last_ener=0; - } - break; - case SPEEX_SET_SUBMODE_ENCODING: - st->encode_submode = (*(spx_int32_t*)ptr); - speex_decoder_ctl(st->st_low, SPEEX_SET_SUBMODE_ENCODING, ptr); - break; - case SPEEX_GET_SUBMODE_ENCODING: - (*(spx_int32_t*)ptr) = st->encode_submode; - break; - case SPEEX_GET_LOOKAHEAD: - speex_decoder_ctl(st->st_low, SPEEX_GET_LOOKAHEAD, ptr); - (*(spx_int32_t*)ptr) = 2*(*(spx_int32_t*)ptr); - break; - case SPEEX_SET_HIGHPASS: - speex_decoder_ctl(st->st_low, SPEEX_SET_HIGHPASS, ptr); - break; - case SPEEX_GET_HIGHPASS: - speex_decoder_ctl(st->st_low, SPEEX_GET_HIGHPASS, ptr); - break; - case SPEEX_GET_ACTIVITY: - speex_decoder_ctl(st->st_low, SPEEX_GET_ACTIVITY, ptr); - break; - case SPEEX_GET_PI_GAIN: - { - int i; - spx_word32_t *g = (spx_word32_t*)ptr; - for (i=0;i<st->nbSubframes;i++) - g[i]=st->pi_gain[i]; - } - break; - case SPEEX_GET_EXC: - { - int i; - for (i=0;i<st->nbSubframes;i++) - ((spx_word16_t*)ptr)[i] = st->exc_rms[i]; - } - break; - case SPEEX_GET_DTX_STATUS: - speex_decoder_ctl(st->st_low, SPEEX_GET_DTX_STATUS, ptr); - break; - case SPEEX_SET_INNOVATION_SAVE: - st->innov_save = (spx_word16_t*)ptr; - break; - case SPEEX_SET_WIDEBAND: - speex_decoder_ctl(st->st_low, SPEEX_SET_WIDEBAND, ptr); - break; - case SPEEX_GET_STACK: - *((char**)ptr) = st->stack; - break; - default: - speex_warning_int("Unknown nb_ctl request: ", request); - return -1; - } - return 0; -} #endif diff --git a/libspeex/stereo.c b/libspeex/stereo.c index 1f29a1c..02337ef 100644 --- a/libspeex/stereo.c +++ b/libspeex/stereo.c @@ -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) diff --git a/libspeex/vq.c b/libspeex/vq.c index 609f124..e95e1f2 100644 --- a/libspeex/vq.c +++ b/libspeex/vq.c @@ -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) */ |