[xiph-commits] r11650 - in trunk/speex: include/speex libspeex src

jm at svn.xiph.org jm at svn.xiph.org
Sun Jun 25 05:14:09 PDT 2006


Author: jm
Date: 2006-06-25 05:14:04 -0700 (Sun, 25 Jun 2006)
New Revision: 11650

Modified:
   trunk/speex/include/speex/speex.h
   trunk/speex/libspeex/nb_celp.c
   trunk/speex/libspeex/nb_celp.h
   trunk/speex/src/speexenc.c
Log:
Initial implementation of SPEEX_MAX_VBR_BITRATE. Narrowband-only for now.


Modified: trunk/speex/include/speex/speex.h
===================================================================
--- trunk/speex/include/speex/speex.h	2006-06-25 11:10:32 UTC (rev 11649)
+++ trunk/speex/include/speex/speex.h	2006-06-25 12:14:04 UTC (rev 11650)
@@ -141,6 +141,11 @@
 /** Gets tuning for PLC */
 #define SPEEX_GET_PLC_TUNING 41
 
+/** Sets the max bit-rate allowed in VBR mode */
+#define SPEEX_SET_VBR_MAX_BITRATE 42
+/** Gets the max bit-rate allowed in VBR mode */
+#define SPEEX_GET_VBR_MAX_BITRATE 43
+
 /* Used internally, not to be used in applications */
 /** Used internally*/
 #define SPEEX_GET_PI_GAIN 100

Modified: trunk/speex/libspeex/nb_celp.c
===================================================================
--- trunk/speex/libspeex/nb_celp.c	2006-06-25 11:10:32 UTC (rev 11649)
+++ trunk/speex/libspeex/nb_celp.c	2006-06-25 12:14:04 UTC (rev 11650)
@@ -195,6 +195,7 @@
    vbr_init(st->vbr);
    st->vbr_quality = 8;
    st->vbr_enabled = 0;
+   st->vbr_max = 0;
    st->vad_enabled = 0;
    st->dtx_enabled = 0;
    st->abr_enabled = 0;
@@ -521,7 +522,17 @@
          }
 
          speex_encoder_ctl(state, SPEEX_SET_MODE, &mode);
