[xiph-cvs] cvs commit: speex/src speexdec.c speexenc.c

Jean-Marc Valin jm at xiph.org
Tue Oct 7 22:03:48 PDT 2003



jm          03/10/08 01:03:48

  Modified:    libspeex filters.c jitter.c misc.c modes.c nb_celp.c
                        nb_celp.h preprocess.c sb_celp.c sb_celp.h
                        smallft.c speex.h speex_jitter.h speex_preprocess.h
                        speex_stereo.h stereo.c testdenoise.c testenc.c
                        testenc_uwb.c testenc_wb.c vbr.c vbr.h
               src      speexdec.c speexenc.c
  Log:
  fixed-point: converted user-visible functions to use "short" signals,
  fixed (fixed-point) bug in comb-filter.

Revision  Changes    Path
1.46      +2 -2      speex/libspeex/filters.c

Index: filters.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/filters.c,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- filters.c	8 Oct 2003 05:01:18 -0000	1.45
+++ filters.c	8 Oct 2003 05:03:47 -0000	1.46
@@ -397,7 +397,7 @@
    float fact;
    /*Compute excitation energy prior to enhancement*/
    for (i=0;i<nsf;i++)
-      exc_energy+=exc[i]*exc[i];
+      exc_energy+=((float)exc[i])*exc[i];
 
    /*Some gain adjustment is pitch is too high or if unvoiced*/
    {
@@ -435,7 +435,7 @@
 
    /*Gain after enhancement*/
    for (i=0;i<nsf;i++)
-      new_exc_energy+=new_exc[i]*new_exc[i];
+      new_exc_energy+=((float)new_exc[i])*new_exc[i];
 
    /*Compute scaling factor and normalize energy*/
    gain = sqrt(exc_energy)/sqrt(.1+new_exc_energy);

<p><p>1.4       +1 -1      speex/libspeex/jitter.c

Index: jitter.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/jitter.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- jitter.c	18 Sep 2003 03:58:58 -0000	1.3
+++ jitter.c	8 Oct 2003 05:03:47 -0000	1.4
@@ -122,7 +122,7 @@
    /* Adjust the buffer size depending on network conditions */
 }
 
-void speex_jitter_get(SpeexJitter *jitter, float *out)
+void speex_jitter_get(SpeexJitter *jitter, short *out)
 {
    int i;
    int ret;

<p><p>1.10      +1 -1      speex/libspeex/misc.c

Index: misc.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/misc.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- misc.c	8 Oct 2003 04:40:41 -0000	1.9
+++ misc.c	8 Oct 2003 05:03:47 -0000	1.10
@@ -130,7 +130,7 @@
 {
    int i;
    for (i=0;i<len;i++)
-      data[i]+=3*std*((((float)rand())/RAND_MAX)-.5);
+      data[i]+=SIG_SCALING*3*std*((((float)rand())/RAND_MAX)-.5);
 }
 
 float speex_rand(float std)

<p><p>1.110     +2 -2      speex/libspeex/modes.c

Index: modes.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/modes.c,v
retrieving revision 1.109
retrieving revision 1.110
diff -u -r1.109 -r1.110
--- modes.c	8 Oct 2003 04:35:01 -0000	1.109
+++ modes.c	8 Oct 2003 05:03:47 -0000	1.110
@@ -652,7 +652,7 @@
    (*((SpeexMode**)state))->enc_destroy(state);
 }
 
-int speex_encode(void *state, float *in, SpeexBits *bits)
+int speex_encode(void *state, short *in, SpeexBits *bits)
 {
    return (*((SpeexMode**)state))->enc(state, in, bits);
 }
@@ -662,7 +662,7 @@
    (*((SpeexMode**)state))->dec_destroy(state);
 }
 
-int speex_decode(void *state, SpeexBits *bits, float *out)
+int speex_decode(void *state, SpeexBits *bits, short *out)
 {
    return (*((SpeexMode**)state))->dec(state, bits, out);
 }

<p><p>1.135     +8 -5      speex/libspeex/nb_celp.c

