[xiph-commits] r14181 - trunk/speex/libspeex
jm at svn.xiph.org
jm at svn.xiph.org
Sat Nov 17 20:57:56 PST 2007
Author: jm
Date: 2007-11-17 20:57:55 -0800 (Sat, 17 Nov 2007)
New Revision: 14181
Modified:
trunk/speex/libspeex/modes.h
trunk/speex/libspeex/modes_wb.c
trunk/speex/libspeex/nb_celp.c
trunk/speex/libspeex/nb_celp.h
trunk/speex/libspeex/sb_celp.c
trunk/speex/libspeex/sb_celp.h
trunk/speex/libspeex/speex.c
trunk/speex/libspeex/speex_callbacks.c
trunk/speex/libspeex/stereo.c
trunk/speex/libspeex/testenc.c
trunk/speex/libspeex/vbr.c
Log:
New DISABLE_VBR and DISABLE_FLOAT_API switches can together remove every single
float operation out of libspeex.
Modified: trunk/speex/libspeex/modes.h
===================================================================
--- trunk/speex/libspeex/modes.h 2007-11-18 04:25:29 UTC (rev 14180)
+++ trunk/speex/libspeex/modes.h 2007-11-18 04:57:55 UTC (rev 14181)
@@ -146,7 +146,9 @@
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;
Modified: trunk/speex/libspeex/modes_wb.c
===================================================================
--- trunk/speex/libspeex/modes_wb.c 2007-11-18 04:25:29 UTC (rev 14180)
+++ trunk/speex/libspeex/modes_wb.c 2007-11-18 04:57:55 UTC (rev 14181)
@@ -188,13 +188,15 @@
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 @@
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)
Modified: trunk/speex/libspeex/nb_celp.c
===================================================================
--- trunk/speex/libspeex/nb_celp.c 2007-11-18 04:25:29 UTC (rev 14180)
+++ trunk/speex/libspeex/nb_celp.c 2007-11-18 04:57:55 UTC (rev 14181)
@@ -185,6 +185,7 @@
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 @@
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 @@
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 @@
/*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 @@
#endif
/*VBR stuff*/
+#ifndef DISABLE_VBR
if (st->vbr && (st->vbr_enabled||st->vad_enabled))
{
float lsp_dist=0;
@@ -529,6 +539,7 @@
} else {
st->relative_quality = -1;
}
+#endif /* #ifndef DISABLE_VBR */
if (st->encode_submode)
{
@@ -907,9 +918,11 @@
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 @@
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 @@
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 @@
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 @@
((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 @@
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 @@
(*(spx_int32_t*)ptr) = (int)(100*ret);
}
break;
+#endif
case SPEEX_GET_PI_GAIN:
{
int i;
Modified: trunk/speex/libspeex/nb_celp.h
===================================================================
--- trunk/speex/libspeex/nb_celp.h 2007-11-18 04:25:29 UTC (rev 14180)
+++ trunk/speex/libspeex/nb_celp.h 2007-11-18 04:57:55 UTC (rev 14181)
@@ -92,7 +92,8 @@
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 @@
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;
Modified: trunk/speex/libspeex/sb_celp.c
===================================================================
--- trunk/speex/libspeex/sb_celp.c 2007-11-18 04:25:29 UTC (rev 14180)
+++ trunk/speex/libspeex/sb_celp.c 2007-11-18 04:57:55 UTC (rev 14181)
@@ -253,6 +253,7 @@
for (i=0;i<st->lpcSize;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 @@
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 @@
/* 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 @@
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 @@
}
}
+#ifndef DISABLE_VBR
/* VBR code */
if ((st->vbr_enabled || st->vad_enabled) && !dtx)
{
@@ -494,6 +500,7 @@
}
/*fprintf (stderr, "%f %f\n", ratio, low_qual);*/
}
+#endif /* #ifndef DISABLE_VBR */
if (st->encode_submode)
{
@@ -1127,6 +1134,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
((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;
Modified: trunk/speex/libspeex/sb_celp.h
===================================================================
--- trunk/speex/libspeex/sb_celp.h 2007-11-18 04:25:29 UTC (rev 14180)
+++ trunk/speex/libspeex/sb_celp.h 2007-11-18 04:57:55 UTC (rev 14181)
@@ -72,6 +72,7 @@
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 @@
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;
Modified: trunk/speex/libspeex/speex.c
===================================================================
--- trunk/speex/libspeex/speex.c 2007-11-18 04:25:29 UTC (rev 14180)
+++ trunk/speex/libspeex/speex.c 2007-11-18 04:57:55 UTC (rev 14181)
@@ -84,6 +84,7 @@
#ifdef FIXED_POINT
+#ifndef DISABLE_FLOAT_API
int speex_encode(void *state, float *in, SpeexBits *bits)
{
int i;
@@ -101,6 +102,7 @@
}
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 @@
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 @@
out[i] = short_out[i];
return ret;
}
+#endif /* #ifndef DISABLE_FLOAT_API */
int speex_decode_int(void *state, SpeexBits *bits, spx_int16_t *out)
{
Modified: trunk/speex/libspeex/speex_callbacks.c
===================================================================
--- trunk/speex/libspeex/speex_callbacks.c 2007-11-18 04:25:29 UTC (rev 14180)
+++ trunk/speex/libspeex/speex_callbacks.c 2007-11-18 04:57:55 UTC (rev 14181)
@@ -96,6 +96,7 @@
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 @@
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 @@
return 0;
}
+#ifndef DISABLE_VBR
int speex_std_vbr_quality_request_handler(SpeexBits *bits, void *state, void *data)
{
float qual;
@@ -119,8 +122,8 @@
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)
{
unsigned char ch;
Modified: trunk/speex/libspeex/stereo.c
===================================================================
--- trunk/speex/libspeex/stereo.c 2007-11-18 04:25:29 UTC (rev 14180)
+++ trunk/speex/libspeex/stereo.c 2007-11-18 04:57:55 UTC (rev 14181)
@@ -104,6 +104,7 @@
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 @@
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 @@
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 @@
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)
{
Modified: trunk/speex/libspeex/testenc.c
===================================================================
--- trunk/speex/libspeex/testenc.c 2007-11-18 04:25:29 UTC (rev 14180)
+++ trunk/speex/libspeex/testenc.c 2007-11-18 04:57:55 UTC (rev 14181)
@@ -19,7 +19,6 @@
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 @@
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 @@
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 @@
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 @@
#ifdef FIXED_DEBUG
printf ("Total: %f MIPS\n", (float)(1e-6*50*spx_mips/snr_frames));
#endif
-
+ }
+#endif
+
+ fclose(fin);
+ fclose(fout);
+
return 0;
}
Modified: trunk/speex/libspeex/vbr.c
===================================================================
--- trunk/speex/libspeex/vbr.c 2007-11-18 04:25:29 UTC (rev 14180)
+++ trunk/speex/libspeex/vbr.c 2007-11-18 04:57:55 UTC (rev 14181)
@@ -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 @@
void vbr_destroy(VBRState *vbr)
{
}
+
+#endif /* #ifndef DISABLE_VBR */
More information about the commits
mailing list