ex

Fork of mbed-os-example-mbed5-blinky by mbed-os-examples

Committer:
TMBOY
Date:
Tue Jul 18 16:54:45 2017 +0800
Revision:
47:9e361da97763
?

Who changed what in which revision?

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