Index: nb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/nb_celp.c,v
retrieving revision 1.134
retrieving revision 1.135
diff -u -r1.134 -r1.135
--- nb_celp.c	8 Oct 2003 05:01:18 -0000	1.134
+++ nb_celp.c	8 Oct 2003 05:03:47 -0000	1.135
@@ -193,7 +193,7 @@
    speex_free(st);
 }
 
-int nb_encode(void *state, float *in, SpeexBits *bits)
+int nb_encode(void *state, short *in, SpeexBits *bits)
 {
    EncState *st;
    int i, sub, roots;
@@ -999,7 +999,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, float *out, char *stack)
+static void nb_decode_lost(DecState *st, short *out, char *stack)
 {
    int i, sub;
    spx_coef_t *awk1, *awk2, *awk3;
@@ -1101,7 +1101,7 @@
    }
 
    for (i=0;i<st->frameSize;i++)
-      out[i]=st->frame[i];
+      out[i]=SHR(st->frame[i],SIG_SHIFT);
    
    st->first = 0;
    st->count_lost++;
@@ -1110,7 +1110,7 @@
       st->pitch_gain_buf_idx = 0;
 }
 
-int nb_decode(void *state, SpeexBits *bits, float *out)
+int nb_decode(void *state, SpeexBits *bits, short *out)
 {
    DecState *st;
    int i, sub;
@@ -1261,7 +1261,7 @@
       iir_mem2(st->exc, lpc, st->frame, st->frameSize, st->lpcSize, st->mem_sp);
 
       for (i=0;i<st->frameSize;i++)
-         out[i]=st->frame[i];
+         out[i]=SHR(st->frame[i],SIG_SHIFT);
       st->count_lost=0;
       return 0;
    }
@@ -1617,6 +1617,9 @@
    for (i=0;i<st->frameSize;i++)
      out[i]=SHR(st->frame[i],SIG_SHIFT);
 
+   /*for (i=0;i<st->frameSize;i++)
+     printf ("%d\n", (int)st->frame[i]);*/
+
    /* Store the LSPs for interpolation in the next frame */
    for (i=0;i<st->lpcSize;i++)
       st->old_qlsp[i] = st->qlsp[i];

<p><p>1.57      +2 -2      speex/libspeex/nb_celp.h

Index: nb_celp.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/nb_celp.h,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -r1.56 -r1.57
--- nb_celp.h	8 Oct 2003 04:40:41 -0000	1.56
+++ nb_celp.h	8 Oct 2003 05:03:47 -0000	1.57
@@ -185,7 +185,7 @@
 void nb_encoder_destroy(void *state);
 
 /** Encodes one frame*/
-int nb_encode(void *state, float *in, SpeexBits *bits);
+int nb_encode(void *state, short *in, SpeexBits *bits);
 
 
 /** Initializes decoder state*/
@@ -195,7 +195,7 @@
 void nb_decoder_destroy(void *state);
 
 /** Decodes one frame*/
-int nb_decode(void *state, SpeexBits *bits, float *out);
+int nb_decode(void *state, SpeexBits *bits, short *out);
 
 /** ioctl-like function for controlling a narrowband encoder */
 int nb_encoder_ctl(void *state, int request, void *ptr);

<p><p>1.17      +3 -3      speex/libspeex/preprocess.c

Index: preprocess.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/preprocess.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- preprocess.c	8 Oct 2003 04:42:59 -0000	1.16
+++ preprocess.c	8 Oct 2003 05:03:47 -0000	1.17
@@ -536,7 +536,7 @@
    
 }
 
-static void preprocess_analysis(SpeexPreprocessState *st, float *x)
+static void preprocess_analysis(SpeexPreprocessState *st, short *x)
 {
    int i;
    int N = st->ps_size;
@@ -607,7 +607,7 @@
 
 }
 
-int speex_preprocess(SpeexPreprocessState *st, float *x, float *echo)
+int speex_preprocess(SpeexPreprocessState *st, short *x, float *echo)
 {
    int i;
    int is_speech=1;
@@ -917,7 +917,7 @@
    return is_speech;
 }
 
