[xiph-cvs] r6558 - in trunk/speex: . doc libspeex src
jm at xiph.org
jm at xiph.org
Tue May 4 21:23:10 PDT 2004
Author: jm
Date: 2004-04-20 17:52:01 -0400 (Tue, 20 Apr 2004)
New Revision: 6558
Modified:
trunk/speex/Speex.kdevelop
trunk/speex/doc/manual.lyx
trunk/speex/libspeex/filters.c
trunk/speex/libspeex/filters.h
trunk/speex/libspeex/jitter.c
trunk/speex/libspeex/modes.c
trunk/speex/libspeex/modes.h
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.h
trunk/speex/libspeex/speex_stereo.h
trunk/speex/libspeex/stereo.c
trunk/speex/libspeex/testenc.c
trunk/speex/libspeex/testenc_uwb.c
trunk/speex/libspeex/testenc_wb.c
trunk/speex/libspeex/vbr.c
trunk/speex/libspeex/vbr.h
trunk/speex/src/speexdec.c
trunk/speex/src/speexenc.c
Log:
speex_encode/speex_decode are back to using floats, new speex_encode_int
and speex_decode_int for the short version
<p>Modified: trunk/speex/Speex.kdevelop
===================================================================
--- trunk/speex/Speex.kdevelop 2004-04-20 18:02:23 UTC (rev 6557)
+++ trunk/speex/Speex.kdevelop 2004-04-20 21:52:01 UTC (rev 6558)
@@ -9,7 +9,7 @@
<ignoreparts/>
<projectdirectory>.</projectdirectory>
<absoluteprojectpath>false</absoluteprojectpath>
- <description></description>
+ <description/>
<secondaryLanguages/>
</general>
<kdevautoproject>
@@ -57,11 +57,11 @@
<kdevdebugger>
<general>
<dbgshell>libtool</dbgshell>
- <programargs></programargs>
- <gdbpath></gdbpath>
- <configGdbScript></configGdbScript>
- <runShellScript></runShellScript>
- <runGdbScript></runGdbScript>
+ <programargs/>
+ <gdbpath/>
+ <configGdbScript/>
+ <runShellScript/>
+ <runGdbScript/>
<breakonloadinglibs>true</breakonloadinglibs>
<separatetty>false</separatetty>
<floatingtoolbar>false</floatingtoolbar>
Modified: trunk/speex/doc/manual.lyx
===================================================================
--- trunk/speex/doc/manual.lyx 2004-04-20 18:02:23 UTC (rev 6557)
+++ trunk/speex/doc/manual.lyx 2004-04-20 21:52:01 UTC (rev 6558)
@@ -5515,7 +5515,7 @@
files (I prefer to call them just Speex files).
One difference with Vorbis however, is that Speex is less tied with Ogg.
- Actually, if you just do Voice of IP (VoIP), you don't need Ogg at all.
+ Actually, if you just do Voice over IP (VoIP), you don't need Ogg at all.
\layout Subsection*
What's the extension for Speex?
@@ -5664,7 +5664,11 @@
and how does Speex fit into that?
\layout Standard
-Currently (2003/03/09), I'm doing a Ph.D.
+Currently (2004/04/06), I'm doing my
+\emph on
+Ph.D.
+
+\emph default
at the University of Sherbrooke in mobile robotics.
Although I did my master with the Sherbrooke speech coding group (in speech
enhancement, not coding), I am not associated with them anymore.
@@ -5672,8 +5676,8 @@
\series bold
not
\series default
- be understood that they or the University of Sherbrooke endorse the Speex
- project in any way.
+ be understood that they or the University of Sherbrooke have anything to
+ do with the Speex project.
Furthermore, Speex does not make use of any code or proprietary technology
developed in the Sherbrooke speech coding group.
Modified: trunk/speex/libspeex/filters.c
===================================================================
--- trunk/speex/libspeex/filters.c 2004-04-20 18:02:23 UTC (rev 6557)
+++ trunk/speex/libspeex/filters.c 2004-04-20 21:52:01 UTC (rev 6558)
@@ -345,7 +345,7 @@
fir_mem2(y, awk2, y, N, ord, mem);
}
-void qmf_decomp(const short *xx, const spx_word16_t *aa, spx_sig_t *y1, spx_sig_t *y2, int N, int M, spx_word16_t *mem, char *stack)
+void qmf_decomp(const spx_word16_t *xx, const spx_word16_t *aa, spx_sig_t *y1, spx_sig_t *y2, int N, int M, spx_word16_t *mem, char *stack)
{
int i,j,k,M2;
spx_word16_t *a;
Modified: trunk/speex/libspeex/filters.h
===================================================================
--- trunk/speex/libspeex/filters.h 2004-04-20 18:02:23 UTC (rev 6557)
+++ trunk/speex/libspeex/filters.h 2004-04-20 21:52:01 UTC (rev 6558)
@@ -52,7 +52,7 @@
} CombFilterMem;
-void qmf_decomp(const short *xx, const spx_word16_t *aa, spx_sig_t *y1, spx_sig_t *y2, int N, int M, spx_word16_t *mem, char *stack);
+void qmf_decomp(const spx_word16_t *xx, const spx_word16_t *aa, spx_sig_t *y1, spx_sig_t *y2, int N, int M, spx_word16_t *mem, char *stack);
void fir_mem_up(const spx_sig_t *x, const spx_word16_t *a, spx_sig_t *y, int N, int M, spx_word32_t *mem, char *stack);
Modified: trunk/speex/libspeex/jitter.c
===================================================================
--- trunk/speex/libspeex/jitter.c 2004-04-20 18:02:23 UTC (rev 6557)
+++ trunk/speex/libspeex/jitter.c 2004-04-20 21:52:01 UTC (rev 6558)
@@ -130,7 +130,7 @@
/* Handle frame interpolation (receiving too fast) */
if (jitter->interp_frame)
{
- speex_decode(jitter->dec, NULL, out);
+ speex_decode_int(jitter->dec, NULL, out);
jitter->interp_frame = 0;
return;
}
@@ -166,7 +166,7 @@
if (jitter->valid_bits)
{
/* Try decoding last received packet */
- ret = speex_decode(jitter->dec, &jitter->current_packet, out);
+ ret = speex_decode_int(jitter->dec, &jitter->current_packet, out);
if (ret == 0)
return;
else
@@ -174,13 +174,13 @@
}
/*Packet is late or lost*/
- speex_decode(jitter->dec, NULL, out);
+ speex_decode_int(jitter->dec, NULL, out);
} else {
/* Found the right packet */
speex_bits_read_from(&jitter->current_packet, jitter->buf[i], jitter->len[i]);
jitter->len[i]=-1;
/* Decode packet */
- ret = speex_decode(jitter->dec, &jitter->current_packet, out);
+ ret = speex_decode_int(jitter->dec, &jitter->current_packet, out);
if (ret == 0)
{
jitter->valid_bits = 1;
Modified: trunk/speex/libspeex/modes.c
===================================================================
--- trunk/speex/libspeex/modes.c 2004-04-20 18:02:23 UTC (rev 6557)
+++ trunk/speex/libspeex/modes.c 2004-04-20 21:52:01 UTC (rev 6558)
@@ -40,11 +40,14 @@
#include "nb_celp.h"
#include "vbr.h"
#include "misc.h"
+#include <math.h>
#ifndef NULL
#define NULL 0
#endif
+#define MAX_IN_SAMPLES 640
+
const SpeexMode *speex_mode_list[SPEEX_NB_MODES] = {&speex_nb_mode, &speex_wb_mode, &speex_uwb_mode};
/* Extern declarations for all codebooks we use here */
@@ -702,22 +705,113 @@
(*((SpeexMode**)state))->enc_destroy(state);
}
-int speex_encode(void *state, short *in, SpeexBits *bits)
+void speex_decoder_destroy(void *state)
{
+ (*((SpeexMode**)state))->dec_destroy(state);
+}
+
+
+
+int speex_encode_native(void *state, spx_word16_t *in, SpeexBits *bits)
+{
return (*((SpeexMode**)state))->enc(state, in, bits);
}
-void speex_decoder_destroy(void *state)
+int speex_decode_native(void *state, SpeexBits *bits, spx_word16_t *out)
{
- (*((SpeexMode**)state))->dec_destroy(state);
+ return (*((SpeexMode**)state))->dec(state, bits, out);
}
-int speex_decode(void *state, SpeexBits *bits, short *out)
+
+
+#ifdef FIXED_POINT
+
+int speex_encode(void *state, float *in, SpeexBits *bits)
{
+ int i;
+ int N;
+ short short_in[MAX_IN_SAMPLES];
+ speex_encoder_ctl(state, SPEEX_GET_FRAME_SIZE, &N);
+ for (i=0;i<N;i++)
+ {
+ if (in[i]>32767.f)
+ short_in[i] = 32767;
+ else if (in[i]<-32768.f)
+ short_in[i] = -32768;
+ else
+ short_in[i] = (short)floor(.5+in[i]);
+ }
+ return (*((SpeexMode**)state))->enc(state, short_in, bits);
+}
+
+int speex_encode_int(void *state, short *in, SpeexBits *bits)
+{
+ return (*((SpeexMode**)state))->enc(state, in, bits);
+}
+
+int speex_decode(void *state, SpeexBits *bits, float *out)
+{
+ int i, ret;
+ int N;
+ float short_out[MAX_IN_SAMPLES];
+ speex_decoder_ctl(state, SPEEX_GET_FRAME_SIZE, &N);
+ ret = (*((SpeexMode**)state))->dec(state, bits, short_out);
+ for (i=0;i<N;i++)
+ out[i] = short_out[i];
+ return ret;
+}
+
+int speex_decode_int(void *state, SpeexBits *bits, short *out)
+{
return (*((SpeexMode**)state))->dec(state, bits, out);
}
+#else
+int speex_encode(void *state, float *in, SpeexBits *bits)
+{
+ return (*((SpeexMode**)state))->enc(state, in, bits);
+}
+
+int speex_encode_int(void *state, short *in, SpeexBits *bits)
+{
+ int i;
+ int N;
+ float float_in[MAX_IN_SAMPLES];
+ speex_encoder_ctl(state, SPEEX_GET_FRAME_SIZE, &N);
+ for (i=0;i<N;i++)
+ float_in[i] = in[i];
+ return (*((SpeexMode**)state))->enc(state, float_in, bits);
+}
+
+int speex_decode(void *state, SpeexBits *bits, float *out)
+{
+ return (*((SpeexMode**)state))->dec(state, bits, out);
+}
+
+int speex_decode_int(void *state, SpeexBits *bits, short *out)
+{
+ int i;
+ int N;
+ float float_out[MAX_IN_SAMPLES];
+ int ret;
+ speex_decoder_ctl(state, SPEEX_GET_FRAME_SIZE, &N);
+ ret = (*((SpeexMode**)state))->dec(state, bits, float_out);
+ for (i=0;i<N;i++)
+ {
+ if (float_out[i]>32767.f)
+ out[i] = 32767;
+ else if (float_out[i]<-32768.f)
+ out[i] = -32768;
+ else
+ out[i] = (short)floor(.5+float_out[i]);
+ }
+ return ret;
+}
+#endif
+
+
+
int speex_encoder_ctl(void *state, int request, void *ptr)
{
return (*((SpeexMode**)state))->enc_ctl(state, request, ptr);
Modified: trunk/speex/libspeex/modes.h
===================================================================
--- trunk/speex/libspeex/modes.h 2004-04-20 18:02:23 UTC (rev 6557)
+++ trunk/speex/libspeex/modes.h 2004-04-20 21:52:01 UTC (rev 6558)
@@ -145,5 +145,7 @@
int nb_modes;
} SpeexSBMode;
+int speex_encode_native(void *state, spx_word16_t *in, SpeexBits *bits);
+int speex_decode_native(void *state, SpeexBits *bits, spx_word16_t *out);
#endif
Modified: trunk/speex/libspeex/nb_celp.c
===================================================================
--- trunk/speex/libspeex/nb_celp.c 2004-04-20 18:02:23 UTC (rev 6557)
+++ trunk/speex/libspeex/nb_celp.c 2004-04-20 21:52:01 UTC (rev 6558)
@@ -215,7 +215,7 @@
speex_free(st);
}
-int nb_encode(void *state, short *in, SpeexBits *bits)
+int nb_encode(void *state, void *vin, SpeexBits *bits)
{
EncState *st;
int i, sub, roots;
@@ -231,6 +231,7 @@
int pitch_half[2];
int ol_pitch_id=0;
#endif
+ spx_word16_t *in = vin;
st=(EncState *)state;
stack=st->stack;
@@ -1024,7 +1025,7 @@
#define median3(a, b, c) ((a) < (b) ? ((b) < (c) ? (b) : ((a) < (c) ? (c) : (a))) : ((c) < (b) ? (b) : ((c) < (a) ? (c) : (a))))
-static void nb_decode_lost(DecState *st, short *out, char *stack)
+static void nb_decode_lost(DecState *st, spx_word16_t *out, char *stack)
{
int i, sub;
spx_coef_t *awk1, *awk2, *awk3;
@@ -1137,7 +1138,7 @@
st->pitch_gain_buf_idx = 0;
}
-int nb_decode(void *state, SpeexBits *bits, short *out)
+int nb_decode(void *state, SpeexBits *bits, void *vout)
{
DecState *st;
int i, sub;
@@ -1157,6 +1158,7 @@
int pitch_half[2];
int ol_pitch_id=0;
#endif
+ spx_word16_t *out = vout;
st=(DecState*)state;
stack=st->stack;
Modified: trunk/speex/libspeex/nb_celp.h
===================================================================
--- trunk/speex/libspeex/nb_celp.h 2004-04-20 18:02:23 UTC (rev 6557)
+++ trunk/speex/libspeex/nb_celp.h 2004-04-20 21:52:01 UTC (rev 6558)
@@ -183,7 +183,7 @@
void nb_encoder_destroy(void *state);
/** Encodes one frame*/
-int nb_encode(void *state, short *in, SpeexBits *bits);
+int nb_encode(void *state, void *in, SpeexBits *bits);
/** Initializes decoder state*/
@@ -193,7 +193,7 @@
void nb_decoder_destroy(void *state);
/** Decodes one frame*/
-int nb_decode(void *state, SpeexBits *bits, short *out);
+int nb_decode(void *state, SpeexBits *bits, void *out);
/** ioctl-like function for controlling a narrowband encoder */
int nb_encoder_ctl(void *state, int request, void *ptr);
Modified: trunk/speex/libspeex/sb_celp.c
===================================================================
--- trunk/speex/libspeex/sb_celp.c 2004-04-20 18:02:23 UTC (rev 6557)
+++ trunk/speex/libspeex/sb_celp.c 2004-04-20 21:52:01 UTC (rev 6558)
@@ -147,7 +147,7 @@
};
#endif
-static void mix_and_saturate(spx_word32_t *y0, spx_word32_t *y1, short *out, int len)
+static void mix_and_saturate(spx_word32_t *y0, spx_word32_t *y1, spx_word16_t *out, int len)
{
int i;
for (i=0;i<len;i++)
@@ -279,7 +279,7 @@
}
-int sb_encode(void *state, short *in, SpeexBits *bits)
+int sb_encode(void *state, void *vin, SpeexBits *bits)
{
SBEncState *st;
int i, roots, sub;
@@ -290,13 +290,14 @@
spx_sig_t *low_exc, *low_innov;
SpeexSBMode *mode;
int dtx;
+ spx_word16_t *in = vin;
st = (SBEncState*)state;
stack=st->stack;
mode = (SpeexSBMode*)(st->mode->mode);
{
- short *low = PUSH(stack, st->frame_size, short);
+ spx_word16_t *low = PUSH(stack, st->frame_size, spx_word16_t);
/* Compute the two sub-bands by filtering with h0 and h1*/
qmf_decomp(in, h0, st->x0d, st->x1d, st->full_frame_size, QMF_ORDER, st->h0_mem, stack);
@@ -305,7 +306,7 @@
low[i] = PSHR(st->x0d[i],SIG_SHIFT);
/* Encode the narrowband part*/
- speex_encode(st->st_low, low, bits);
+ speex_encode_native(st->st_low, low, bits);
for (i=0;i<st->frame_size;i++)
st->x0d[i] = SHL(low[i],SIG_SHIFT);
@@ -777,7 +778,7 @@
speex_free(state);
}
-static void sb_decode_lost(SBDecState *st, short *out, int dtx, char *stack)
+static void sb_decode_lost(SBDecState *st, spx_word16_t *out, int dtx, char *stack)
{
int i;
spx_coef_t *awk1, *awk2, *awk3;
@@ -857,7 +858,7 @@
return;
}
-int sb_decode(void *state, SpeexBits *bits, short *out)
+int sb_decode(void *state, SpeexBits *bits, void *vout)
{
int i, sub;
SBDecState *st;
@@ -869,17 +870,18 @@
spx_coef_t *awk1, *awk2, *awk3;
int dtx;
SpeexSBMode *mode;
-
+ spx_word16_t *out = vout;
+
st = (SBDecState*)state;
stack=st->stack;
mode = (SpeexSBMode*)(st->mode->mode);
{
- short *low;
- low = PUSH(stack, st->frame_size, short);
+ spx_word16_t *low;
+ low = PUSH(stack, st->frame_size, spx_word16_t);
/* Decode the low-band */
- ret = speex_decode(st->st_low, bits, low);
+ ret = speex_decode_native(st->st_low, bits, low);
for (i=0;i<st->frame_size;i++)
st->x0d[i] = low[i]*SIG_SCALING;
Modified: trunk/speex/libspeex/sb_celp.h
===================================================================
--- trunk/speex/libspeex/sb_celp.h 2004-04-20 18:02:23 UTC (rev 6557)
+++ trunk/speex/libspeex/sb_celp.h 2004-04-20 21:52:01 UTC (rev 6558)
@@ -150,7 +150,7 @@
void sb_encoder_destroy(void *state);
/**Encodes one frame*/
-int sb_encode(void *state, short *in, SpeexBits *bits);
+int sb_encode(void *state, void *in, SpeexBits *bits);
/**Initializes decoder state*/
@@ -160,7 +160,7 @@
void sb_decoder_destroy(void *state);
/**Decodes one frame*/
-int sb_decode(void *state, SpeexBits *bits, short *out);
+int sb_decode(void *state, SpeexBits *bits, void *out);
int sb_encoder_ctl(void *state, int request, void *ptr);
Modified: trunk/speex/libspeex/speex.h
===================================================================
--- trunk/speex/libspeex/speex.h 2004-04-20 18:02:23 UTC (rev 6557)
+++ trunk/speex/libspeex/speex.h 2004-04-20 21:52:01 UTC (rev 6558)
@@ -173,7 +173,7 @@
typedef void (*encoder_destroy_func)(void *st);
/** Main encoding function */
-typedef int (*encode_func)(void *state, short *in, SpeexBits *bits);
+typedef int (*encode_func)(void *state, void *in, SpeexBits *bits);
/** Function for controlling the encoder options */
typedef int (*encoder_ctl_func)(void *state, int request, void *ptr);
@@ -185,7 +185,7 @@
typedef void (*decoder_destroy_func)(void *st);
/** Main decoding function */
-typedef int (*decode_func)(void *state, SpeexBits *bits, short *out);
+typedef int (*decode_func)(void *state, SpeexBits *bits, void *out);
/** Function for controlling the decoder options */
typedef int (*decoder_ctl_func)(void *state, int request, void *ptr);
@@ -259,8 +259,16 @@
@param in Frame that will be encoded with a +-2^16 range
@param bits Bit-stream where the data will be written
*/
-int speex_encode(void *state, short *in, SpeexBits *bits);
+int speex_encode(void *state, float *in, SpeexBits *bits);
+/** Uses an existing encoder state to encode one frame of speech pointed to by
+ "in". The encoded bit-stream is saved in "bits".
+ @param state Encoder state
+ @param in Frame that will be encoded with a +-2^16 range
+ @param bits Bit-stream where the data will be written
+ */
+int speex_encode_int(void *state, short *in, SpeexBits *bits);
+
/** Used like the ioctl function to control the encoder parameters
*
* @param state Encoder state
@@ -295,8 +303,18 @@
* @param out Where to write the decoded frame
* @return return status (0 for no error, -1 for end of stream, -2 other)
*/
-int speex_decode(void *state, SpeexBits *bits, short *out);
+int speex_decode(void *state, SpeexBits *bits, float *out);
+/** Uses an existing decoder state to decode one frame of speech from
+ * bit-stream bits. The output speech is saved written to out.
+ *
+ * @param state Decoder state
+ * @param bits Bit-stream from which to decode the frame (NULL if the packet was lost)
+ * @param out Where to write the decoded frame
+ * @return return status (0 for no error, -1 for end of stream, -2 other)
+ */
+int speex_decode_int(void *state, SpeexBits *bits, short *out);
+
/** Used like the ioctl function to control the encoder parameters
*
* @param state Decoder state
Modified: trunk/speex/libspeex/speex_stereo.h
===================================================================
--- trunk/speex/libspeex/speex_stereo.h 2004-04-20 18:02:23 UTC (rev 6557)
+++ trunk/speex/libspeex/speex_stereo.h 2004-04-20 21:52:01 UTC (rev 6558)
@@ -55,11 +55,17 @@
#define SPEEX_STEREO_STATE_INIT {1,.5,1,1}
/** Transforms a stereo frame into a mono frame and stores intensity stereo info in 'bits' */
-void speex_encode_stereo(short *data, int frame_size, SpeexBits *bits);
+void speex_encode_stereo(float *data, int frame_size, SpeexBits *bits);
+/** Transforms a stereo frame into a mono frame and stores intensity stereo info in 'bits' */
+void speex_encode_stereo_int(short *data, int frame_size, SpeexBits *bits);
+
/** Transforms a mono frame into a stereo frame using intensity stereo info */
-void speex_decode_stereo(short *data, int frame_size, SpeexStereoState *stereo);
+void speex_decode_stereo(float *data, int frame_size, SpeexStereoState *stereo);
+/** Transforms a mono frame into a stereo frame using intensity stereo info */
+void speex_decode_stereo_int(short *data, int frame_size, SpeexStereoState *stereo);
+
/** Callback handler for intensity stereo info */
int speex_std_stereo_request_handler(SpeexBits *bits, void *state, void *data);
Modified: trunk/speex/libspeex/stereo.c
===================================================================
--- trunk/speex/libspeex/stereo.c 2004-04-20 18:02:23 UTC (rev 6557)
+++ trunk/speex/libspeex/stereo.c 2004-04-20 21:52:01 UTC (rev 6558)
@@ -37,7 +37,7 @@
/*float e_ratio_quant[4] = {1, 1.26, 1.587, 2};*/
static const float e_ratio_quant[4] = {.25f, .315f, .397f, .5f};
-void speex_encode_stereo(short *data, int frame_size, SpeexBits *bits)
+void speex_encode_stereo(float *data, int frame_size, SpeexBits *bits)
{
int i, tmp;
float e_left=0, e_right=0, e_tot=0;
@@ -74,9 +74,46 @@
speex_bits_pack(bits, tmp, 2);
}
-void speex_decode_stereo(short *data, int frame_size, SpeexStereoState *stereo)
+void speex_encode_stereo_int(short *data, int frame_size, SpeexBits *bits)
{
+ int i, tmp;
+ float e_left=0, e_right=0, e_tot=0;
float balance, e_ratio;
+ for (i=0;i<frame_size;i++)
+ {
+ e_left += ((float)data[2*i])*data[2*i];
+ e_right += ((float)data[2*i+1])*data[2*i+1];
+ data[i] = .5*(((float)data[2*i])+data[2*i+1]);
+ e_tot += ((float)data[i])*data[i];
+ }
+ balance=(e_left+1)/(e_right+1);
+ e_ratio = e_tot/(1+e_left+e_right);
+
+ /*Quantization*/
+ speex_bits_pack(bits, 14, 5);
+ speex_bits_pack(bits, SPEEX_INBAND_STEREO, 4);
+
+ balance=4*log(balance);
+
+ /*Pack sign*/
+ if (balance>0)
+ speex_bits_pack(bits, 0, 1);
+ else
+ speex_bits_pack(bits, 1, 1);
+ balance=floor(.5+fabs(balance));
+ if (balance>30)
+ balance=31;
+
+ speex_bits_pack(bits, (int)balance, 5);
+
+ /*Quantize energy ratio*/
+ tmp=vq_index(&e_ratio, e_ratio_quant, 1, 4);
+ speex_bits_pack(bits, tmp, 2);
+}
+
+void speex_decode_stereo(float *data, int frame_size, SpeexStereoState *stereo)
+{
+ float balance, e_ratio;
int i;
float e_tot=0, e_left, e_right, e_sum;
@@ -103,6 +140,35 @@
}
}
+void speex_decode_stereo_int(short *data, int frame_size, SpeexStereoState *stereo)
+{
+ float balance, e_ratio;
+ int i;
+ float e_tot=0, e_left, e_right, e_sum;
+
+ balance=stereo->balance;
+ e_ratio=stereo->e_ratio;
+ for (i=frame_size-1;i>=0;i--)
+ {
+ e_tot += ((float)data[i])*data[i];
+ }
+ e_sum=e_tot/e_ratio;
+ e_left = e_sum*balance / (1+balance);
+ e_right = e_sum-e_left;
+
+ e_left = sqrt(e_left/(e_tot+.01));
+ e_right = sqrt(e_right/(e_tot+.01));
+
+ for (i=frame_size-1;i>=0;i--)
+ {
+ float ftmp=data[i];
+ stereo->smooth_left = .98*stereo->smooth_left + .02*e_left;
+ stereo->smooth_right = .98*stereo->smooth_right + .02*e_right;
+ data[2*i] = stereo->smooth_left*ftmp;
+ data[2*i+1] = stereo->smooth_right*ftmp;
+ }
+}
+
int speex_std_stereo_request_handler(SpeexBits *bits, void *state, void *data)
{
SpeexStereoState *stereo;
Modified: trunk/speex/libspeex/testenc.c
===================================================================
--- trunk/speex/libspeex/testenc.c 2004-04-20 18:02:23 UTC (rev 6557)
+++ trunk/speex/libspeex/testenc.c 2004-04-20 21:52:01 UTC (rev 6558)
@@ -82,7 +82,7 @@
in_float[i]=in_short[i];
speex_bits_reset(&bits);
- speex_encode(st, in_short, &bits);
+ speex_encode_int(st, in_short, &bits);
nbBits = speex_bits_write(&bits, cbits, 200);
bitCount+=bits.nbBits;
@@ -90,7 +90,7 @@
fwrite(cbits, 1, nbBits, fbits);
speex_bits_rewind(&bits);
- speex_decode(dec, &bits, out_short);
+ speex_decode_int(dec, &bits, out_short);
speex_bits_reset(&bits);
fwrite(&out_short[skip_group_delay], sizeof(short), FRAME_SIZE-skip_group_delay, fout);
Modified: trunk/speex/libspeex/testenc_uwb.c
===================================================================
--- trunk/speex/libspeex/testenc_uwb.c 2004-04-20 18:02:23 UTC (rev 6557)
+++ trunk/speex/libspeex/testenc_uwb.c 2004-04-20 21:52:01 UTC (rev 6558)
@@ -82,7 +82,7 @@
in_float[i]=in_short[i];
speex_bits_reset(&bits);
- speex_encode(st, in_short, &bits);
+ speex_encode_int(st, in_short, &bits);
nbBits = speex_bits_write(&bits, cbits, 200);
bitCount+=bits.nbBits;
@@ -90,7 +90,7 @@
fwrite(cbits, 1, nbBits, fbits);
speex_bits_rewind(&bits);
- speex_decode(dec, &bits, out_short);
+ speex_decode_int(dec, &bits, out_short);
speex_bits_reset(&bits);
fwrite(&out_short[skip_group_delay], sizeof(short), FRAME_SIZE-skip_group_delay, fout);
Modified: trunk/speex/libspeex/testenc_wb.c
===================================================================
--- trunk/speex/libspeex/testenc_wb.c 2004-04-20 18:02:23 UTC (rev 6557)
+++ trunk/speex/libspeex/testenc_wb.c 2004-04-20 21:52:01 UTC (rev 6558)
@@ -87,7 +87,7 @@
in_float[i]=in_short[i];
speex_bits_reset(&bits);
- speex_encode(st, in_short, &bits);
+ speex_encode_int(st, in_short, &bits);
nbBits = speex_bits_write(&bits, cbits, 200);
bitCount+=bits.nbBits;
@@ -95,7 +95,7 @@
fwrite(cbits, 1, nbBits, fbits);
speex_bits_rewind(&bits);
- speex_decode(dec, &bits, out_short);
+ speex_decode_int(dec, &bits, out_short);
speex_bits_reset(&bits);
fwrite(&out_short[skip_group_delay], sizeof(short), FRAME_SIZE-skip_group_delay, fout);
Modified: trunk/speex/libspeex/vbr.c
===================================================================
--- trunk/speex/libspeex/vbr.c 2004-04-20 18:02:23 UTC (rev 6557)
+++ trunk/speex/libspeex/vbr.c 2004-04-20 21:52:01 UTC (rev 6558)
@@ -116,7 +116,7 @@
*/
-float vbr_analysis(VBRState *vbr, short *sig, int len, int pitch, float pitch_coef)
+float vbr_analysis(VBRState *vbr, spx_word16_t *sig, int len, int pitch, float pitch_coef)
{
int i;
float ener=0, ener1=0, ener2=0;
Modified: trunk/speex/libspeex/vbr.h
===================================================================
--- trunk/speex/libspeex/vbr.h 2004-04-20 18:02:23 UTC (rev 6557)
+++ trunk/speex/libspeex/vbr.h 2004-04-20 21:52:01 UTC (rev 6558)
@@ -36,6 +36,8 @@
#ifndef VBR_H
#define VBR_H
+#include "misc.h"
+
#define VBR_MEMORY_SIZE 5
extern float vbr_nb_thresh[9][11];
@@ -59,7 +61,7 @@
void vbr_init(VBRState *vbr);
-float vbr_analysis(VBRState *vbr, short *sig, int len, int pitch, float pitch_coef);
+float vbr_analysis(VBRState *vbr, spx_word16_t *sig, int len, int pitch, float pitch_coef);
void vbr_destroy(VBRState *vbr);
Modified: trunk/speex/src/speexdec.c
===================================================================
--- trunk/speex/src/speexdec.c 2004-04-20 18:02:23 UTC (rev 6557)
+++ trunk/speex/src/speexdec.c 2004-04-20 21:52:01 UTC (rev 6558)
@@ -624,9 +624,9 @@
int ret;
/*Decode frame*/
if (!lost)
- ret = speex_decode(st, &bits, output);
+ ret = speex_decode_int(st, &bits, output);
else
- ret = speex_decode(st, NULL, output);
+ ret = speex_decode_int(st, NULL, output);
/*for (i=0;i<frame_size*channels;i++)
printf ("%d\n", (int)output[i]);*/
@@ -644,7 +644,7 @@
break;
}
if (channels==2)
- speex_decode_stereo(output, frame_size, &stereo);
+ speex_decode_stereo_int(output, frame_size, &stereo);
if (print_bitrate) {
int tmp;
Modified: trunk/speex/src/speexenc.c
===================================================================
--- trunk/speex/src/speexenc.c 2004-04-20 18:02:23 UTC (rev 6557)
+++ trunk/speex/src/speexenc.c 2004-04-20 21:52:01 UTC (rev 6558)
@@ -573,19 +573,6 @@
ogg_stream_packetin(&os, &op);
free(op.packet);
- while((result = ogg_stream_flush(&os, &og)))
- {
- if(!result) break;
- ret = oe_write_page(&og, fout);
- if(ret != og.header_len + og.body_len)
- {
- fprintf (stderr,"Error: failed writing header to output stream\n");
- exit(1);
- }
- else
- bytes_written += ret;
- }
-
op.packet = (unsigned char *)comments;
op.bytes = comments_length;
op.b_o_s = 0;
@@ -674,12 +661,12 @@
id++;
/*Encode current frame*/
if (chan==2)
- speex_encode_stereo(input, frame_size, &bits);
+ speex_encode_stereo_int(input, frame_size, &bits);
if (preprocess)
speex_preprocess(preprocess, input, NULL);
- speex_encode(st, input, &bits);
+ speex_encode_int(st, input, &bits);
if (print_bitrate) {
int tmp;
--- >8 ----
List archives: http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body. No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.
More information about the commits
mailing list