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

Jean-Marc Valin jm at xiph.org
Wed Nov 6 22:10:37 PST 2002



jm          02/11/07 01:10:37

  Modified:    libspeex ltp.c speex_callbacks.h stereo.c
               src      speexenc.c wav_io.c
  Log:
  First stereo support in encoder (might be buggy), not in decoder yet.

Revision  Changes    Path
1.65      +9 -0      speex/libspeex/ltp.c

Index: ltp.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/ltp.c,v
retrieving revision 1.64
retrieving revision 1.65
diff -u -r1.64 -r1.65
--- ltp.c	27 Oct 2002 06:01:30 -0000	1.64
+++ ltp.c	7 Nov 2002 06:10:37 -0000	1.65
@@ -238,6 +238,15 @@
          for (j=0;j<9;j++)
             sum+=C[j]*ptr[j+3];
          if (0) {
+            float tot = fabs(ptr[1]);
+            if (ptr[0]>0)
+               tot+=ptr[0];
+            if (ptr[2]>0)
+               tot+=ptr[2];
+            if (tot>1)
+               continue;
+         }
+         if (0) {
             float tot=ptr[0]+ptr[1]+ptr[2];
             if (tot < 1.1)
                sum *= 1+.15*tot;

<p><p>1.6       +3 -0      speex/libspeex/speex_callbacks.h

Index: speex_callbacks.h
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/speex_callbacks.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- speex_callbacks.h	11 Oct 2002 03:39:34 -0000	1.5
+++ speex_callbacks.h	7 Nov 2002 06:10:37 -0000	1.6
@@ -60,9 +60,12 @@
 /*These are 8-bit requests*/
 /** Send a character in-band */
 #define SPEEX_INBAND_CHAR                8
+#define SPEEX_INBAND_STEREO              9
 
+/*These are 16-bit requests*/
 #define SPEEX_INBAND_MAX_BITRATE         10
 
+/*These are 32-bit requests*/
 #define SPEEX_INBAND_ACKNOWLEDGE         12
 
 /** Callback function type */

<p><p>1.2       +51 -4     speex/libspeex/stereo.c

Index: stereo.c
===================================================================
RCS file: /usr/local/cvsroot/speex/libspeex/stereo.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- stereo.c	5 Nov 2002 15:57:19 -0000	1.1
+++ stereo.c	7 Nov 2002 06:10:37 -0000	1.2
@@ -30,25 +30,53 @@
 */
 
 #include "speex_stereo.h"
+#include "speex_callbacks.h"
+#include "vq.h"
+#include <math.h>
 
-void encode_stereo(float *data, int frame_size, SpeexBits *bits)
+/*float e_ratio_quant[4] = {1, 1.26, 1.587, 2};*/
+static float e_ratio_quant[4] = {.25, .315, .397, .5};
+
+#include <stdio.h>
+
+void speex_encode_stereo(float *data, int frame_size, SpeexBits *bits)
 {
-   int i;
+   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] =  data[2*i]+data[2*i+1];
+      data[i] =  .5*(data[2*i]+data[2*i+1]);
       e_tot   += 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 decode_stereo(float *data, int frame_size, SpeexStereoState *stereo)
+void speex_decode_stereo(float *data, int frame_size, SpeexStereoState *stereo)
 {
    float balance, e_ratio;
    int i;
@@ -71,4 +99,23 @@
       data[2*i] = e_left*data[i];
       data[2*i+1] = e_right*data[i];
    }
+}
+
+
+int speex_std_stereo_request_handler(SpeexBits *bits, void *state, void *data)
+{
+   SpeexStereoState *stereo;
+   float sign=1;
+   int tmp;
+
+   stereo = (SpeexStereoState*)data;
+   if (speex_bits_unpack_unsigned(bits, 1))
+      sign=-1;
+   tmp = speex_bits_unpack_unsigned(bits, 5);
+   stereo->balance = sign*exp(.25*tmp);
+
+   tmp = speex_bits_unpack_unsigned(bits, 2);
+   stereo->e_ratio = e_ratio_quant[tmp];
+
+   return 0;
 }

<p><p>1.55      +10 -1     speex/src/speexenc.c

Index: speexenc.c
===================================================================
RCS file: /usr/local/cvsroot/speex/src/speexenc.c,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -r1.54 -r1.55
--- speexenc.c	6 Nov 2002 21:27:31 -0000	1.54
+++ speexenc.c	7 Nov 2002 06:10:37 -0000	1.55
@@ -100,6 +100,7 @@
       }
    }
 
+#if 0
    if(channels==2)
    {
       /* downmix to mono */
@@ -109,9 +110,10 @@
          s[i]=d>>1;
       }
    }
+#endif
 
    /* copy to float input buffer */
-   for (i=0;i<frame_size;i++)
+   for (i=0;i<frame_size*channels;i++)
    {
       input[i]=(short)s[i];
    }
@@ -155,6 +157,7 @@
    printf (" --be               Raw input is big-endian\n"); 
    printf (" --8bit             Raw input is 8-bit unsigned\n"); 
    printf (" --16bit            Raw input is 16-bit signed\n"); 
+   printf (" --stereo           Consider input as stereo\n"); 
    printf ("Default raw PCM input is 16-bit, little-endian, mono\n"); 
    printf ("\n");
    printf ("More information is available from the Speex site: http://www.speex.org\n");
@@ -196,6 +199,7 @@
       {"be", no_argument, NULL, 0},
       {"lin8", no_argument, NULL, 0},
       {"lin16", no_argument, NULL, 0},
+      {"stereo", no_argument, NULL, 0},
       {"version", no_argument, NULL, 0},
       {"comment", required_argument, NULL, 0},
       {"author", required_argument, NULL, 0},
@@ -278,6 +282,9 @@
          } else if (strcmp(long_options[option_index].name,"lin16")==0)
          {
             fmt=16;
+         } else if (strcmp(long_options[option_index].name,"stereo")==0)
+         {
+            chan=2;
          } else if (strcmp(long_options[option_index].name,"comment")==0)
          {
            comment_add(&comments, &comments_length, NULL, optarg); 
@@ -527,6 +534,8 @@
    {
       id++;
       /*Encode current frame*/
+      if (chan==2)
+         speex_encode_stereo(input, frame_size, &bits);
       speex_encode(st, input, &bits);
       
       if (print_bitrate) {

<p><p>1.9       +2 -2      speex/src/wav_io.c

Index: wav_io.c
===================================================================
RCS file: /usr/local/cvsroot/speex/src/wav_io.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- wav_io.c	4 Nov 2002 03:00:52 -0000	1.8
+++ wav_io.c	7 Nov 2002 06:10:37 -0000	1.9
@@ -87,9 +87,9 @@
    stmp = le_short(stmp);
    *channels = stmp;
    
-   if (stmp>1)
+   if (stmp>2)
    {
-      fprintf (stderr, "Only mono supported for now\n");
+      fprintf (stderr, "Only mono and (intensity) stereo supported\n");
       return -1;
    }
 

<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