Cleaned up vocoder mode...
[speexdsp.git] / libspeex / modes.c
index 2cc443f..fc9bf73 100644 (file)
 #include "sb_celp.h"
 #include "nb_celp.h"
 
+SpeexMode *speex_mode_list[SPEEX_NB_MODES] = {&speex_nb_mode, &speex_wb_mode};
 
 /* Extern declarations for all codebooks we use here */
 extern float gain_cdbk_nb[];
+extern float gain_cdbk_lbr[];
 extern float hexc_table[];
 extern float exc_5_256_table[];
-/*extern float exc_8_256_table[];*/
 extern float exc_5_64_table[];
+extern float exc_8_128_table[];
+extern float exc_8_32_table[];
+extern float exc_10_32_table[];
+extern float exc_10_16_table[];
+extern float hexc_10_32_table[];
 
 /* Parameters for Long-Term Prediction (LTP)*/
 static ltp_params ltp_params_nb = {
@@ -42,42 +48,170 @@ static ltp_params ltp_params_nb = {
    7
 };
 
-/* Split-VQ innovation parameters */
-split_cb_params split_cb_nb = {
+/* Parameters for Long-Term Prediction (LTP)*/
+static ltp_params ltp_params_vlbr = {
+   gain_cdbk_lbr,
+   5,
+   0
+};
+
+/* Parameters for Long-Term Prediction (LTP)*/
+static ltp_params ltp_params_lbr = {
+   gain_cdbk_lbr,
+   5,
+   7
+};
+
+/* Parameters for Long-Term Prediction (LTP)*/
+static ltp_params ltp_params_med = {
+   gain_cdbk_lbr,
+   5,
+   7
+};
+
+/* Split-VQ innovation parameters for very low bit-rate narrowband */
+static split_cb_params split_cb_nb_vlbr = {
+   10,               /*subvect_size*/
+   4,               /*nb_subvect*/
+   exc_10_16_table, /*shape_cb*/
+   4,               /*shape_bits*/
+};
+
+/* Split-VQ innovation parameters for low bit-rate narrowband */
+static split_cb_params split_cb_nb_lbr = {
+   10,              /*subvect_size*/
+   4,               /*nb_subvect*/
+   exc_10_32_table, /*shape_cb*/
+   5,               /*shape_bits*/
+};
+
+
+/* Split-VQ innovation parameters narrowband */
+static split_cb_params split_cb_nb = {
    5,               /*subvect_size*/
    8,               /*nb_subvect*/
    exc_5_64_table, /*shape_cb*/
    6,               /*shape_bits*/
 };
 
-split_cb_params split_cb_sb = {
+/* Split-VQ innovation parameters narrowband */
+static split_cb_params split_cb_nb_med = {
+   8,               /*subvect_size*/
+   5,               /*nb_subvect*/
+   exc_8_128_table, /*shape_cb*/
+   7,               /*shape_bits*/
+};
+
+/* Split-VQ innovation for low-band wideband */
+static split_cb_params split_cb_sb = {
    5,               /*subvect_size*/
    8,              /*nb_subvect*/
    exc_5_256_table,    /*shape_cb*/
    8,               /*shape_bits*/
 };
 
+/* Split-VQ innovation for high-band wideband */
 static split_cb_params split_cb_high = {
    8,               /*subvect_size*/
    5,               /*nb_subvect*/
    hexc_table,       /*shape_cb*/
-   8,               /*shape_bits*/
+   7,               /*shape_bits*/
 };
 
-/* Default mode for narrowband */
-SpeexNBMode nb_mode = {
-   160,    /*frameSize*/
-   40,     /*subframeSize*/
-   320,    /*windowSize*/
-   10,     /*lpcSize*/
-   640,    /*bufSize*/
-   17,     /*pitchStart*/
-   144,    /*pitchEnd*/
-   0.9,    /*gamma1*/
-   0.6,    /*gamma2*/
-   .005,   /*lag_factor*/
-   1.0001, /*lpc_floor*/
-   0.0,    /*preemph*/
+
+/* Split-VQ innovation for high-band wideband */
+static split_cb_params split_cb_high_lbr = {
+   10,               /*subvect_size*/
+   4,               /*nb_subvect*/
+   hexc_10_32_table,       /*shape_cb*/
+   5,               /*shape_bits*/
+};
+
+
+static SpeexSubmode nb_submode1 = {
+   0,
+   1,
+   1,
+   /* LSP quantization */
+   lsp_quant_lbr,
+   lsp_unquant_lbr,
+   /* No pitch quantization */
+   forced_pitch_quant,
+   forced_pitch_unquant,
+   NULL,
+   /* No innovation quantization (noise only) */
+   noise_codebook_quant,
+   noise_codebook_unquant,
+   NULL,
+   0, 0, -1,
+   43
+};
+
+static SpeexSubmode nb_submode2 = {
+   0,
+   0,
+   0,
+   /*LSP quantization*/
+   lsp_quant_lbr,
+   lsp_unquant_lbr,
+   /*No pitch quantization*/
+   pitch_search_3tap,
+   pitch_unquant_3tap,
+   &ltp_params_vlbr,
+   /*Innovation quantization*/
+   split_cb_search_nogain,
+   split_cb_nogain_unquant,
+   &split_cb_nb_vlbr,
+
+   0.75, 0.6, .6,
+   119
+};
+
+
+static SpeexSubmode nb_submode3 = {
+   -1,
+   0,
+   1,
+   /*LSP quantization*/
+   lsp_quant_lbr,
+   lsp_unquant_lbr,
+   /*Pitch quantization*/
+   pitch_search_3tap,
+   pitch_unquant_3tap,
+   &ltp_params_lbr,
+   /*Innovation quantization*/
+   split_cb_search_nogain,
+   split_cb_nogain_unquant,
+   &split_cb_nb_lbr,
+
+   0.75, 0.6, .5,
+   160
+};
+
+static SpeexSubmode nb_submode4 = {
+   -1,
+   0,
+   1,
+   /*LSP quantization*/
+   lsp_quant_lbr,
+   lsp_unquant_lbr,
+   /*Pitch quantization*/
+   pitch_search_3tap,
+   pitch_unquant_3tap,
+   &ltp_params_med,
+   /*Innovation quantization*/
+   split_cb_search_nogain,
+   split_cb_nogain_unquant,
+   &split_cb_nb_med,
+
+   0.72, 0.65, .3,
+   220
+};
+
+static SpeexSubmode nb_submode5 = {
+   -1,
+   0,
+   3,
    /*LSP quantization*/
    lsp_quant_nb,
    lsp_unquant_nb,
@@ -86,25 +220,18 @@ SpeexNBMode nb_mode = {
    pitch_unquant_3tap,
    &ltp_params_nb,
    /*Innovation quantization*/
-   split_cb_search_nogain2,
+   split_cb_search_nogain,
    split_cb_nogain_unquant,
-   &split_cb_nb
+   &split_cb_nb,
+
+   0.7, 0.65, .2,
+   300
 };
 
-/* Narrowband mode used for split-band wideband CELP*/
-static SpeexNBMode low_sb_mode = {
-   160,    /*frameSize*/
-   40,     /*subframeSize*/
-   320,    /*windowSize*/
-   10,     /*lpcSize*/
-   640,    /*bufSize*/
-   17,     /*pitchStart*/
-   144,    /*pitchEnd*/
-   .9,    /*gamma1*/
-   0.6,    /*gamma2*/
-   .002,   /*lag_factor*/
-   1.00005, /*lpc_floor*/
-   0.0,    /*preemph*/
+static SpeexSubmode nb_submode6 = {
+   -1,
+   0,
+   3,
    /*LSP quantization*/
    lsp_quant_nb,
    lsp_unquant_nb,
@@ -113,39 +240,120 @@ static SpeexNBMode low_sb_mode = {
    pitch_unquant_3tap,
    &ltp_params_nb,
    /*Innovation quantization*/
-   split_cb_search_nogain2,
+   split_cb_search_nogain,
    split_cb_nogain_unquant,
-   &split_cb_sb
+   &split_cb_sb,
+
+   0.68, 0.65, .1,
+   364
 };
 
-SpeexMode low_wb_mode = {
-   &low_sb_mode,
-   &nb_encoder_init,
-   &nb_encoder_destroy,
-   &nb_encode,
-   &nb_decoder_init,
-   &nb_decoder_destroy,
-   &nb_decode,
-   160
+
+/* Default mode for narrowband */
+static SpeexNBMode nb_mode = {
+   160,    /*frameSize*/
+   40,     /*subframeSize*/
+   10,     /*lpcSize*/
+   640,    /*bufSize*/
+   17,     /*pitchStart*/
+   144,    /*pitchEnd*/
+   0.9,    /*gamma1*/
+   0.6,    /*gamma2*/
+   .005,   /*lag_factor*/
+   1.0001, /*lpc_floor*/
+   0.0,    /*preemph*/
+   {NULL, &nb_submode1, &nb_submode2, &nb_submode3, &nb_submode4, &nb_submode5, &nb_submode6, NULL,
+   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
+   5
 };
 
+
 SpeexMode speex_nb_mode = {
    &nb_mode,
+   "narrowband",
+   0,
+   4,
    &nb_encoder_init,
    &nb_encoder_destroy,
    &nb_encode,
    &nb_decoder_init,
    &nb_decoder_destroy,
    &nb_decode,
-   160
+   &nb_encoder_ctl,
+   &nb_decoder_ctl,
+   160,
+   -1,
+   0
+};
+
+static SpeexSubmode wb_submode1 = {
+   0,
+   0,
+   1,
+   /*LSP quantization*/
+   lsp_quant_high,
+   lsp_unquant_high,
+   /*Pitch quantization*/
+   NULL,
+   NULL,
+   NULL,
+   /*No innovation quantization*/
+   NULL,
+   NULL,
+   NULL,
+
+   0, 0, -1,
+   36
+};
+
+
+static SpeexSubmode wb_submode2 = {
+   0,
+   0,
+   1,
+   /*LSP quantization*/
+   lsp_quant_high,
+   lsp_unquant_high,
+   /*Pitch quantization*/
+   NULL,
+   NULL,
+   NULL,
+   /*Innovation quantization*/
+   split_cb_search_nogain,
+   split_cb_nogain_unquant,
+   &split_cb_high_lbr,
+
+   0, 0, -1,
+   112
 };
 
+
+static SpeexSubmode wb_submode3 = {
+   0,
+   0,
+   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,
+
+   0, 0, -1,
+   192
+};
+
+
 /* Split-band wideband CELP mode*/
-static SpeexSBMode sb_wb_mode = {
-   &low_wb_mode,
+SpeexSBMode sb_wb_mode = {
+   &speex_nb_mode,
    160,    /*frameSize*/
    40,     /*subframeSize*/
-   320,    /*windowSize*/
    8,     /*lpcSize*/
    640,    /*bufSize*/
    .9,    /*gamma1*/
@@ -153,56 +361,68 @@ static SpeexSBMode sb_wb_mode = {
    .002,   /*lag_factor*/
    1.0001, /*lpc_floor*/
    0.0,    /*preemph*/
-   /*LSP quantization*/
-   lsp_quant_high,
-   lsp_unquant_high,
-   /*Innovation quantization*/
-   split_cb_search_nogain2,
-   split_cb_nogain_unquant,
-   &split_cb_high
+   {NULL, &wb_submode1, &wb_submode2, &wb_submode3, NULL, NULL, NULL, NULL},
+   3
 };
 
 
 SpeexMode speex_wb_mode = {
    &sb_wb_mode,
+   "full-rate wideband (sub-band CELP)",
+   1,
+   4,
    &sb_encoder_init,
    &sb_encoder_destroy,
    &sb_encode,
    &sb_decoder_init,
    &sb_decoder_destroy,
    &sb_decode,
-   320
+   &sb_encoder_ctl,
+   &sb_decoder_ctl,
+   320,
+   -1,
+   0
 };
 
 
 
-
-void *encoder_init(SpeexMode *mode)
+void *speex_encoder_init(SpeexMode *mode)
 {
    return mode->enc_init(mode);
 }
 
-void *decoder_init(SpeexMode *mode)
+void *speex_decoder_init(SpeexMode *mode)
 {
    return mode->dec_init(mode);
 }
 
-void encoder_destroy(void *state)
+void speex_encoder_destroy(void *state)
 {
    (*((SpeexMode**)state))->enc_destroy(state);
 }
 
-void encode(void *state, float *in, SpeexBits *bits)
+void speex_encode(void *state, float *in, SpeexBits *bits)
 {
    (*((SpeexMode**)state))->enc(state, in, bits);
 }
 
-void decoder_destroy(void *state)
+void speex_decoder_destroy(void *state)
 {
    (*((SpeexMode**)state))->dec_destroy(state);
 }
 
-void decode(void *state, SpeexBits *bits, float *out, int lost)
+void speex_decode(void *state, SpeexBits *bits, float *out, int lost)
 {
    (*((SpeexMode**)state))->dec(state, bits, out, lost);
 }
+
+
+void speex_encoder_ctl(void *state, int request, void *ptr)
+{
+   (*((SpeexMode**)state))->enc_ctl(state, request, ptr);
+}
+
+void speex_decoder_ctl(void *state, int request, void *ptr)
+{
+   (*((SpeexMode**)state))->dec_ctl(state, request, ptr);
+}