Cleaned up vocoder mode...
[speexdsp.git] / libspeex / modes.c
index fa0cc38..fc9bf73 100644 (file)
 #include "ltp.h"
 #include "quant_lsp.h"
 #include "cb_search.h"
-#include "mpulse.h"
+#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 exc_gains_table[];
-extern float exc_table[];
-extern float exc_wb_table[];
-extern float exc_gains_wb_table[];
-ltp_params ltp_params_nb = {
+extern float gain_cdbk_lbr[];
+extern float hexc_table[];
+extern float exc_5_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 = {
    gain_cdbk_nb,
    7,
    7
 };
 
-ltp_params ltp_params_wb = {
-   gain_cdbk_nb,
-   7,
-   8
+/* 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_nb = {
+/* Split-VQ innovation parameters narrowband */
+static split_cb_params split_cb_nb_med = {
    8,               /*subvect_size*/
    5,               /*nb_subvect*/
-   exc_table,       /*shape_cb*/
+   exc_8_128_table, /*shape_cb*/
    7,               /*shape_bits*/
-   exc_gains_table, /*gain_cb*/
-   8                /*gain_bits*/
 };
 
-split_cb_params split_cb_wb = {
+/* 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*/
-   10,              /*nb_subvect*/
-   exc_wb_table,    /*shape_cb*/
+   5,               /*nb_subvect*/
+   hexc_table,       /*shape_cb*/
    7,               /*shape_bits*/
-   exc_gains_wb_table, /*gain_cb*/
-   8                /*gain_bits*/
 };
 
-mpulse_params mpulse_nb = {
-   12,     /*nb_pulse*/
-   4,      /*nb_tracks*/
-   2.2,    /*gain_coef*/
-   10
+
+/* 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*/
 };
 
 
-mpulse_params mpulse_sb = {
-   50,     /*nb_pulse*/
-   10,      /*nb_tracks*/
-   2.5,    /*gain_coef*/
-   10
+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,
 
-mpulse_params mpulse_wb = {
-   24,     /*nb_pulse*/
-   4,      /*nb_tracks*/
-   2.2,    /*gain_coef*/
-   26,
+   0.75, 0.6, .6,
+   119
 };
 
 
-SpeexMode 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*/
+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,
+   /*Pitch quantization*/
+   pitch_search_3tap,
+   pitch_unquant_3tap,
+   &ltp_params_nb,
+   /*Innovation quantization*/
+   split_cb_search_nogain,
+   split_cb_nogain_unquant,
+   &split_cb_nb,
+
+   0.7, 0.65, .2,
+   300
+};
+
+static SpeexSubmode nb_submode6 = {
+   -1,
+   0,
+   3,
    /*LSP quantization*/
    lsp_quant_nb,
    lsp_unquant_nb,
@@ -107,15 +240,19 @@ SpeexMode nb_mode = {
    pitch_unquant_3tap,
    &ltp_params_nb,
    /*Innovation quantization*/
-   split_cb_search,
-   split_cb_unquant,
-   &split_cb_nb
+   split_cb_search_nogain,
+   split_cb_nogain_unquant,
+   &split_cb_sb,
+
+   0.68, 0.65, .1,
+   364
 };
 
-SpeexMode mp_nb_mode = {
+
+/* Default mode for narrowband */
+static SpeexNBMode nb_mode = {
    160,    /*frameSize*/
    40,     /*subframeSize*/
-   320,    /*windowSize*/
    10,     /*lpcSize*/
    640,    /*bufSize*/
    17,     /*pitchStart*/
@@ -125,96 +262,167 @@ SpeexMode mp_nb_mode = {
    .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,
+   &nb_encoder_ctl,
+   &nb_decoder_ctl,
+   160,
+   -1,
+   0
+};
+
+static SpeexSubmode wb_submode1 = {
+   0,
+   0,
+   1,
    /*LSP quantization*/
-   lsp_quant_nb,
-   lsp_unquant_nb,
+   lsp_quant_high,
+   lsp_unquant_high,
    /*Pitch quantization*/
-   pitch_search_3tap,
-   pitch_unquant_3tap,
-   &ltp_params_nb,
-   /*Innovation quantization*/
-   mpulse_search,
-   mpulse_unquant,
-   &mpulse_nb
-};
-
-SpeexMode wb_mode = {
-   320,    /*frameSize*/
-   80,     /*subframeSize*/
-   640,    /*windowSize*/
-   16,     /*lpcSize*/
-   1280,   /*bufSize*/
-   35,     /*pitchStart*/
-   290,    /*pitchEnd*/
-   0.9,    /*gamma1*/
-   -1.0,    /*gamma2*/
-   .002,   /*lag_factor*/
-   1.0001, /*lpc_floor*/
-   0.7,    /*preemph*/
+   NULL,
+   NULL,
+   NULL,
+   /*No innovation quantization*/
+   NULL,
+   NULL,
+   NULL,
 
+   0, 0, -1,
+   36
+};
+
+
+static SpeexSubmode wb_submode2 = {
+   0,
+   0,
+   1,
    /*LSP quantization*/
-   lsp_quant_wb,
-   lsp_unquant_wb,
+   lsp_quant_high,
+   lsp_unquant_high,
    /*Pitch quantization*/
-   pitch_search_3tap,
-   pitch_unquant_3tap,
-   &ltp_params_wb,
+   NULL,
+   NULL,
+   NULL,
    /*Innovation quantization*/
-   split_cb_search_wb,
-   split_cb_unquant,
-   &split_cb_wb
-};
-
-SpeexMode mp_wb_mode = {
-   320,    /*frameSize*/
-   80,     /*subframeSize*/
-   640,    /*windowSize*/
-   16,     /*lpcSize*/
-   1280,   /*bufSize*/
-   35,     /*pitchStart*/
-   290,    /*pitchEnd*/
-   0.9,    /*gamma1*/
-   -0.2,    /*gamma2*/
-   .002,   /*lag_factor*/
-   1.0001,/*lpc_floor*/
-   0.55,    /*preemph*/
+   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_wb,
-   lsp_unquant_wb,
+   lsp_quant_high,
+   lsp_unquant_high,
    /*Pitch quantization*/
-   pitch_search_3tap,
-   pitch_unquant_3tap,
-   &ltp_params_wb,
+   NULL,
+   NULL,
+   NULL,
    /*Innovation quantization*/
-   mpulse_search,
-   mpulse_unquant,
-   &mpulse_wb
+   split_cb_search_shape_sign,
+   split_cb_shape_sign_unquant,
+   &split_cb_high,
+
+   0, 0, -1,
+   192
 };
 
 
-SpeexMode mp_sb_mode = {
+/* Split-band wideband CELP mode*/
+SpeexSBMode sb_wb_mode = {
+   &speex_nb_mode,
    160,    /*frameSize*/
    40,     /*subframeSize*/
-   320,    /*windowSize*/
-   10,     /*lpcSize*/
+   8,     /*lpcSize*/
    640,    /*bufSize*/
-   17,     /*pitchStart*/
-   144,    /*pitchEnd*/
-   0.9,    /*gamma1*/
-   0.4,    /*gamma2*/
+   .9,    /*gamma1*/
+   0.6,    /*gamma2*/
    .002,   /*lag_factor*/
    1.0001, /*lpc_floor*/
    0.0,    /*preemph*/
-   /*LSP quantization*/
-   lsp_quant_nb,
-   lsp_unquant_nb,
-   /*Pitch quantization*/
-   pitch_search_3tap,
-   pitch_unquant_3tap,
-   &ltp_params_nb,
-   /*Innovation quantization*/
-   mpulse_search,
-   mpulse_unquant,
-   &mpulse_sb
+   {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,
+   &sb_encoder_ctl,
+   &sb_decoder_ctl,
+   320,
+   -1,
+   0
+};
+
+
+
+void *speex_encoder_init(SpeexMode *mode)
+{
+   return mode->enc_init(mode);
+}
+
+void *speex_decoder_init(SpeexMode *mode)
+{
+   return mode->dec_init(mode);
+}
+
+void speex_encoder_destroy(void *state)
+{
+   (*((SpeexMode**)state))->enc_destroy(state);
+}
+
+void speex_encode(void *state, float *in, SpeexBits *bits)
+{
+   (*((SpeexMode**)state))->enc(state, in, bits);
+}
+
+void speex_decoder_destroy(void *state)
+{
+   (*((SpeexMode**)state))->dec_destroy(state);
+}
+
+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);
+}