⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modes_noglobals.c

📁 ppciaxclient softphone
💻 C
📖 第 1 页 / 共 2 页
字号:
   /*LSP quantization*/
   lsp_quant_lbr,
   lsp_unquant_lbr,
   /*Pitch quantization*/
   pitch_search_3tap,
   pitch_unquant_3tap,
   ltp_params_med(),
   /*Innovation quantization*/
   split_cb_search_shape_sign,
   split_cb_shape_sign_unquant,
   split_cb_nb_med(),
#ifdef FIXED_POINT
   22938, 20644, 5243, 11469,
#else
   0.7, 0.63, .16, .35,
#endif
   220
   );
}

/* 15 kbps high bit-rate mode */
static const SpeexSubmode * nb_submode5 (void)
{
  return speex_submode_new (
   -1,
   0,
   3,
   0,
   /*LSP quantization*/
   lsp_quant_nb,
   lsp_unquant_nb,
   /*Pitch quantization*/
   pitch_search_3tap,
   pitch_unquant_3tap,
   ltp_params_nb(),
   /*Innovation quantization*/
   split_cb_search_shape_sign,
   split_cb_shape_sign_unquant,
   split_cb_nb(),
#ifdef FIXED_POINT
   22938, 21299, 3932, 8192,
#else
   0.7, 0.65, .12, .25,
#endif
   300
   );
}

/* 18.2 high bit-rate mode */
static const SpeexSubmode * nb_submode6 (void)
{
  return speex_submode_new (
   -1,
   0,
   3,
   0,
   /*LSP quantization*/
   lsp_quant_nb,
   lsp_unquant_nb,
   /*Pitch quantization*/
   pitch_search_3tap,
   pitch_unquant_3tap,
   ltp_params_nb(),
   /*Innovation quantization*/
   split_cb_search_shape_sign,
   split_cb_shape_sign_unquant,
   split_cb_sb(),
#ifdef FIXED_POINT
   22282, 21299, 2294, 3277,
#else
   0.68, 0.65, .07, .1,
#endif
   364
   );
}

/* 24.6 kbps high bit-rate mode */
static const SpeexSubmode * nb_submode7 (void)
{
  return speex_submode_new (
   -1,
   0,
   3,
   1,
   /*LSP quantization*/
   lsp_quant_nb,
   lsp_unquant_nb,
   /*Pitch quantization*/
   pitch_search_3tap,
   pitch_unquant_3tap,
   ltp_params_nb(),
   /*Innovation quantization*/
   split_cb_search_shape_sign,
   split_cb_shape_sign_unquant,
   split_cb_nb(),
#ifdef FIXED_POINT
   21299, 21299, 0, -1,
#else
   0.65, 0.65, .0, -1,
#endif
   492
   );
}


/* Default mode for narrowband */
static const SpeexNBMode * nb_mode (void)
{
  const SpeexSubmode ** submodes;
  int quality_map[11] = {1, 8, 2, 3, 3, 4, 4, 5, 5, 6, 7};
  const SpeexNBMode * ret;

  submodes = (const SpeexSubmode **)
    speex_alloc (sizeof (SpeexSubmode *) * SB_SUBMODES);
  if (submodes == NULL) return NULL;
  memset (submodes, 0, sizeof (submodes));

  if (!(submodes[1] = nb_submode1())) goto nb_1;
  if (!(submodes[2] = nb_submode2())) goto nb_2;
  if (!(submodes[3] = nb_submode3())) goto nb_3;
  if (!(submodes[4] = nb_submode4())) goto nb_4;
  if (!(submodes[5] = nb_submode5())) goto nb_5;
  if (!(submodes[6] = nb_submode6())) goto nb_6;
  if (!(submodes[7] = nb_submode7())) goto nb_7;
  if (!(submodes[8] = nb_submode8())) goto nb_8;

  ret = nb_mode_new (
   160,    /*frameSize*/
   40,     /*subframeSize*/
   10,     /*lpcSize*/
   640,    /*bufSize*/
   17,     /*pitchStart*/
   144,    /*pitchEnd*/
#ifdef FIXED_POINT
   29491, 19661, /* gamma1, gamma2 */
#else
   0.9, 0.6, /* gamma1, gamma2 */
#endif
   .012,   /*lag_factor*/
   1.0002, /*lpc_floor*/
#ifdef EPIC_48K
   0,
#endif
   submodes,
   5,
   quality_map
   );

  if (ret == NULL) goto nb_8;
 
  /* If nb_mode_new() was successful, the references to submodes have been
   * copied into ret->submodes[], and it's safe to free submodes.
   */
  speex_free ((void *)submodes);

  return ret;

  /* Cleanup on memory allocation errors */
 nb_8: speex_submode_free (submodes[8]);
 nb_7: speex_submode_free (submodes[7]);
 nb_6: speex_submode_free (submodes[6]);
 nb_5: speex_submode_free (submodes[5]);
 nb_4: speex_submode_free (submodes[4]);
 nb_3: speex_submode_free (submodes[3]);
 nb_2: speex_submode_free (submodes[2]);
 nb_1: speex_submode_free (submodes[1]);

  speex_free ((void *)submodes);

  return NULL;
}


