Some stereo enhancements
authorjm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Mon, 6 Jan 2003 22:06:45 +0000 (22:06 +0000)
committerjm <jm@0101bb08-14d6-0310-b084-bc0e0c8e3800>
Mon, 6 Jan 2003 22:06:45 +0000 (22:06 +0000)
git-svn-id: http://svn.xiph.org/trunk/speex@4207 0101bb08-14d6-0310-b084-bc0e0c8e3800

libspeex/sb_celp.c
libspeex/speex_stereo.h
libspeex/stereo.c
src/speexdec.c
src/speexenc.c

index 0e12350..caf6847 100644 (file)
@@ -652,7 +652,7 @@ void *sb_decoder_init(SpeexMode *m)
 {
    SBDecState *st;
    SpeexSBMode *mode;
-   st = (SBDecState*)speex_alloc(sizeof(SBDecState)+4000*sizeof(float));
+   st = (SBDecState*)speex_alloc(sizeof(SBDecState)+6000*sizeof(float));
    st->mode = m;
    mode=(SpeexSBMode*)m->mode;
 
index 65d5b94..6007da3 100644 (file)
 
 /** State used for decoding (intensity) stereo information */
 typedef struct SpeexStereoState {
-   float balance;     /**< Left/right balance info */
-   float e_ratio;     /**< Ratio of energies: E(left+right)/[E(left)+E(right)]  */
+   float balance;      /**< Left/right balance info */
+   float e_ratio;      /**< Ratio of energies: E(left+right)/[E(left)+E(right)]  */
+   float smooth_left;  /**< Smoothed left channel gain */
+   float smooth_right; /**< Smoothed right channel gain */
 } SpeexStereoState;
 
 /** Initialization value for a stereo state */
-#define SPEEX_STEREO_STATE_INIT {1,.5}
+#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);
index 09b8873..e033ce5 100644 (file)
@@ -96,8 +96,10 @@ void speex_decode_stereo(float *data, int frame_size, SpeexStereoState *stereo)
    for (i=frame_size-1;i>=0;i--)
    {
       float ftmp=data[i];
-      data[2*i] = e_left*ftmp;
-      data[2*i+1] = e_right*ftmp;
+      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;
    }
 }
 
index cb19cc7..3e766ed 100644 (file)
@@ -297,11 +297,13 @@ static void *process_header(ogg_packet *op, int enh_enabled, int *frame_size, in
    speex_decoder_ctl(st, SPEEX_SET_ENH, &enh_enabled);
    speex_decoder_ctl(st, SPEEX_GET_FRAME_SIZE, frame_size);
 
-   callback.callback_id = SPEEX_INBAND_STEREO;
-   callback.func = speex_std_stereo_request_handler;
-   callback.data = stereo;
-   speex_decoder_ctl(st, SPEEX_SET_HANDLER, &callback);
-   
+   if (!(*channels==1))
+   {
+      callback.callback_id = SPEEX_INBAND_STEREO;
+      callback.func = speex_std_stereo_request_handler;
+      callback.data = stereo;
+      speex_decoder_ctl(st, SPEEX_SET_HANDLER, &callback);
+   }
    if (!*rate)
       *rate = header->rate;
    /* Adjust rate if --force-* options are used */
index f657429..c81b1fa 100644 (file)
@@ -97,7 +97,7 @@ static int read_samples(FILE *fin,int frame_size, int bits, int channels, int ls
    }
    nb_read /= bits/8*channels;
 
-   fprintf (stderr, "%d\n", nb_read);
+   /*fprintf (stderr, "%d\n", nb_read);*/
    if (nb_read==0)
       return 1;