| 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 |
#ifndef LTP_H |
| 36 |
#define LTP_H |
| 37 |
|
| 38 |
#include "speex/speex_bits.h" |
| 39 |
#include "arch.h" |
| 40 |
|
| 41 |
/** LTP parameters. */ |
| 42 |
typedef struct { |
| 43 |
const signed char *gain_cdbk; |
| 44 |
int gain_bits; |
| 45 |
int pitch_bits; |
| 46 |
} ltp_params; |
| 47 |
|
| 48 |
#ifdef FIXED_POINT |
| 49 |
#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))) |
| 50 |
#else |
| 51 |
#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])) |
| 52 |
#endif |
| 53 |
|
| 54 |
spx_word32_t inner_prod(const spx_word16_t *x, const spx_word16_t *y, int len); |
| 55 |
|
| 56 |
void open_loop_nbest_pitch(spx_word16_t *sw, int start, int end, int len, int *pitch, spx_word16_t *gain, int N, char *stack); |
| 57 |
|
| 58 |
|
| 59 |
/** Finds the best quantized 3-tap pitch predictor by analysis by synthesis */ |
| 60 |
int pitch_search_3tap( |
| 61 |
spx_word16_t target[], /* Target vector */ |
| 62 |
spx_word16_t *sw, |
| 63 |
spx_coef_t ak[], /* LPCs for this subframe */ |
| 64 |
spx_coef_t awk1[], /* Weighted LPCs #1 for this subframe */ |
| 65 |
spx_coef_t awk2[], /* Weighted LPCs #2 for this subframe */ |
| 66 |
spx_sig_t exc[], /* Overlapping codebook */ |
| 67 |
const void *par, |
| 68 |
int start, /* Smallest pitch value allowed */ |
| 69 |
int end, /* Largest pitch value allowed */ |
| 70 |
spx_word16_t pitch_coef, /* Voicing (pitch) coefficient */ |
| 71 |
int p, /* Number of LPC coeffs */ |
| 72 |
int nsf, /* Number of samples in subframe */ |
| 73 |
SpeexBits *bits, |
| 74 |
char *stack, |
| 75 |
spx_word16_t *exc2, |
| 76 |
spx_word16_t *r, |
| 77 |
int complexity, |
| 78 |
int cdbk_offset, |
| 79 |
int plc_tuning, |
| 80 |
spx_word32_t *cumul_gain |
| 81 |
); |
| 82 |
|
| 83 |
/*Unquantize adaptive codebook and update pitch contribution*/ |
| 84 |
void pitch_unquant_3tap( |
| 85 |
spx_word16_t exc[], /* Input excitation */ |
| 86 |
spx_word32_t exc_out[], /* Output excitation */ |
| 87 |
int start, /* Smallest pitch value allowed */ |
| 88 |
int end, /* Largest pitch value allowed */ |
| 89 |
spx_word16_t pitch_coef, /* Voicing (pitch) coefficient */ |
| 90 |
const void *par, |
| 91 |
int nsf, /* Number of samples in subframe */ |
| 92 |
int *pitch_val, |
| 93 |
spx_word16_t *gain_val, |
| 94 |
SpeexBits *bits, |
| 95 |
char *stack, |
| 96 |
int lost, |
| 97 |
int subframe_offset, |
| 98 |
spx_word16_t last_pitch_gain, |
| 99 |
int cdbk_offset |
| 100 |
); |
| 101 |
|
| 102 |
/** Forced pitch delay and gain */ |
| 103 |
int forced_pitch_quant( |
| 104 |
spx_word16_t target[], /* Target vector */ |
| 105 |
spx_word16_t *sw, |
| 106 |
spx_coef_t ak[], /* LPCs for this subframe */ |
| 107 |
spx_coef_t awk1[], /* Weighted LPCs #1 for this subframe */ |
| 108 |
spx_coef_t awk2[], /* Weighted LPCs #2 for this subframe */ |
| 109 |
spx_sig_t exc[], /* Excitation */ |
| 110 |
const void *par, |
| 111 |
int start, /* Smallest pitch value allowed */ |
| 112 |
int end, /* Largest pitch value allowed */ |
| 113 |
spx_word16_t pitch_coef, /* Voicing (pitch) coefficient */ |
| 114 |
int p, /* Number of LPC coeffs */ |
| 115 |
int nsf, /* Number of samples in subframe */ |
| 116 |
SpeexBits *bits, |
| 117 |
char *stack, |
| 118 |
spx_word16_t *exc2, |
| 119 |
spx_word16_t *r, |
| 120 |
int complexity, |
| 121 |
int cdbk_offset, |
| 122 |
int plc_tuning, |
| 123 |
spx_word32_t *cumul_gain |
| 124 |
); |
| 125 |
|
| 126 |
/** Unquantize forced pitch delay and gain */ |
| 127 |
void forced_pitch_unquant( |
| 128 |
spx_word16_t exc[], /* Input excitation */ |
| 129 |
spx_word32_t exc_out[], /* Output excitation */ |
| 130 |
int start, /* Smallest pitch value allowed */ |
| 131 |
int end, /* Largest pitch value allowed */ |
| 132 |
spx_word16_t pitch_coef, /* Voicing (pitch) coefficient */ |
| 133 |
const void *par, |
| 134 |
int nsf, /* Number of samples in subframe */ |
| 135 |
int *pitch_val, |
| 136 |
spx_word16_t *gain_val, |
| 137 |
SpeexBits *bits, |
| 138 |
char *stack, |
| 139 |
int lost, |
| 140 |
int subframe_offset, |
| 141 |
spx_word16_t last_pitch_gain, |
| 142 |
int cdbk_offset |
| 143 |
); |
| 144 |
|
| 145 |
#endif /* LTP_H */ |