1 /* Copyright (C) 2002 Jean-Marc Valin */ 2 /** 3 @file ltp.h 4 @brief Long-Term Prediction functions 5 */ 6 /* 7 Redistribution and use in source and binary forms, with or without 8 modification, are permitted provided that the following conditions 9 are met: 10 11 - Redistributions of source code must retain the above copyright 12 notice, this list of conditions and the following disclaimer. 13 14 - Redistributions in binary form must reproduce the above copyright 15 notice, this list of conditions and the following disclaimer in the 16 documentation and/or other materials provided with the distribution. 17 18 - Neither the name of the Xiph.org Foundation nor the names of its 19 contributors may be used to endorse or promote products derived from 20 this software without specific prior written permission. 21 22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR 26 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 */ 34 35 #include "speex_bits.h" 36 #include "misc.h" 37 38 /** LTP parameters. */ 39 typedef struct { 40 const signed char *gain_cdbk; 41 int gain_bits; 42 int pitch_bits; 43 } ltp_params; 44 45 #ifdef FIXED_POINT 46 #define gain_3tap_to_1tap(g) (ABS(g[1]) + (g[0]>0 ? g[0] : -SHR16(g[0],1)) + (g[2]>0 ? g[2] : -SHR16(g[2],1))) 47 #else 48 #define gain_3tap_to_1tap(g) (ABS(g[1]) + (g[0]>0 ? g[0] : -.5*g[0]) + (g[2]>0 ? g[2] : -.5*g[2])) 49 #endif 50 51 void open_loop_nbest_pitch(spx_sig_t *sw, int start, int end, int len, int *pitch, spx_word16_t *gain, int N, char *stack); 52 53 54 /** Finds the best quantized 3-tap pitch predictor by analysis by synthesis */ 55 int pitch_search_3tap( 56 spx_sig_t target[], /* Target vector */ 57 spx_sig_t *sw, 58 spx_coef_t ak[], /* LPCs for this subframe */ 59 spx_coef_t awk1[], /* Weighted LPCs #1 for this subframe */ 60 spx_coef_t awk2[], /* Weighted LPCs #2 for this subframe */ 61 spx_sig_t exc[], /* Overlapping codebook */ 62 const void *par, 63 int start, /* Smallest pitch value allowed */ 64 int end, /* Largest pitch value allowed */ 65 spx_word16_t pitch_coef, /* Voicing (pitch) coefficient */ 66 int p, /* Number of LPC coeffs */ 67 int nsf, /* Number of samples in subframe */ 68 SpeexBits *bits, 69 char *stack, 70 spx_sig_t *exc2, 71 spx_word16_t *r, 72 int complexity, 73 int cdbk_offset, 74 int plc_tuning 75 ); 76 77 /*Unquantize adaptive codebook and update pitch contribution*/ 78 void pitch_unquant_3tap( 79 spx_sig_t exc[], /* Excitation */ 80 int start, /* Smallest pitch value allowed */ 81 int end, /* Largest pitch value allowed */ 82 spx_word16_t pitch_coef, /* Voicing (pitch) coefficient */ 83 const void *par, 84 int nsf, /* Number of samples in subframe */ 85 int *pitch_val, 86 spx_word16_t *gain_val, 87 SpeexBits *bits, 88 char *stack, 89 int lost, 90 int subframe_offset, 91 spx_word16_t last_pitch_gain, 92 int cdbk_offset 93 ); 94 95 /** Forced pitch delay and gain */ 96 int forced_pitch_quant( 97 spx_sig_t target[], /* Target vector */ 98 spx_sig_t *sw, 99 spx_coef_t ak[], /* LPCs for this subframe */ 100 spx_coef_t awk1[], /* Weighted LPCs #1 for this subframe */ 101 spx_coef_t awk2[], /* Weighted LPCs #2 for this subframe */ 102 spx_sig_t exc[], /* Excitation */ 103 const void *par, 104 int start, /* Smallest pitch value allowed */ 105 int end, /* Largest pitch value allowed */ 106 spx_word16_t pitch_coef, /* Voicing (pitch) coefficient */ 107 int p, /* Number of LPC coeffs */ 108 int nsf, /* Number of samples in subframe */ 109 SpeexBits *bits, 110 char *stack, 111 spx_sig_t *exc2, 112 spx_word16_t *r, 113 int complexity, 114 int cdbk_offset, 115 int plc_tuning 116 ); 117 118 /** Unquantize forced pitch delay and gain */ 119 void forced_pitch_unquant( 120 spx_sig_t exc[], /* Excitation */ 121 int start, /* Smallest pitch value allowed */ 122 int end, /* Largest pitch value allowed */ 123 spx_word16_t pitch_coef, /* Voicing (pitch) coefficient */ 124 const void *par, 125 int nsf, /* Number of samples in subframe */ 126 int *pitch_val, 127 spx_word16_t *gain_val, 128 SpeexBits *bits, 129 char *stack, 130 int lost, 131 int subframe_offset, 132 spx_word16_t last_pitch_gain, 133 int cdbk_offset 134 ); 135