From f39618b8d4e20453b9ac60d9c6c334e4fbe774dc Mon Sep 17 00:00:00 2001 From: jm Date: Sun, 18 Nov 2007 04:57:55 +0000 Subject: New DISABLE_VBR and DISABLE_FLOAT_API switches can together remove every single float operation out of libspeex. git-svn-id: http://svn.xiph.org/trunk/speex@14181 0101bb08-14d6-0310-b084-bc0e0c8e3800 --- libspeex/modes.h | 2 ++ libspeex/modes_wb.c | 32 ++++++++++++++++++-------------- libspeex/nb_celp.c | 32 ++++++++++++++++++++++++++++---- libspeex/nb_celp.h | 5 ++++- libspeex/sb_celp.c | 18 ++++++++++++++++++ libspeex/sb_celp.h | 4 +++- libspeex/speex.c | 4 ++++ libspeex/speex_callbacks.c | 5 ++++- libspeex/stereo.c | 4 ++++ libspeex/testenc.c | 20 ++++++++++++-------- libspeex/vbr.c | 3 +++ 11 files changed, 100 insertions(+), 29 deletions(-) diff --git a/libspeex/modes.h b/libspeex/modes.h index d0ff842..26e2d86 100644 --- a/libspeex/modes.h +++ b/libspeex/modes.h @@ -146,7 +146,9 @@ typedef struct SpeexSBMode { int defaultSubmode; /**< Default sub-mode to use when encoding */ int low_quality_map[11]; /**< Mode corresponding to each quality setting */ int quality_map[11]; /**< Mode corresponding to each quality setting */ +#ifndef DISABLE_VBR const float (*vbr_thresh)[11]; +#endif int nb_modes; } SpeexSBMode; diff --git a/libspeex/modes_wb.c b/libspeex/modes_wb.c index 64c9373..4b575b2 100644 --- a/libspeex/modes_wb.c +++ b/libspeex/modes_wb.c @@ -188,13 +188,15 @@ static const SpeexSBMode sb_wb_mode = { 0.9, 0.6, /* gamma1, gamma2 */ #endif QCONST16(.0002,15), /*lpc_floor*/ - QCONST16(0.9f,15), - {NULL, &wb_submode1, &wb_submode2, &wb_submode3, &wb_submode4, NULL, NULL, NULL}, - 3, - {1, 8, 2, 3, 4, 5, 5, 6, 6, 7, 7}, - {1, 1, 1, 1, 1, 1, 2, 2, 3, 3, 4}, - vbr_hb_thresh, - 5 + QCONST16(0.9f,15), + {NULL, &wb_submode1, &wb_submode2, &wb_submode3, &wb_submode4, NULL, NULL, NULL}, + 3, + {1, 8, 2, 3, 4, 5, 5, 6, 6, 7, 7}, + {1, 1, 1, 1, 1, 1, 2, 2, 3, 3, 4}, +#ifndef DISABLE_VBR + vbr_hb_thresh, +#endif + 5 }; @@ -232,13 +234,15 @@ static const SpeexSBMode sb_uwb_mode = { 0.9, 0.6, /* gamma1, gamma2 */ #endif QCONST16(.0002,15), /*lpc_floor*/ - QCONST16(0.7f,15), - {NULL, &wb_submode1, NULL, NULL, NULL, NULL, NULL, NULL}, - 1, - {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, - {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, - vbr_uhb_thresh, - 2 + QCONST16(0.7f,15), + {NULL, &wb_submode1, NULL, NULL, NULL, NULL, NULL, NULL}, + 1, + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, + {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, +#ifndef DISABLE_VBR + vbr_uhb_thresh, +#endif + 2 }; int wb_mode_query(const void *mode, int request, void *ptr) diff --git a/libspeex/nb_celp.c b/libspeex/nb_celp.c index d637637..b1d8592 100644 --- a/libspeex/nb_celp.c +++ b/libspeex/nb_celp.c @@ -185,6 +185,7 @@ void *nb_encoder_init(const SpeexMode *m) st->pitch = (int*)speex_alloc((st->nbSubframes)*sizeof(int)); +#ifndef DISABLE_VBR st->vbr = (VBRState*)speex_alloc(sizeof(VBRState)); vbr_init(st->vbr); st->vbr_quality = 8; @@ -192,13 +193,16 @@ void *nb_encoder_init(const SpeexMode *m) st->vbr_max = 0; st->vad_enabled = 0; st->dtx_enabled = 0; + st->dtx_count=0; st->abr_enabled = 0; st->abr_drift = 0; + st->abr_drift2 = 0; + st->abr_drift = 0; +#endif /* #ifndef DISABLE_VBR */ st->plc_tuning = 2; st->complexity=2; st->sampling_rate=8000; - st->dtx_count=0; st->isWideband = 0; st->highpass_enabled = 1; @@ -230,8 +234,10 @@ void nb_encoder_destroy(void *state) speex_free (st->pi_gain); speex_free (st->pitch); +#ifndef DISABLE_VBR vbr_destroy(st->vbr); speex_free (st->vbr); +#endif /* #ifndef DISABLE_VBR */ #ifdef VORBIS_PSYCHO vorbis_psy_destroy(st->psy); @@ -344,8 +350,11 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) /*Open-loop pitch*/ - if (!st->submodes[st->submodeID] || (st->complexity>2 && SUBMODE(have_subframe_gain)<3) || st->vbr_enabled || st->vad_enabled || SUBMODE(forced_pitch_gain) || - SUBMODE(lbr_pitch) != -1) + if (!st->submodes[st->submodeID] || (st->complexity>2 && SUBMODE(have_subframe_gain)<3) || SUBMODE(forced_pitch_gain) || SUBMODE(lbr_pitch) != -1 +#ifndef DISABLE_VBR + || st->vbr_enabled || st->vad_enabled +#endif + ) { int nol_pitch[6]; spx_word16_t nol_pitch_coef[6]; @@ -418,6 +427,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) #endif /*VBR stuff*/ +#ifndef DISABLE_VBR if (st->vbr && (st->vbr_enabled||st->vad_enabled)) { float lsp_dist=0; @@ -529,6 +539,7 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) } else { st->relative_quality = -1; } +#endif /* #ifndef DISABLE_VBR */ if (st->encode_submode) { @@ -907,9 +918,11 @@ int nb_encode(void *state, void *vin, SpeexBits *bits) if (st->submodeID==1) { +#ifndef DISABLE_VBR if (st->dtx_count) speex_bits_pack(bits, 15, 4); else +#endif speex_bits_pack(bits, 0, 4); } @@ -1604,7 +1617,8 @@ int nb_encoder_ctl(void *state, int request, void *ptr) case SPEEX_GET_MODE: (*(spx_int32_t*)ptr) = st->submodeID; break; - case SPEEX_SET_VBR: +#ifndef DISABLE_VBR + case SPEEX_SET_VBR: st->vbr_enabled = (*(spx_int32_t*)ptr); break; case SPEEX_GET_VBR: @@ -1652,12 +1666,15 @@ int nb_encoder_ctl(void *state, int request, void *ptr) 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); @@ -1735,12 +1752,14 @@ int nb_encoder_ctl(void *state, int request, void *ptr) 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; @@ -1764,9 +1783,11 @@ int nb_encoder_ctl(void *state, int request, void *ptr) ((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; @@ -1858,6 +1879,8 @@ int nb_decoder_ctl(void *state, int request, void *ptr) 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; @@ -1871,6 +1894,7 @@ int nb_decoder_ctl(void *state, int request, void *ptr) (*(spx_int32_t*)ptr) = (int)(100*ret); } break; +#endif case SPEEX_GET_PI_GAIN: { int i; diff --git a/libspeex/nb_celp.h b/libspeex/nb_celp.h index eac1261..14c776f 100644 --- a/libspeex/nb_celp.h +++ b/libspeex/nb_celp.h @@ -92,7 +92,8 @@ typedef struct EncState { spx_mem_t mem_hp[2]; /**< High-pass filter memory */ spx_word32_t *pi_gain; /**< Gain of LPC filter at theta=pi (fe/2) */ spx_word16_t *innov_rms_save; /**< If non-NULL, innovation RMS is copied here */ - + +#ifndef DISABLE_VBR VBRState *vbr; /**< State of the VBR data */ float vbr_quality; /**< Quality setting for VBR encoding */ float relative_quality; /**< Relative quality that will be needed by VBR */ @@ -105,6 +106,8 @@ typedef struct EncState { float abr_drift; float abr_drift2; float abr_count; +#endif /* #ifndef DISABLE_VBR */ + int complexity; /**< Complexity setting (0-10 from least complex to most complex) */ spx_int32_t sampling_rate; int plc_tuning; diff --git a/libspeex/sb_celp.c b/libspeex/sb_celp.c index 0f4ea24..619512c 100644 --- a/libspeex/sb_celp.c +++ b/libspeex/sb_celp.c @@ -253,6 +253,7 @@ void *sb_encoder_init(const SpeexMode *m) for (i=0;ilpcSize;i++) st->old_lsp[i]= DIV32(MULT16_16(QCONST16(3.1415927f, LSP_SHIFT), i+1), st->lpcSize+1); +#ifndef DISABLE_VBR st->vbr_quality = 8; st->vbr_enabled = 0; st->vbr_max = 0; @@ -260,6 +261,7 @@ void *sb_encoder_init(const SpeexMode *m) st->vad_enabled = 0; st->abr_enabled = 0; st->relative_quality=0; +#endif /* #ifndef DISABLE_VBR */ st->complexity=2; speex_encoder_ctl(st->st_low, SPEEX_GET_SAMPLING_RATE, &st->sampling_rate); @@ -336,6 +338,7 @@ int sb_encode(void *state, void *vin, SpeexBits *bits) /* Compute the two sub-bands by filtering with QMF h0*/ qmf_decomp(in, h0, low, high, st->full_frame_size, QMF_ORDER, st->h0_mem, stack); +#ifndef DISABLE_VBR if (st->vbr_enabled || st->vad_enabled) { /* Need to compute things here before the signal is trashed by the encoder */ @@ -343,6 +346,8 @@ int sb_encode(void *state, void *vin, SpeexBits *bits) e_low = compute_rms16(low, st->frame_size); e_high = compute_rms16(high, st->frame_size); } +#endif /* #ifndef DISABLE_VBR */ + ALLOC(low_innov_rms, st->nbSubframes, spx_word16_t); speex_encoder_ctl(st->st_low, SPEEX_SET_INNOVATION_SAVE, low_innov_rms); /* Encode the narrowband part*/ @@ -418,6 +423,7 @@ int sb_encode(void *state, void *vin, SpeexBits *bits) } } +#ifndef DISABLE_VBR /* VBR code */ if ((st->vbr_enabled || st->vad_enabled) && !dtx) { @@ -494,6 +500,7 @@ int sb_encode(void *state, void *vin, SpeexBits *bits) } /*fprintf (stderr, "%f %f\n", ratio, low_qual);*/ } +#endif /* #ifndef DISABLE_VBR */ if (st->encode_submode) { @@ -1127,6 +1134,7 @@ int sb_encoder_ctl(void *state, int request, void *ptr) 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); @@ -1141,6 +1149,8 @@ int sb_encoder_ctl(void *state, int request, void *ptr) 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; @@ -1158,6 +1168,8 @@ int sb_encoder_ctl(void *state, int request, void *ptr) 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; @@ -1188,6 +1200,8 @@ int sb_encoder_ctl(void *state, int request, void *ptr) 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; @@ -1274,6 +1288,7 @@ int sb_encoder_ctl(void *state, int request, void *ptr) 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); @@ -1305,6 +1320,7 @@ int sb_encoder_ctl(void *state, int request, void *ptr) 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; @@ -1329,9 +1345,11 @@ int sb_encoder_ctl(void *state, int request, void *ptr) ((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; diff --git a/libspeex/sb_celp.h b/libspeex/sb_celp.h index c2e28bf..e8c3761 100644 --- a/libspeex/sb_celp.h +++ b/libspeex/sb_celp.h @@ -72,6 +72,7 @@ typedef struct SBEncState { spx_word16_t *exc_rms; spx_word16_t *innov_rms_save; /**< If non-NULL, innovation is copied here */ +#ifndef DISABLE_VBR float vbr_quality; /**< Quality setting for VBR encoding */ int vbr_enabled; /**< 1 for enabling VBR, 0 otherwise */ spx_int32_t vbr_max; /**< Max bit-rate allowed in VBR mode (total) */ @@ -82,7 +83,8 @@ typedef struct SBEncState { float abr_count; int vad_enabled; /**< 1 for enabling VAD, 0 otherwise */ float relative_quality; - +#endif /* #ifndef DISABLE_VBR */ + int encode_submode; const SpeexSubmode * const *submodes; int submodeID; diff --git a/libspeex/speex.c b/libspeex/speex.c index b6bfbd1..78e1a7a 100644 --- a/libspeex/speex.c +++ b/libspeex/speex.c @@ -84,6 +84,7 @@ int speex_decode_native(void *state, SpeexBits *bits, spx_word16_t *out) #ifdef FIXED_POINT +#ifndef DISABLE_FLOAT_API int speex_encode(void *state, float *in, SpeexBits *bits) { int i; @@ -101,6 +102,7 @@ int speex_encode(void *state, float *in, SpeexBits *bits) } return (*((SpeexMode**)state))->enc(state, short_in, bits); } +#endif /* #ifndef DISABLE_FLOAT_API */ int speex_encode_int(void *state, spx_int16_t *in, SpeexBits *bits) { @@ -109,6 +111,7 @@ int speex_encode_int(void *state, spx_int16_t *in, SpeexBits *bits) return (mode)->enc(state, in, bits); } +#ifndef DISABLE_FLOAT_API int speex_decode(void *state, SpeexBits *bits, float *out) { int i, ret; @@ -120,6 +123,7 @@ int speex_decode(void *state, SpeexBits *bits, float *out) out[i] = short_out[i]; return ret; } +#endif /* #ifndef DISABLE_FLOAT_API */ int speex_decode_int(void *state, SpeexBits *bits, spx_int16_t *out) { diff --git a/libspeex/speex_callbacks.c b/libspeex/speex_callbacks.c index b884775..d1158b2 100644 --- a/libspeex/speex_callbacks.c +++ b/libspeex/speex_callbacks.c @@ -96,6 +96,7 @@ int speex_std_high_mode_request_handler(SpeexBits *bits, void *state, void *data return 0; } +#ifndef DISABLE_VBR int speex_std_vbr_request_handler(SpeexBits *bits, void *state, void *data) { spx_int32_t vbr; @@ -103,6 +104,7 @@ int speex_std_vbr_request_handler(SpeexBits *bits, void *state, void *data) speex_encoder_ctl(data, SPEEX_SET_VBR, &vbr); return 0; } +#endif /* #ifndef DISABLE_VBR */ int speex_std_enh_request_handler(SpeexBits *bits, void *state, void *data) { @@ -112,6 +114,7 @@ int speex_std_enh_request_handler(SpeexBits *bits, void *state, void *data) return 0; } +#ifndef DISABLE_VBR int speex_std_vbr_quality_request_handler(SpeexBits *bits, void *state, void *data) { float qual; @@ -119,7 +122,7 @@ int speex_std_vbr_quality_request_handler(SpeexBits *bits, void *state, void *da speex_encoder_ctl(data, SPEEX_SET_VBR_QUALITY, &qual); return 0; } - +#endif /* #ifndef DISABLE_VBR */ int speex_std_char_handler(SpeexBits *bits, void *state, void *data) { diff --git a/libspeex/stereo.c b/libspeex/stereo.c index a8bdfdd..bc6e1ba 100644 --- a/libspeex/stereo.c +++ b/libspeex/stereo.c @@ -104,6 +104,7 @@ void speex_stereo_state_destroy(SpeexStereoState *stereo) speex_free(stereo); } +#ifndef DISABLE_FLOAT_API void speex_encode_stereo(float *data, int frame_size, SpeexBits *bits) { int i, tmp; @@ -140,6 +141,7 @@ void speex_encode_stereo(float *data, int frame_size, SpeexBits *bits) tmp=scal_quant(e_ratio*Q15_ONE, e_ratio_quant_bounds, 4); speex_bits_pack(bits, tmp, 2); } +#endif /* #ifndef DISABLE_FLOAT_API */ void speex_encode_stereo_int(spx_int16_t *data, int frame_size, SpeexBits *bits) { @@ -215,6 +217,7 @@ void speex_encode_stereo_int(spx_int16_t *data, int frame_size, SpeexBits *bits) speex_bits_pack(bits, tmp, 2); } +#ifndef DISABLE_FLOAT_API void speex_decode_stereo(float *data, int frame_size, SpeexStereoState *_stereo) { int i; @@ -240,6 +243,7 @@ void speex_decode_stereo(float *data, int frame_size, SpeexStereoState *_stereo) data[2*i+1] = (float)MULT16_16_P14(stereo->smooth_right, tmp); } } +#endif /* #ifndef DISABLE_FLOAT_API */ void speex_decode_stereo_int(spx_int16_t *data, int frame_size, SpeexStereoState *_stereo) { diff --git a/libspeex/testenc.c b/libspeex/testenc.c index 3dbfa96..44c132f 100644 --- a/libspeex/testenc.c +++ b/libspeex/testenc.c @@ -19,7 +19,6 @@ int main(int argc, char **argv) FILE *fin, *fout, *fbits=NULL; short in_short[FRAME_SIZE]; short out_short[FRAME_SIZE]; - float sigpow,errpow,snr, seg_snr=0; int snr_frames = 0; char cbits[200]; int nbBits; @@ -32,9 +31,6 @@ int main(int argc, char **argv) spx_int32_t skip_group_delay; SpeexCallback callback; - sigpow = 0; - errpow = 0; - st = speex_encoder_init(speex_lib_get_mode(SPEEX_MODEID_NB)); dec = speex_decoder_init(speex_lib_get_mode(SPEEX_MODEID_NB)); @@ -109,6 +105,12 @@ int main(int argc, char **argv) speex_decoder_destroy(dec); speex_bits_destroy(&bits); +#ifndef DISABLE_FLOAT_API + { + float sigpow,errpow,snr, seg_snr=0; + sigpow = 0; + errpow = 0; + /* This code just computes SNR, so you don't need it either */ rewind(fin); rewind(fout); @@ -127,9 +129,6 @@ int main(int argc, char **argv) errpow += e; snr_frames++; } - fclose(fin); - fclose(fout); - snr = 10 * log10( sigpow / errpow ); seg_snr /= snr_frames; fprintf(stderr,"SNR = %f\nsegmental SNR = %f\n",snr, seg_snr); @@ -137,6 +136,11 @@ int main(int argc, char **argv) #ifdef FIXED_DEBUG printf ("Total: %f MIPS\n", (float)(1e-6*50*spx_mips/snr_frames)); #endif - + } +#endif + + fclose(fin); + fclose(fout); + return 0; } diff --git a/libspeex/vbr.c b/libspeex/vbr.c index fa74620..5b7dd9b 100644 --- a/libspeex/vbr.c +++ b/libspeex/vbr.c @@ -45,6 +45,7 @@ #define MIN_ENERGY 6000 #define NOISE_POW .3 +#ifndef DISABLE_VBR const float vbr_nb_thresh[9][11]={ {-1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f, -1.0f}, /* CNG */ @@ -270,3 +271,5 @@ float vbr_analysis(VBRState *vbr, spx_word16_t *sig, int len, int pitch, float p void vbr_destroy(VBRState *vbr) { } + +#endif /* #ifndef DISABLE_VBR */ -- cgit v1.2.3