-void speex_preprocess_estimate_update(SpeexPreprocessState *st, float *x, float *noise)
+void speex_preprocess_estimate_update(SpeexPreprocessState *st, short *x, float *noise)
 {
    int i;
    int N = st->ps_size;

<p><p>1.137     +12 -7     speex/libspeex/sb_celp.c

Index: sb_celp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/sb_celp.c,v
retrieving revision 1.136
retrieving revision 1.137
diff -u -r1.136 -r1.137
--- sb_celp.c	8 Oct 2003 05:01:18 -0000	1.136
+++ sb_celp.c	8 Oct 2003 05:03:47 -0000	1.137
@@ -233,7 +233,7 @@
 }
 
 
-int sb_encode(void *state, float *in, SpeexBits *bits)
+int sb_encode(void *state, short *in, SpeexBits *bits)
 {
    SBEncState *st;
    int i, roots, sub;
@@ -250,10 +250,15 @@
    mode = (SpeexSBMode*)(st->mode->mode);
 
    {
-      float *low = PUSH(stack, st->frame_size, float);
+      float *sig_in;
+      short *low = PUSH(stack, st->frame_size, short);
+
+      sig_in = PUSH(stack, st->full_frame_size, float);
+      for (i=0;i<st->full_frame_size;i++)
+         sig_in[i] = in[i];
 
       /* 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);
+      qmf_decomp(sig_in, h0, st->x0d, st->x1d, st->full_frame_size, QMF_ORDER, st->h0_mem, stack);
       
       for (i=0;i<st->frame_size;i++)
          low[i] = st->x0d[i];
@@ -741,7 +746,7 @@
    speex_free(state);
 }
 
-static void sb_decode_lost(SBDecState *st, float *out, int dtx, char *stack)
+static void sb_decode_lost(SBDecState *st, short *out, int dtx, char *stack)
 {
    int i;
    spx_coef_t *awk1, *awk2, *awk3;
@@ -829,7 +834,7 @@
    return;
 }
 
-int sb_decode(void *state, SpeexBits *bits, float *out)
+int sb_decode(void *state, SpeexBits *bits, short *out)
 {
    int i, sub;
    SBDecState *st;
@@ -847,8 +852,8 @@
    mode = (SpeexSBMode*)(st->mode->mode);
 
    {
-      float *low;
-      low = PUSH(stack, st->frame_size, float);
+      short *low;
+      low = PUSH(stack, st->frame_size, short);
       
       /* Decode the low-band */
       ret = speex_decode(st->st_low, bits, low);

<p><p>1.45      +2 -2      speex/libspeex/sb_celp.h

Index: sb_celp.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/sb_celp.h,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- sb_celp.h	8 Oct 2003 04:40:41 -0000	1.44
+++ sb_celp.h	8 Oct 2003 05:03:47 -0000	1.45
@@ -149,7 +149,7 @@
 void sb_encoder_destroy(void *state);
 
 /**Encodes one frame*/
-int sb_encode(void *state, float *in, SpeexBits *bits);
+int sb_encode(void *state, short *in, SpeexBits *bits);
 
 
 /**Initializes decoder state*/
@@ -159,7 +159,7 @@
 void sb_decoder_destroy(void *state);
 
 /**Decodes one frame*/
-int sb_decode(void *state, SpeexBits *bits, float *out);
+int sb_decode(void *state, SpeexBits *bits, short *out);
 
 int sb_encoder_ctl(void *state, int request, void *ptr);
 

<p><p>1.15      +0 -0      speex/libspeex/smallft.c

Index: smallft.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/smallft.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- smallft.c	8 Oct 2003 05:01:18 -0000	1.14
+++ smallft.c	8 Oct 2003 05:03:47 -0000	1.15
@@ -11,7 +11,7 @@
  ********************************************************************
 
  function: *unnormalized* fft transform
- last mod: $Id: smallft.c,v 1.14 2003/10/08 05:01:18 jm Exp $
+ last mod: $Id: smallft.c,v 1.15 2003/10/08 05:03:47 jm Exp $
 
  ********************************************************************/
 

<p><p>1.78      +4 -4      speex/libspeex/speex.h

Index: speex.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/speex.h,v
retrieving revision 1.77
retrieving revision 1.78
diff -u -r1.77 -r1.78
--- speex.h	19 Aug 2003 06:07:44 -0000	1.77
+++ speex.h	8 Oct 2003 05:03:47 -0000	1.78
@@ -173,7 +173,7 @@
 typedef void (*encoder_destroy_func)(void *st);
 
 /** Main encoding function */
-typedef int (*encode_func)(void *state, float *in, SpeexBits *bits);
+typedef int (*encode_func)(void *state, short *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, float *out);
+typedef int  (*decode_func)(void *state, SpeexBits *bits, short *out);
 
 /** Function for controlling the decoder options */
 typedef int (*decoder_ctl_func)(void *state, int request, void *ptr);
@@ -259,7 +259,7 @@
  @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, float *in, SpeexBits *bits);
+int speex_encode(void *state, short *in, SpeexBits *bits);
 
 /** Used like the ioctl function to control the encoder parameters
  *
@@ -295,7 +295,7 @@
  * @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, float *out);
+int speex_decode(void *state, SpeexBits *bits, short *out);
 
 /** Used like the ioctl function to control the encoder parameters
  *

<p><p>1.2       +1 -1      speex/libspeex/speex_jitter.h

Index: speex_jitter.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/speex_jitter.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- speex_jitter.h	4 Aug 2003 17:17:23 -0000	1.1
+++ speex_jitter.h	8 Oct 2003 05:03:47 -0000	1.2
@@ -68,7 +68,7 @@
 
 void speex_jitter_put(SpeexJitter *jitter, char *packet, int len, int time);
 
-void speex_jitter_get(SpeexJitter *jitter, float *out);
+void speex_jitter_get(SpeexJitter *jitter, short *out);
 
 
 #endif

<p><p>1.10      +2 -2      speex/libspeex/speex_preprocess.h

Index: speex_preprocess.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/speex_preprocess.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- speex_preprocess.h	18 Sep 2003 03:34:38 -0000	1.9
+++ speex_preprocess.h	8 Oct 2003 05:03:47 -0000	1.10
@@ -101,10 +101,10 @@
 void speex_preprocess_state_destroy(SpeexPreprocessState *st);
 
 /** Preprocess a frame */
-int speex_preprocess(SpeexPreprocessState *st, float *x, float *noise);
+int speex_preprocess(SpeexPreprocessState *st, short *x, float *noise);
 
 /** Preprocess a frame */
-void speex_preprocess_estimate_update(SpeexPreprocessState *st, float *x, float *noise);
+void speex_preprocess_estimate_update(SpeexPreprocessState *st, short *x, float *noise);
 
 /** Used like the ioctl function to control the preprocessor parameters */
 int speex_preprocess_ctl(SpeexPreprocessState *st, int request, void *ptr);

<p><p>1.7       +2 -2      speex/libspeex/speex_stereo.h

Index: speex_stereo.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/speex_stereo.h,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- speex_stereo.h	3 Mar 2003 06:52:41 -0000	1.6
+++ speex_stereo.h	8 Oct 2003 05:03:47 -0000	1.7
@@ -51,10 +51,10 @@
 #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(float *data, int frame_size, SpeexBits *bits);
+void speex_encode_stereo(short *data, int frame_size, SpeexBits *bits);
 
 /** Transforms a mono frame into a stereo frame using intensity stereo info */
-void speex_decode_stereo(float *data, int frame_size, SpeexStereoState *stereo);
+void speex_decode_stereo(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);

<p><p>1.7       +7 -7      speex/libspeex/stereo.c

Index: stereo.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/stereo.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- stereo.c	8 Oct 2003 04:35:01 -0000	1.6
+++ stereo.c	8 Oct 2003 05:03:47 -0000	1.7
@@ -37,17 +37,17 @@
 /*float e_ratio_quant[4] = {1, 1.26, 1.587, 2};*/
 static float e_ratio_quant[4] = {.25f, .315f, .397f, .5f};
 
-void speex_encode_stereo(float *data, int frame_size, SpeexBits *bits)
+void speex_encode_stereo(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  += data[2*i]*data[2*i];
-      e_right += data[2*i+1]*data[2*i+1];
-      data[i] =  .5*(data[2*i]+data[2*i+1]);
-      e_tot   += data[i]*data[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);
@@ -74,7 +74,7 @@
    speex_bits_pack(bits, tmp, 2);
 }
 
-void speex_decode_stereo(float *data, int frame_size, SpeexStereoState *stereo)
+void speex_decode_stereo(short *data, int frame_size, SpeexStereoState *stereo)
 {
    float balance, e_ratio;
    int i;
@@ -84,7 +84,7 @@
    e_ratio=stereo->e_ratio;
    for (i=frame_size-1;i>=0;i--)
    {
-      e_tot += data[i]*data[i];
+      e_tot += ((float)data[i])*data[i];
    }
    e_sum=e_tot/e_ratio;
    e_left  = e_sum*balance / (1+balance);

<p><p>1.11      +2 -8      speex/libspeex/testdenoise.c

Index: testdenoise.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/testdenoise.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- testdenoise.c	18 Sep 2003 03:34:38 -0000	1.10
+++ testdenoise.c	8 Oct 2003 05:03:47 -0000	1.11
@@ -6,8 +6,6 @@
 int main()
 {
    short in[NN];
-   short out[NN];
-   float x[NN];
    int i;
    SpeexPreprocessState *st;
    int count=0;
@@ -26,13 +24,9 @@
       fread(in, sizeof(short), NN, stdin);
       if (feof(stdin))
          break;
-      for (i=0;i<NN;i++)
-         x[i]=in[i];
-      vad = speex_preprocess(st, x, NULL);
-      for (i=0;i<NN;i++)
-         out[i]=x[i];
+      vad = speex_preprocess(st, in, NULL);
       /*fprintf (stderr, "%d\n", vad);*/
-      fwrite(out, sizeof(short), NN, stdout);
+      fwrite(in, sizeof(short), NN, stdout);
       count++;
    }
    speex_preprocess_state_destroy(st);

<p><p>1.49      +2 -13     speex/libspeex/testenc.c

Index: testenc.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/testenc.c,v
retrieving revision 1.48
retrieving revision 1.49
diff -u -r1.48 -r1.49
--- testenc.c	8 Oct 2003 04:38:54 -0000	1.48
+++ testenc.c	8 Oct 2003 05:03:47 -0000	1.49
@@ -12,7 +12,6 @@
    short in_short[FRAME_SIZE];
    short out_short[FRAME_SIZE];
    float in_float[FRAME_SIZE];
-   float out_float[FRAME_SIZE];
    float sigpow,errpow,snr, seg_snr=0;
    int snr_frames = 0;
    char cbits[200];
@@ -79,7 +78,7 @@
          in_float[i]=in_short[i];
       speex_bits_reset(&bits);
 
-      speex_encode(st, in_float, &bits);
+      speex_encode(st, in_short, &bits);
       nbBits = speex_bits_write(&bits, cbits, 200);
       bitCount+=bits.nbBits;
 
@@ -87,19 +86,9 @@
          fwrite(cbits, 1, nbBits, fbits);
       speex_bits_rewind(&bits);
 
-      speex_decode(dec, &bits, out_float);
+      speex_decode(dec, &bits, out_short);
       speex_bits_reset(&bits);
 
-      /* Save the bits here */
-      for (i=0;i<FRAME_SIZE;i++)
-      {
-         if (out_float[i]>32767)
-            out_short[i]=32767;
-         else if (out_float[i]<-32768)
-            out_short[i]=-32768;
-         else
-             out_short[i]=(short)(out_float[i]+.5);
-      }
       fwrite(&out_short[skip_group_delay], sizeof(short), FRAME_SIZE-skip_group_delay, fout);
       skip_group_delay = 0;
    }

<p><p>1.3       +2 -14     speex/libspeex/testenc_uwb.c

Index: testenc_uwb.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/testenc_uwb.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- testenc_uwb.c	4 Nov 2002 03:00:51 -0000	1.2
+++ testenc_uwb.c	8 Oct 2003 05:03:47 -0000	1.3
@@ -60,7 +60,7 @@
       for (i=0;i<FRAME_SIZE;i++)
          bak[i]=input[i]=in[i];
       speex_bits_reset(&bits);
-      speex_encode(st, input, &bits);
+      speex_encode(st, in, &bits);
       nbBits = speex_bits_write(&bits, cbits, 200);
       bitCount+=bits.nbBits;
       printf ("Encoding frame in %d bits\n", nbBits*8);
@@ -78,21 +78,9 @@
       }
       speex_bits_rewind(&bits);
       