/* Default mode for narrowband */
static const SpeexMode * speex_nb_mode_new (void)
{
  const SpeexNBMode * _nb_mode;

  _nb_mode = nb_mode();
  if (_nb_mode == NULL) return NULL;

  return mode_new (
   _nb_mode,
   nb_mode_query,
   "narrowband",
   0,
   4,
   &nb_encoder_init,
   &nb_encoder_destroy,
   &nb_encode,
   &nb_decoder_init,
   &nb_decoder_destroy,
   &nb_decode,
   &nb_encoder_ctl,
   &nb_decoder_ctl
   );
}

static void speex_nb_mode_free (const SpeexMode * mode)
{
  nb_mode_free ((SpeexNBMode *)mode->mode);
  speex_free ((void *)mode);
}

/* Wideband part */

static const SpeexSubmode * wb_submode1 (void)
{
  return speex_submode_new (
   0,
   0,
   1,
   0,
   /*LSP quantization*/
   lsp_quant_high,
   lsp_unquant_high,
   /*Pitch quantization*/
   NULL,
   NULL,
   NULL,
   /*No innovation quantization*/
   NULL,
   NULL,
   NULL,
#ifdef FIXED_POINT
   24576, 24576, 0, -1,
#else
   .75, .75, .0, -1,
#endif
   36
   );
}


static const SpeexSubmode * wb_submode2 (void)
{
  return speex_submode_new (
   0,
   0,
   1,
   0,
   /*LSP quantization*/
   lsp_quant_high,
   lsp_unquant_high,
   /*Pitch quantization*/
   NULL,
   NULL,
   NULL,
   /*Innovation quantization*/
   split_cb_search_shape_sign,
   split_cb_shape_sign_unquant,
   split_cb_high_lbr(),
#ifdef FIXED_POINT
   27853, 19661, 8192, -1,
#else
   .85, .6, .25, -1,
#endif
   112
   );
}


static const SpeexSubmode * wb_submode3 (void)
{
  return speex_submode_new (
   0,
   0,
   1,
   0,
   /*LSP quantization*/
   lsp_quant_high,
   lsp_unquant_high,
   /*Pitch quantization*/
   NULL,
   NULL,
   NULL,
   /*Innovation quantization*/
   split_cb_search_shape_sign,
   split_cb_shape_sign_unquant,
   split_cb_high(),

#ifdef FIXED_POINT
   24576, 22938, 1638, -1,
#else
   .75, .7, .05, -1,
#endif
   192
   );
}

static const SpeexSubmode * wb_submode4 (void)
{
  return speex_submode_new (
   0,
   0,
   1,
   1,
   /*LSP quantization*/
   lsp_quant_high,
   lsp_unquant_high,
   /*Pitch quantization*/
   NULL,
   NULL,
   NULL,
   /*Innovation quantization*/
   split_cb_search_shape_sign,
   split_cb_shape_sign_unquant,
   split_cb_high(),
#ifdef FIXED_POINT
   24576, 24576, 0, -1,
#else
   .75, .75, .0, -1,
#endif
   352
   );
}


/* Split-band wideband CELP mode*/
static const SpeexSBMode * sb_wb_mode (void)
{
  const SpeexMode * nb_mode;
  const SpeexSubmode ** submodes;
  int low_quality_map[11] = {1, 8, 2, 3, 4, 5, 5, 6, 6, 7, 7};
  int quality_map[11] = {1, 1, 1, 1, 1, 1, 2, 2, 3, 3, 4};
  SpeexSBMode * ret;

  nb_mode = speex_nb_mode_new ();
  if (nb_mode == NULL) return NULL;

  submodes = (const SpeexSubmode **)
    speex_alloc (sizeof (SpeexSubmode *) * SB_SUBMODES);
  if (submodes == NULL) return NULL;
  memset (submodes, 0, sizeof (submodes));

  if (!(submodes[1] = wb_submode1())) goto sb_1;
  if (!(submodes[2] = wb_submode2())) goto sb_2;
  if (!(submodes[3] = wb_submode3())) goto sb_3;
  if (!(submodes[4] = wb_submode4())) goto sb_4;

  ret = sb_mode_new (
   nb_mode,
   160,    /*frameSize*/
   40,     /*subframeSize*/
   8,     /*lpcSize*/
   640,    /*bufSize*/
#ifdef FIXED_POINT
   29491, 19661, /* gamma1, gamma2 */
#else
   0.9, 0.6, /* gamma1, gamma2 */
#endif
   .001,   /*lag_factor*/
   1.0001, /*lpc_floor*/
   0.9,
   submodes,
   3,
   low_quality_map,
   quality_map,
   vbr_hb_thresh,
   5
   );

  if (ret == NULL) goto sb_4;

  /* If sb_mode_new() was successful, the references to submodes have been
   * copied into ret->submodes[], and it's safe to free submodes.
   */
  speex_free ((void *)submodes);

  return ret;

  /* Cleanup on memory allocation errors */
 sb_4: speex_submode_free (submodes[4]);
 sb_3: speex_submode_free (submodes[3]);
 sb_2: speex_submode_free (submodes[2]);
 sb_1: speex_submode_free (submodes[1]);

  speex_free ((void *)submodes);

  return NULL;
}