-
+         if (st->vbr_max>0)
+         {
+            spx_int32_t rate;
+            speex_encoder_ctl(state, SPEEX_GET_BITRATE, &rate);
+            if (rate > st->vbr_max)
+            {
+               rate = st->vbr_max;
+               speex_encoder_ctl(state, SPEEX_SET_BITRATE, &rate);
+            }
+         }
+         
          if (st->abr_enabled)
          {
             int bitrate;
@@ -1833,12 +1844,13 @@
          st->complexity=0;
       break;
    case SPEEX_GET_COMPLEXITY:
-      (*(int*)ptr) = st->complexity;
+      (*(spx_int32_t*)ptr) = st->complexity;
       break;
    case SPEEX_SET_BITRATE:
       {
-         int i=10, rate, target;
-         target = (*(int*)ptr);
+         int i=10;
+         spx_int32_t rate, target;
+         target = (*(spx_int32_t*)ptr);
          while (i>=0)
          {
             speex_encoder_ctl(st, SPEEX_SET_QUALITY, &i);
@@ -1893,6 +1905,14 @@
    case SPEEX_GET_PLC_TUNING:
       (*(int*)ptr)=(st->plc_tuning);
       break;
+   case SPEEX_SET_VBR_MAX_BITRATE:
+      st->vbr_max = (*(spx_int32_t*)ptr);
+      break;
+   case SPEEX_GET_VBR_MAX_BITRATE:
+      (*(spx_int32_t*)ptr) = st->vbr_max;
+      break;
+         
+   /* This is all internal stuff past this point */
    case SPEEX_GET_PI_GAIN:
       {
          int i;

Modified: trunk/speex/libspeex/nb_celp.h
===================================================================
--- trunk/speex/libspeex/nb_celp.h	2006-06-25 11:10:32 UTC (rev 11649)
+++ trunk/speex/libspeex/nb_celp.h	2006-06-25 12:14:04 UTC (rev 11650)
@@ -77,44 +77,45 @@
 
    spx_word16_t  gamma1;         /**< Perceptual filter: A(z/gamma1) */
    spx_word16_t  gamma2;         /**< Perceptual filter: A(z/gamma2) */
-   float  lag_factor;     /**< Lag windowing Gaussian width */
+   float  lag_factor;            /**< Lag windowing Gaussian width */
    spx_word16_t  lpc_floor;      /**< Noise floor multiplier for A[0] in LPC analysis*/
-   char  *stack;          /**< Pseudo-stack allocation for temporary memory */
-   spx_word16_t *winBuf;          /**< Input buffer (original signal) */
+   char  *stack;                 /**< Pseudo-stack allocation for temporary memory */
+   spx_word16_t *winBuf;         /**< Input buffer (original signal) */
    spx_word16_t *excBuf;         /**< Excitation buffer */
    spx_word16_t *exc;            /**< Start of excitation frame */
    spx_word16_t *swBuf;          /**< Weighted signal buffer */
    spx_word16_t *sw;             /**< Start of weighted signal frame */
-   const spx_word16_t *window;         /**< Temporary (Hanning) window */
+   const spx_word16_t *window;   /**< Temporary (Hanning) window */
    spx_word16_t *lagWindow;      /**< Window applied to auto-correlation */
-   spx_lsp_t *old_lsp;        /**< LSPs for previous frame */
-   spx_lsp_t *old_qlsp;       /**< Quantized LSPs for previous frame */
-   spx_mem_t *mem_sp;         /**< Filter memory for signal synthesis */
-   spx_mem_t *mem_sw;         /**< Filter memory for perceptually-weighted signal */
-   spx_mem_t *mem_sw_whole;   /**< Filter memory for perceptually-weighted signal (whole frame)*/
-   spx_mem_t *mem_exc;        /**< Filter memory for excitation (whole frame) */
-   spx_mem_t *mem_exc2;        /**< Filter memory for excitation (whole frame) */
+   spx_lsp_t *old_lsp;           /**< LSPs for previous frame */
+   spx_lsp_t *old_qlsp;          /**< Quantized LSPs for previous frame */
+   spx_mem_t *mem_sp;            /**< Filter memory for signal synthesis */
+   spx_mem_t *mem_sw;            /**< Filter memory for perceptually-weighted signal */
+   spx_mem_t *mem_sw_whole;      /**< Filter memory for perceptually-weighted signal (whole frame)*/
+   spx_mem_t *mem_exc;           /**< Filter memory for excitation (whole frame) */
+   spx_mem_t *mem_exc2;          /**< Filter memory for excitation (whole frame) */
    spx_word32_t *pi_gain;        /**< Gain of LPC filter at theta=pi (fe/2) */
-   spx_sig_t *innov_save;      /** If non-NULL, innovation is copied here */
+   spx_sig_t *innov_save;        /** If non-NULL, innovation is copied here */
          
-   VBRState *vbr;         /**< State of the VBR data */
-   float  vbr_quality;    /**< Quality setting for VBR encoding */
-   float  relative_quality; /**< Relative quality that will be needed by VBR */
-   int    vbr_enabled;    /**< 1 for enabling VBR, 0 otherwise */
-   int    vad_enabled;    /**< 1 for enabling VAD, 0 otherwise */
-   int    dtx_enabled;    /**< 1 for enabling DTX, 0 otherwise */
-   int    dtx_count;      /**< Number of consecutive DTX frames */
-   int    abr_enabled;    /**< ABR setting (in bps), 0 if off */
+   VBRState *vbr;                /**< State of the VBR data */
+   float  vbr_quality;           /**< Quality setting for VBR encoding */
+   float  relative_quality;      /**< Relative quality that will be needed by VBR */
+   int    vbr_enabled;           /**< 1 for enabling VBR, 0 otherwise */
+   spx_int32_t vbr_max;          /**< Max bit-rate allowed in VBR mode */
+   int    vad_enabled;           /**< 1 for enabling VAD, 0 otherwise */
+   int    dtx_enabled;           /**< 1 for enabling DTX, 0 otherwise */
+   int    dtx_count;             /**< Number of consecutive DTX frames */
+   spx_int32_t abr_enabled;      /**< ABR setting (in bps), 0 if off */
    float  abr_drift;
    float  abr_drift2;
    float  abr_count;
-   int    complexity;     /**< Complexity setting (0-10 from least complex to most complex) */
+   int    complexity;            /**< Complexity setting (0-10 from least complex to most complex) */
    int    sampling_rate;
    int    plc_tuning;
    int    encode_submode;
    const SpeexSubmode * const *submodes; /**< Sub-mode data */
-   int    submodeID;      /**< Activated sub-mode */
-   int    submodeSelect;  /**< Mode chosen by the user (may differ from submodeID if VAD is on) */
+   int    submodeID;             /**< Activated sub-mode */
+   int    submodeSelect;         /**< Mode chosen by the user (may differ from submodeID if VAD is on) */
 } EncState;
 
 /**Structure representing the full state of the narrowband decoder*/

Modified: trunk/speex/src/speexenc.c
===================================================================
--- trunk/speex/src/speexenc.c	2006-06-25 11:10:32 UTC (rev 11649)
+++ trunk/speex/src/speexenc.c	2006-06-25 12:14:04 UTC (rev 11650)
@@ -178,6 +178,7 @@
    printf (" --quality n        Encoding quality (0-10), default 8\n"); 
    printf (" --bitrate n        Encoding bit-rate (use bit-rate n or lower)\n"); 
    printf (" --vbr              Enable variable bit-rate (VBR)\n"); 
+   printf (" --vbr-max-bitrate  Set max VBR bit-rate allowed\n"); 
    printf (" --abr rate         Enable average bit-rate (ABR) at rate bps\n"); 
    printf (" --vad              Enable voice activity detection (VAD)\n"); 
    printf (" --dtx              Enable file-based discontinuous transmission (DTX)\n"); 
@@ -218,6 +219,7 @@
    int frame_size;
    int quiet=0;
    int vbr_enabled=0;
+   spx_int32_t vbr_max=0;
    int abr_enabled=0;
    int vad_enabled=0;
    int dtx_enabled=0;
@@ -233,6 +235,7 @@
       {"ultra-wideband", no_argument, NULL, 0},
       {"narrowband", no_argument, NULL, 0},
       {"vbr", no_argument, NULL, 0},
+      {"vbr-max-bitrate", required_argument, NULL, 0},
       {"abr", required_argument, NULL, 0},
       {"vad", no_argument, NULL, 0},
       {"dtx", no_argument, NULL, 0},
@@ -311,6 +314,14 @@
          } else if (strcmp(long_options[option_index].name,"vbr")==0)
          {
             vbr_enabled=1;
+         } else if (strcmp(long_options[option_index].name,"vbr-max-bitrate")==0)
+         {
+            vbr_max=atoi(optarg);
+            if (vbr_max<1)
+            {
+               fprintf (stderr, "Invalid VBR max bit-rate value: %d\n", vbr_max);
+               exit(1);
+            }
          } else if (strcmp(long_options[option_index].name,"abr")==0)
          {
             abr_enabled=atoi(optarg);
@@ -584,7 +595,11 @@
    if (quality >= 0)
    {
       if (vbr_enabled)
+      {
+         if (vbr_max>0)
+            speex_encoder_ctl(st, SPEEX_SET_VBR_MAX_BITRATE, &vbr_max);
          speex_encoder_ctl(st, SPEEX_SET_VBR_QUALITY, &vbr_quality);
+      }
       else
          speex_encoder_ctl(st, SPEEX_SET_QUALITY, &quality);
    }



More information about the commits mailing list