-      speex_decode(dec, &bits, input);
+      speex_decode(dec, &bits, in);
 
-      /* Save the bits here */
-      for (i=0;i<FRAME_SIZE;i++)
-      {
-         if (input[i]>32000)
-            input[i]=32000;
-         else if (input[i]<-32000)
-            input[i]=-32000;
-      }
       speex_bits_reset(&bits);
-      for (i=0;i<FRAME_SIZE;i++)
-         in[i]=(short)input[i];
-      for (i=0;i<FRAME_SIZE;i++)
-         bak2[i]=bak[i];
       fwrite(in, sizeof(short), FRAME_SIZE, fout);
    }
    

<p><p>1.33      +2 -14     speex/libspeex/testenc_wb.c

Index: testenc_wb.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/testenc_wb.c,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- testenc_wb.c	8 Oct 2003 04:32:24 -0000	1.32
+++ testenc_wb.c	8 Oct 2003 05:03:47 -0000	1.33
@@ -60,7 +60,7 @@
       for (i=0;i<FRAME_SIZE;i++)
          bak[i]=input[i]=in[i];
       speex_bits_reset(&bits);
-      speex_encode(st, input, &bits);
+      speex_encode(st, in, &bits);
       nbBits = speex_bits_write(&bits, cbits, 200);
       bitCount+=bits.nbBits;
       /*printf ("Encoding frame in %d bits\n", nbBits*8);*/
