📄 modes.c
字号:
static const SpeexSubmode wb_submode2 = { 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 = { 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 = { 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 = { &speex_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, {NULL, &wb_submode1, &wb_submode2, &wb_submode3, &wb_submode4, NULL, NULL, NULL}, 3, {1, 8, 2, 3, 4, 5, 5, 6, 6, 7, 7}, {1, 1, 1, 1, 1, 1, 2, 2, 3, 3, 4}, vbr_hb_thresh, 5};const SpeexMode speex_wb_mode = { &sb_wb_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,};/* "Ultra-wideband" mode stuff *//* Split-band "ultra-wideband" (32 kbps) CELP mode*/static const SpeexSBMode sb_uwb_mode = { &speex_wb_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, {NULL, &wb_submode1, NULL, NULL, NULL, NULL, NULL, NULL}, 1, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10}, {0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, vbr_uhb_thresh, 2};const SpeexMode speex_uwb_mode = { &sb_uwb_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,};#ifdef EPIC_48Kextern const signed char gain_cdbk_ulbr[];extern const signed char exc_12_32_table[];/* Parameters for Long-Term Prediction (LTP)*/static const ltp_params ltp_params_48k = { gain_cdbk_ulbr, 3, 0};static const split_cb_params split_cb_nb_48k = { 12, /*subvect_size*/ 4, /*nb_subvect*/ exc_12_32_table, /*shape_cb*/ 5, /*shape_bits*/ 0,};/* 4.8 kbps very low bit-rate mode */static const SpeexSubmode nb_48k_submode = { 0, 0, 0, 0, /*LSP quantization*/ lsp_quant_48k, lsp_unquant_48k, /*No pitch quantization*/ pitch_search_3tap, pitch_unquant_3tap, <p_params_48k, /*Innovation quantization*/ split_cb_search_shape_sign, split_cb_shape_sign_unquant, &split_cb_nb_48k,#ifdef FIXED_POINT 22938, 16384, 11796, 18022,#else 0.7, 0.5, .36, .55,#endif 144};/* Special, non-standard 4.8 kbps mode */static const SpeexNBMode nb_48k_mode = { 240, /*frameSize*/ 48, /*subframeSize*/ 10, /*lpcSize*/ 640, /*bufSize*/ 17, /*pitchStart*/ 144, /*pitchEnd*/ 0.9, /*gamma1*/ 0.6, /*gamma2*/ .01, /*lag_factor*/ 1.0003, /*lpc_floor*/ 1, {NULL, NULL, &nb_48k_submode, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL}, 2, {2,2,2,2,2,2,2,2,2,2,2}};/* Default mode for narrowband */const SpeexMode speex_nb_48k_mode = { &nb_48k_mode, nb_mode_query, "narrowband 4.8 kbps", 1000, 4, &nb_encoder_init, &nb_encoder_destroy, &nb_encode, &nb_decoder_init, &nb_decoder_destroy, &nb_decode, &nb_encoder_ctl, &nb_decoder_ctl,};#endifvoid *speex_encoder_init(const SpeexMode *mode){ return mode->enc_init(mode);}void *speex_decoder_init(const SpeexMode *mode){ return mode->dec_init(mode);}void speex_encoder_destroy(void *state){ (*((SpeexMode**)state))->enc_destroy(state);}void speex_decoder_destroy(void *state){ (*((SpeexMode**)state))->dec_destroy(state);}int speex_encode_native(void *state, spx_word16_t *in, SpeexBits *bits){ return (*((SpeexMode**)state))->enc(state, in, bits);}int speex_decode_native(void *state, SpeexBits *bits, spx_word16_t *out){ return (*((SpeexMode**)state))->dec(state, bits, out);}#ifdef FIXED_POINTint speex_encode(void *state, float *in, SpeexBits *bits){ int i; int N; short short_in[MAX_IN_SAMPLES]; speex_encoder_ctl(state, SPEEX_GET_FRAME_SIZE, &N); for (i=0;i<N;i++) { if (in[i]>32767.f) short_in[i] = 32767; else if (in[i]<-32768.f) short_in[i] = -32768; else short_in[i] = (short)floor(.5+in[i]); } return (*((SpeexMode**)state))->enc(state, short_in, bits);}int speex_encode_int(void *state, short *in, SpeexBits *bits){ return (*((SpeexMode**)state))->enc(state, in, bits);}int speex_decode(void *state, SpeexBits *bits, float *out){ int i, ret; int N; float short_out[MAX_IN_SAMPLES]; speex_decoder_ctl(state, SPEEX_GET_FRAME_SIZE, &N); ret = (*((SpeexMode**)state))->dec(state, bits, short_out); for (i=0;i<N;i++) out[i] = short_out[i]; return ret;}int speex_decode_int(void *state, SpeexBits *bits, short *out){ return (*((SpeexMode**)state))->dec(state, bits, out);}#elseint speex_encode(void *state, float *in, SpeexBits *bits){ return (*((SpeexMode**)state))->enc(state, in, bits);}int speex_encode_int(void *state, short *in, SpeexBits *bits){ int i; int N; float float_in[MAX_IN_SAMPLES]; speex_encoder_ctl(state, SPEEX_GET_FRAME_SIZE, &N); for (i=0;i<N;i++) float_in[i] = in[i]; return (*((SpeexMode**)state))->enc(state, float_in, bits);}int speex_decode(void *state, SpeexBits *bits, float *out){ return (*((SpeexMode**)state))->dec(state, bits, out);}int speex_decode_int(void *state, SpeexBits *bits, short *out){ int i; int N; float float_out[MAX_IN_SAMPLES]; int ret; speex_decoder_ctl(state, SPEEX_GET_FRAME_SIZE, &N); ret = (*((SpeexMode**)state))->dec(state, bits, float_out); for (i=0;i<N;i++) { if (float_out[i]>32767.f) out[i] = 32767; else if (float_out[i]<-32768.f) out[i] = -32768; else out[i] = (short)floor(.5+float_out[i]); } return ret;}#endifint speex_encoder_ctl(void *state, int request, void *ptr){ return (*((SpeexMode**)state))->enc_ctl(state, request, ptr);}int speex_decoder_ctl(void *state, int request, void *ptr){ return (*((SpeexMode**)state))->dec_ctl(state, request, ptr);}static int nb_mode_query(const void *mode, int request, void *ptr){ const SpeexNBMode *m = (const SpeexNBMode*)mode; switch (request) { case SPEEX_MODE_FRAME_SIZE: *((int*)ptr)=m->frameSize; break; case SPEEX_SUBMODE_BITS_PER_FRAME: if (*((int*)ptr)==0) *((int*)ptr) = NB_SUBMODE_BITS+1; else if (m->submodes[*((int*)ptr)]==NULL) *((int*)ptr) = -1; else *((int*)ptr) = m->submodes[*((int*)ptr)]->bits_per_frame; break; default: speex_warning_int("Unknown nb_mode_query request: ", request); return -1; } return 0;}static int wb_mode_query(const void *mode, int request, void *ptr){ const SpeexSBMode *m = (const SpeexSBMode*)mode; switch (request) { case SPEEX_MODE_FRAME_SIZE: *((int*)ptr)=2*m->frameSize; break; case SPEEX_SUBMODE_BITS_PER_FRAME: if (*((int*)ptr)==0) *((int*)ptr) = SB_SUBMODE_BITS+1; else if (m->submodes[*((int*)ptr)]==NULL) *((int*)ptr) = -1; else *((int*)ptr) = m->submodes[*((int*)ptr)]->bits_per_frame; break; default: speex_warning_int("Unknown wb_mode_query request: ", request); return -1; } return 0;}int speex_mode_query(const SpeexMode *mode, int request, void *ptr){ return mode->query(mode->mode, request, ptr);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -