[xiph-commits] r7772 - in branches/rel-1-0-branch/speex: include/speex libspeex src

jm at motherfish-iii.xiph.org jm at motherfish-iii.xiph.org
Thu Sep 16 01:17:54 PDT 2004


Author: jm
Date: 2004-09-16 01:17:54 -0700 (Thu, 16 Sep 2004)
New Revision: 7772

Modified:
   branches/rel-1-0-branch/speex/include/speex/speex.h
   branches/rel-1-0-branch/speex/include/speex/speex_stereo.h
   branches/rel-1-0-branch/speex/libspeex/modes.c
   branches/rel-1-0-branch/speex/libspeex/stereo.c
   branches/rel-1-0-branch/speex/src/speexdec.c
   branches/rel-1-0-branch/speex/src/speexenc.c
Log:
API update for compatibility with latest 1.1.x


Modified: branches/rel-1-0-branch/speex/include/speex/speex.h
===================================================================
--- branches/rel-1-0-branch/speex/include/speex/speex.h	2004-09-16 08:16:01 UTC (rev 7771)
+++ branches/rel-1-0-branch/speex/include/speex/speex.h	2004-09-16 08:17:54 UTC (rev 7772)
@@ -56,7 +56,7 @@
 /** Set quality value */
 #define SPEEX_SET_QUALITY 4
 /** Get current quality setting */
-#define SPEEX_GET_QUALITY 5
+/* #define SPEEX_GET_QUALITY 5 -- Doesn't make much sense, does it? */
 
 /** Set sub-mode to use */
 #define SPEEX_SET_MODE 6
@@ -361,10 +361,10 @@
 extern SpeexMode speex_uwb_mode;
 
 /** List of all modes available */
-extern const SpeexMode * const speex_mode_list[SPEEX_NB_MODES];
+extern SpeexMode *speex_mode_list[SPEEX_NB_MODES];
 
 /** Obtain one of the modes available */
-const SpeexMode * const speex_lib_get_mode (int mode);
+SpeexMode *speex_lib_get_mode (int mode);
 
 #ifdef __cplusplus
 }

Modified: branches/rel-1-0-branch/speex/include/speex/speex_stereo.h
===================================================================
--- branches/rel-1-0-branch/speex/include/speex/speex_stereo.h	2004-09-16 08:16:01 UTC (rev 7771)
+++ branches/rel-1-0-branch/speex/include/speex/speex_stereo.h	2004-09-16 08:17:54 UTC (rev 7772)
@@ -57,9 +57,15 @@
 /** 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);
 
+/** Transforms a stereo frame into a mono frame and stores intensity stereo info in 'bits' (int version) */
+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(float *data, int frame_size, SpeexStereoState *stereo);
 
+/** Transforms a mono frame into a stereo frame using intensity stereo info (int version) */
+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: branches/rel-1-0-branch/speex/libspeex/modes.c
===================================================================
--- branches/rel-1-0-branch/speex/libspeex/modes.c	2004-09-16 08:16:01 UTC (rev 7771)
+++ branches/rel-1-0-branch/speex/libspeex/modes.c	2004-09-16 08:17:54 UTC (rev 7772)
@@ -47,7 +47,7 @@
 
 #define MAX_IN_SAMPLES 640
 
-const SpeexMode * const speex_mode_list[SPEEX_NB_MODES] = {&speex_nb_mode, &speex_wb_mode, &speex_uwb_mode};
+SpeexMode *speex_mode_list[SPEEX_NB_MODES] = {&speex_nb_mode, &speex_wb_mode, &speex_uwb_mode};
 
 /* Extern declarations for all codebooks we use here */
 extern signed char gain_cdbk_nb[];
@@ -578,6 +578,7 @@
 {
    int i;
    int N;
+   /* FIXME: Do some dynamic allocation here */
    float float_in[MAX_IN_SAMPLES];
    speex_encoder_ctl(state, SPEEX_GET_FRAME_SIZE, &N);
    for (i=0;i<N;i++)
@@ -599,6 +600,7 @@
 {
    int i;
    int N;
+   /* FIXME: Do some dynamic allocation here */
    float float_out[MAX_IN_SAMPLES];
    int ret;
    speex_decoder_ctl(state, SPEEX_GET_FRAME_SIZE, &N);
@@ -716,7 +718,7 @@
    return 0;
 }
 
-const SpeexMode * const speex_lib_get_mode (int mode)
+SpeexMode *speex_lib_get_mode (int mode)
 {
   if (mode < 0 || mode > SPEEX_NB_MODES) return NULL;
 

Modified: branches/rel-1-0-branch/speex/libspeex/stereo.c
===================================================================
--- branches/rel-1-0-branch/speex/libspeex/stereo.c	2004-09-16 08:16:01 UTC (rev 7771)
+++ branches/rel-1-0-branch/speex/libspeex/stereo.c	2004-09-16 08:17:54 UTC (rev 7772)
@@ -34,6 +34,8 @@
 #include "vq.h"
 #include <math.h>
 
+#define MAX_IN_SAMPLES 640
+
 /*float e_ratio_quant[4] = {1, 1.26, 1.587, 2};*/
 static float e_ratio_quant[4] = {.25, .315, .397, .5};
 
@@ -74,6 +76,16 @@
    speex_bits_pack(bits, tmp, 2);
 }
 
+void speex_encode_stereo_int(short *data, int frame_size, SpeexBits *bits)
+{
+   int i;
+   /* FIXME: Do some dynamic allocation here */
+   float float_data[2*MAX_IN_SAMPLES];
+   for (i=0;i<2*frame_size;i++)
+      float_data[i] = data[i];
+   speex_encode_stereo(float_data, frame_size, bits);
+}
+
 void speex_decode_stereo(float *data, int frame_size, SpeexStereoState *stereo)
 {
    float balance, e_ratio;
@@ -103,6 +115,24 @@
    }
 }
 
+void speex_decode_stereo_int(short *data, int frame_size, SpeexStereoState *stereo)
+{
+   int i;
+   int N;
+   /* FIXME: Do some dynamic allocation here */
+   float float_data[2*MAX_IN_SAMPLES];
+   speex_decode_stereo(float_data, frame_size, stereo);
+   for (i=0;i<frame_size;i++)
+   {
+      if (float_data[i]>32767.f)
+         data[i] = 32767;
+      else if (float_data[i]<-32768.f)
+         data[i] = -32768;
+      else
+         data[i] = (short)floor(.5+float_data[i]);
+   }
+}
+
 int speex_std_stereo_request_handler(SpeexBits *bits, void *state, void *data)
 {
    SpeexStereoState *stereo;

Modified: branches/rel-1-0-branch/speex/src/speexdec.c
===================================================================
--- branches/rel-1-0-branch/speex/src/speexdec.c	2004-09-16 08:16:01 UTC (rev 7771)
+++ branches/rel-1-0-branch/speex/src/speexdec.c	2004-09-16 08:17:54 UTC (rev 7772)
@@ -29,6 +29,7 @@
    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
+
 #include <stdio.h>
 #if !defined WIN32 && !defined _WIN32
 #include <unistd.h>
@@ -316,7 +317,8 @@
    modeID = header->mode;
    if (forceMode!=-1)
       modeID = forceMode;
-   mode = speex_mode_list[modeID];
+
+   mode = speex_lib_get_mode (modeID);
    
    if (header->speex_version_id > 1)
    {
@@ -400,7 +402,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;
@@ -624,7 +626,7 @@
             {
                /* Ignore extra headers */
             } else {
-               int lost=0;
+               int lost=0;
                packet_no++;
                if (loss_percent>0 && 100*((float)rand())/RAND_MAX<loss_percent)
                   lost=1;
@@ -640,10 +642,13 @@
                   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]);*/
+
                   if (ret==-1)
                      break;
                   if (ret==-2)
@@ -657,7 +662,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;
@@ -666,22 +671,14 @@
                      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)
                   {
                      for (i=0;i<frame_size*channels;i++)
-                        out[i]=(short)le_short((short)floor(.5+output[i]));
+                        out[i]=le_short(output[i]);
 		  } else {
                      for (i=0;i<frame_size*channels;i++)
-                        out[i]=(short)floor(.5+output[i]);
+                        out[i]=output[i];
 		  }
                   {
                      int frame_offset = 0;

Modified: branches/rel-1-0-branch/speex/src/speexenc.c
===================================================================
--- branches/rel-1-0-branch/speex/src/speexenc.c	2004-09-16 08:16:01 UTC (rev 7771)
+++ branches/rel-1-0-branch/speex/src/speexenc.c	2004-09-16 08:17:54 UTC (rev 7772)
@@ -71,7 +71,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;
@@ -205,7 +205,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 quiet=0;
    int vbr_enabled=0;
@@ -214,6 +214,7 @@
    int dtx_enabled=0;
    int nbBytes;
    SpeexMode *mode=NULL;
+   int modeID = -1;
    void *st;
    SpeexBits bits;
    char cbits[MAX_FRAME_BYTES];
@@ -270,8 +271,8 @@
    char first_bytes[12];
    int wave_input=0;
    int tmp;
-   int lookahead = 0;   
-
+   int lookahead = 0;
+   
    comment_init(&comments, &comments_length, vendor_string);
 
    /*Process command-line options*/
@@ -287,13 +288,13 @@
       case 0:
          if (strcmp(long_options[option_index].name,"narrowband")==0)
          {
-            mode=&speex_nb_mode;
+            modeID = SPEEX_MODEID_NB;
          } else if (strcmp(long_options[option_index].name,"wideband")==0)
          {
-            mode=&speex_wb_mode;
+            modeID = SPEEX_MODEID_WB;
          } else if (strcmp(long_options[option_index].name,"ultra-wideband")==0)
          {
-            mode=&speex_uwb_mode;
+            modeID = SPEEX_MODEID_UWB;
          } else if (strcmp(long_options[option_index].name,"vbr")==0)
          {
             vbr_enabled=1;
@@ -380,7 +381,7 @@
 
          break;
       case 'n':
-         mode=&speex_nb_mode;
+         modeID = SPEEX_MODEID_NB;
          break;
       case 'h':
          usage();
@@ -394,10 +395,10 @@
          print_bitrate=1;
          break;
       case 'w':
-         mode=&speex_wb_mode;
+         modeID = SPEEX_MODEID_WB;
          break;
       case 'u':
-         mode=&speex_uwb_mode;
+         modeID = SPEEX_MODEID_UWB;
          break;
       case '?':
          usage();
@@ -450,12 +451,12 @@
       }
    }
 