@@ -78,21 +78,9 @@
       }
       speex_bits_rewind(&bits);
       
-      speex_decode(dec, &bits, input);
+      speex_decode(dec, &bits, in);
 
-      /* Save the bits here */
-      for (i=0;i<FRAME_SIZE;i++)
-      {
-         if (input[i]>32000)
-            input[i]=32000;
-         else if (input[i]<-32000)
-            input[i]=-32000;
-      }
       speex_bits_reset(&bits);
-      for (i=0;i<FRAME_SIZE;i++)
-         in[i]=(short)input[i];
-      for (i=0;i<FRAME_SIZE;i++)
-         bak2[i]=bak[i];
       fwrite(in, sizeof(short), FRAME_SIZE, fout);
    }
    

<p><p>1.22      +3 -3      speex/libspeex/vbr.c

Index: vbr.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/vbr.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -r1.21 -r1.22
--- vbr.c	17 Jan 2003 05:15:08 -0000	1.21
+++ vbr.c	8 Oct 2003 05:03:47 -0000	1.22
@@ -116,7 +116,7 @@
 
 */
 
-float vbr_analysis(VBRState *vbr, float *sig, int len, int pitch, float pitch_coef)
+float vbr_analysis(VBRState *vbr, short *sig, int len, int pitch, float pitch_coef)
 {
    int i;
    float ener=0, ener1=0, ener2=0;
@@ -128,10 +128,10 @@
    float pow_ener;
 
    for (i=0;i<len>>1;i++)
-      ener1 += sig[i]*sig[i];
+      ener1 += ((float)sig[i])*sig[i];
 
    for (i=len>>1;i<len;i++)
-      ener2 += sig[i]*sig[i];
+      ener2 += ((float)sig[i])*sig[i];
    ener=ener1+ener2;
 
    log_energy = log(ener+MIN_ENERGY);

<p><p>1.11      +1 -1      speex/libspeex/vbr.h

Index: vbr.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/vbr.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- vbr.h	17 Jan 2003 05:15:08 -0000	1.10
+++ vbr.h	8 Oct 2003 05:03:47 -0000	1.11
@@ -59,7 +59,7 @@
 
 void vbr_init(VBRState *vbr);
 
-float vbr_analysis(VBRState *vbr, float *sig, int len, int pitch, float pitch_coef);
+float vbr_analysis(VBRState *vbr, short *sig, int len, int pitch, float pitch_coef);
 
 void vbr_destroy(VBRState *vbr);
 

<p><p>1.83      +4 -9      speex/src/speexdec.c

Index: speexdec.c
===================================================================
RCS file: /usr/local/cvsroot/speex/src/speexdec.c,v
retrieving revision 1.82
retrieving revision 1.83
diff -u -r1.82 -r1.83
--- speexdec.c	8 Oct 2003 04:35:02 -0000	1.82
+++ speexdec.c	8 Oct 2003 05:03:48 -0000	1.83
@@ -397,7 +397,7 @@
    char *inFile, *outFile;
    FILE *fin, *fout=NULL;
    short out[MAX_FRAME_SIZE];
-   float output[MAX_FRAME_SIZE];
+   short output[MAX_FRAME_SIZE];
    int frame_size=0;
    void *st=NULL;
    SpeexBits bits;
@@ -620,6 +620,9 @@
                   else
                      ret = speex_decode(st, NULL, output);
 
+                  /*for (i=0;i<frame_size*channels;i++)
+                    printf ("%d\n", (int)output[i]);*/
+
                   if (ret==-1)
                      break;
                   if (ret==-2)
@@ -642,14 +645,6 @@
                      fputc (ch, stderr);
                      fprintf (stderr, "Bitrate is use: %d bps     ", tmp);
                   }
