1 /****************************************************************************** 2 * 3 * Copyright 2021 Google, Inc. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ******************************************************************************/ 18 19 /** 20 * LC3 - Long Term Postfilter 21 * 22 * Reference : Low Complexity Communication Codec (LC3) 23 * Bluetooth Specification v1.0 24 */ 25 26 #ifndef __LC3_LTPF_H 27 #define __LC3_LTPF_H 28 29 #include "common.h" 30 #include "bits.h" 31 32 33 /** 34 * LTPF data 35 */ 36 37 typedef struct lc3_ltpf_data { 38 bool active; 39 int pitch_index; 40 } lc3_ltpf_data_t; 41 42 43 /* ---------------------------------------------------------------------------- 44 * Encoding 45 * -------------------------------------------------------------------------- */ 46 47 /** 48 * LTPF analysis 49 * dt, sr Duration and samplerate of the frame 50 * ltpf Context of analysis 51 * allowed True when activation of LTPF is allowed 52 * x [-d..-1] Previous, [0..ns-1] Current samples 53 * data Return bitstream data 54 * return True when pitch present, False otherwise 55 * 56 * The number of previous samples `d` accessed on `x` is : 57 * d: { 10, 20, 30, 40, 60 } - 1 for samplerates from 8KHz to 48KHz 58 */ 59 bool lc3_ltpf_analyse(enum lc3_dt dt, enum lc3_srate sr, 60 lc3_ltpf_analysis_t *ltpf, const float *x, lc3_ltpf_data_t *data); 61 62 /** 63 * LTPF disable 64 * data LTPF data, disabled activation on return 65 */ 66 void lc3_ltpf_disable(lc3_ltpf_data_t *data); 67 68 /** 69 * Return number of bits coding the bitstream data 70 * pitch True when pitch present, False otherwise 71 * return Bit consumption, including the pitch present flag 72 */ 73 int lc3_ltpf_get_nbits(bool pitch); 74 75 /** 76 * Put bitstream data 77 * bits Bitstream context 78 * data LTPF data 79 */ 80 void lc3_ltpf_put_data(lc3_bits_t *bits, const lc3_ltpf_data_t *data); 81 82 83 /* ---------------------------------------------------------------------------- 84 * Decoding 85 * -------------------------------------------------------------------------- */ 86 /** 87 * Get bitstream data 88 * bits Bitstream context 89 * data Return bitstream data 90 */ 91 void lc3_ltpf_get_data(lc3_bits_t *bits, lc3_ltpf_data_t *data); 92 93 /** 94 * LTPF synthesis 95 * dt, sr Duration and samplerate of the frame 96 * nbytes Size in bytes of the frame 97 * ltpf Context of synthesis 98 * data Bitstream data, NULL when pitch not present 99 * x [-d..-1] Previous, [0..ns-1] Current, filtered as output 100 * 101 * The number of previous samples `d` accessed on `x` is about 18 ms 102 */ 103 void lc3_ltpf_synthesize(enum lc3_dt dt, enum lc3_srate sr, int nbytes, 104 lc3_ltpf_synthesis_t *ltpf, const lc3_ltpf_data_t *data, float *x); 105 106 107 #endif /* __LC3_LTPF_H */ 108