-   if (!mode && !rate)
+   if (modeID==-1 && !rate)
    {
       /* By default, use narrowband/8 kHz */
-      mode=&speex_nb_mode;
+      modeID = SPEEX_MODEID_NB;
       rate=8000;
-   } else if (mode && rate)
+   } else if (modeID!=-1 && rate)
    {
       if (rate>48000)
       {
@@ -463,19 +464,19 @@
          exit(1);
       } else if (rate>25000)
       {
-         if (mode!=&speex_uwb_mode)
+         if (modeID != SPEEX_MODEID_UWB)
          {
             fprintf (stderr, "Warning: Trying to encode in %s at %d Hz. I'll do it but I suggest you try ultra-wideband instead\n", mode->modeName , rate);
          }
       } else if (rate>12500)
       {
-         if (mode!=&speex_wb_mode)
+         if (modeID != SPEEX_MODEID_WB)
          {
             fprintf (stderr, "Warning: Trying to encode in %s at %d Hz. I'll do it but I suggest you try wideband instead\n", mode->modeName , rate);
          }
       } else if (rate>=6000)
       {
-         if (mode!=&speex_nb_mode)
+         if (modeID != SPEEX_MODEID_NB)
          {
             fprintf (stderr, "Warning: Trying to encode in %s at %d Hz. I'll do it but I suggest you try narrowband instead\n", mode->modeName , rate);
          }
@@ -483,7 +484,7 @@
          fprintf (stderr, "Error: sampling rate too low: %d Hz\n", rate);
          exit(1);
       }
-   } else if (!mode)
+   } else if (modeID==-1)
    {
       if (rate>48000)
       {
@@ -491,24 +492,24 @@
          exit(1);
       } else if (rate>25000)
       {
-         mode=&speex_uwb_mode;
+         modeID = SPEEX_MODEID_UWB;
       } else if (rate>12500)
       {
-         mode=&speex_wb_mode;
+         modeID = SPEEX_MODEID_WB;
       } else if (rate>=6000)
       {
-         mode=&speex_nb_mode;
+         modeID = SPEEX_MODEID_NB;
       } else {
          fprintf (stderr, "Error: Sampling rate too low: %d Hz\n", rate);
          exit(1);
       }
    } else if (!rate)
    {
-      if (mode==&speex_nb_mode)
+      if (modeID == SPEEX_MODEID_NB)
          rate=8000;
-      else if (mode==&speex_wb_mode)
+      else if (modeID == SPEEX_MODEID_WB)
          rate=16000;
-      else if (mode==&speex_uwb_mode)
+      else if (modeID == SPEEX_MODEID_UWB)
          rate=32000;
    }
 
@@ -516,6 +517,8 @@
       if (rate!=8000 && rate!=16000 && rate!=32000)
          fprintf (stderr, "Warning: Speex is only optimized for 8, 16 and 32 kHz. It will still work at %d Hz but your mileage may vary\n", rate); 
 
+   mode = speex_lib_get_mode (modeID);
+
    speex_init_header(&header, rate, 1, mode);
    header.frames_per_packet=nframes;
    header.vbr=vbr_enabled;
@@ -649,8 +652,10 @@
       id++;
       /*Encode current frame*/
       if (chan==2)
-         speex_encode_stereo(input, frame_size, &bits);
-      speex_encode(st, input, &bits);
+         speex_encode_stereo_int(input, frame_size, &bits);
+
+      speex_encode_int(st, input, &bits);
+      
       nb_encoded += frame_size;
       if (print_bitrate) {
          int tmp;
@@ -749,7 +754,6 @@
       else
          bytes_written += ret;
    }
-   
 
    speex_encoder_destroy(st);
    speex_bits_destroy(&bits);



More information about the commits mailing list