-                  /*PCM saturation (just in case)*/
-                  for (i=0;i<frame_size*channels;i++)
-                  {
-                     if (output[i]>32000.0)
-                        output[i]=32000.0;
-                     else if (output[i]<-32000.0)
-                        output[i]=-32000.0;
-                  }
                   /*Convert to short and save to output file*/
                   if (strlen(outFile)!=0)
                   {

<p><p>1.82      +4 -3      speex/src/speexenc.c

Index: speexenc.c
===================================================================
RCS file: /usr/local/cvsroot/speex/src/speexenc.c,v
retrieving revision 1.81
retrieving revision 1.82
diff -u -r1.81 -r1.82
--- speexenc.c	19 Sep 2003 02:31:59 -0000	1.81
+++ speexenc.c	8 Oct 2003 05:03:48 -0000	1.82
@@ -72,7 +72,7 @@
 #define MAX_FRAME_BYTES 2000
 
 /* Convert input audio bits, endians and channels */
-static int read_samples(FILE *fin,int frame_size, int bits, int channels, int lsb, float * input, char *buff, int *size)
+static int read_samples(FILE *fin,int frame_size, int bits, int channels, int lsb, short * input, char *buff, int *size)
 {   
    unsigned char in[MAX_FRAME_BYTES*2];
    int i;
@@ -122,6 +122,7 @@
       }
    }
 
+   /* FIXME: This is probably redundent now */
    /* copy to float input buffer */
    for (i=0;i<frame_size*channels;i++)
    {
@@ -206,7 +207,7 @@
    int option_index = 0;
    char *inFile, *outFile;
    FILE *fin, *fout;
-   float input[MAX_FRAME_SIZE];
+   short input[MAX_FRAME_SIZE];
    int frame_size;
    int vbr_enabled=0;
    int abr_enabled=0;
@@ -659,7 +660,7 @@
       /*Encode current frame*/
       if (chan==2)
          speex_encode_stereo(input, frame_size, &bits);
-      
+
       if (preprocess)
          speex_preprocess(preprocess, input, NULL);
 

<p><p>--- >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