static void
sb_wb_mode_free (const SpeexSBMode * mode)
{
  speex_nb_mode_free (mode->nb_mode);
}

static const SpeexMode * speex_wb_mode_new (void)
{
  const SpeexSBMode * sb_mode;

  sb_mode = sb_wb_mode ();
  if (sb_mode == NULL) return NULL;

  return mode_new (
   (const SpeexNBMode *)sb_mode,
   wb_mode_query,
   "wideband (sub-band CELP)",
   1,
   4,
   &sb_encoder_init,
   &sb_encoder_destroy,
   &sb_encode,
   &sb_decoder_init,
   &sb_decoder_destroy,
   &sb_decode,
   &sb_encoder_ctl,
   &sb_decoder_ctl
   );
}

static void speex_wb_mode_free (const SpeexMode * mode)
{
  sb_wb_mode_free (mode->mode);
  speex_free ((void *)mode);
}


/* "Ultra-wideband" mode stuff */



/* Split-band "ultra-wideband" (32 kbps) CELP mode*/
static const SpeexSBMode * sb_uwb_mode (void)
{
  const SpeexSBMode * nb_mode;
  const SpeexSubmode ** submodes;
  int low_quality_map[11] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
  int quality_map[11] = {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};
  SpeexSBMode * ret;

  nb_mode = sb_wb_mode ();
  if (nb_mode == NULL) return NULL;

  submodes = (const SpeexSubmode **)
    speex_alloc (sizeof (SpeexSubmode *) * SB_SUBMODES);
  if (submodes == NULL) return NULL;
  memset (submodes, 0, sizeof (submodes));

  if (!(submodes[1] = wb_submode1())) goto uwb_1;

  ret = sb_mode_new (
   (const SpeexMode *)nb_mode,
   320,    /*frameSize*/
   80,     /*subframeSize*/
   8,     /*lpcSize*/
   1280,    /*bufSize*/
#ifdef FIXED_POINT
   29491, 19661, /* gamma1, gamma2 */
#else
   0.9, 0.6, /* gamma1, gamma2 */
#endif
   .002,   /*lag_factor*/
   1.0001, /*lpc_floor*/
   0.7,
   submodes,
   1,
   low_quality_map,
   quality_map,
   vbr_uhb_thresh,
   2
   );

  if (ret == NULL) goto uwb_1;

  /* If sb_mode_new() was successful, the references to submodes have been
   * copied into ret->submodes[], and it's safe to free submodes.
   */
  speex_free ((void *)submodes);

  return ret;

 uwb_1: speex_submode_free (submodes[1]);

  speex_free ((void *)submodes);

  return NULL;
}

static void sb_uwb_mode_free (const SpeexSBMode * mode)
{
  sb_wb_mode_free ((const SpeexSBMode *)mode->nb_mode);
  sb_mode_free (mode);
}

static const SpeexMode * speex_uwb_mode_new (void)
{
  const SpeexSBMode * sb_mode;

  sb_mode = sb_uwb_mode();
  if (sb_mode == NULL) return NULL;

  return mode_new (
   sb_mode,
   wb_mode_query,
   "ultra-wideband (sub-band CELP)",
   2,
   4,
   &sb_encoder_init,
   &sb_encoder_destroy,
   &sb_encode,
   &sb_decoder_init,
   &sb_decoder_destroy,
   &sb_decode,
   &sb_encoder_ctl,
   &sb_decoder_ctl
   );
}

static void speex_uwb_mode_free (const SpeexMode * mode)
{
  sb_uwb_mode_free (mode->mode);
  speex_free ((void *)mode);
}

const SpeexMode * speex_mode_new (int modeID)
{
  switch (modeID) {
  case 0: return speex_nb_mode_new(); break;
  case 1: return speex_wb_mode_new(); break;
  case 2: return speex_uwb_mode_new(); break;
  default: return NULL;
  }
}

void speex_mode_destroy (const SpeexMode * mode)
{
  switch (mode->modeID) {
  case 0: speex_nb_mode_free(mode); break;
  case 1: speex_wb_mode_free(mode); break;
  case 2:  speex_uwb_mode_free(mode); break;
  default: break;
  }
}

/** XXX: This is just a dummy global mode, as used by nb_celp.c */
const SpeexMode speex_wb_mode = {
   NULL,
   NULL,
   NULL,
   0,
   0,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL
};

int speex_mode_query(const SpeexMode *mode, int request, void *ptr)
{
  if (mode == &speex_wb_mode && request == SPEEX_SUBMODE_BITS_PER_FRAME) {
    int * p = (int*)ptr;

    switch (*p) {
    case 0: *p = SB_SUBMODE_BITS+1; break;
    case 1: *p = 36; break;
    case 2: *p = 112; break;
    case 3: *p = 192; break;
    case 4: *p = 352; break;
    default: *p = -1; break;
    }

    return 0;
  }
  
  return mode->query(mode->mode, request, ptr);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -