1 /****************************************************************************** 2 * 3 * Copyright 2022 Google LLC 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 `x` vector is aligned on 32 bits 57 * The number of previous samples `d` accessed on `x` is : 58 * d: { 10, 20, 30, 40, 60 } - 1 for samplerates from 8KHz to 48KHz 59 */ 60 bool lc3_ltpf_analyse(enum lc3_dt dt, enum lc3_srate sr, 61 lc3_ltpf_analysis_t *ltpf, const int16_t *x, lc3_ltpf_data_t *data); 62 63 /** 64 * LTPF disable 65 * data LTPF data, disabled activation on return 66 */ 67 void lc3_ltpf_disable(lc3_ltpf_data_t *data); 68 69 /** 70 * Return number of bits coding the bitstream data 71 * pitch True when pitch present, False otherwise 72 * return Bit consumption, including the pitch present flag 73 */ 74 int lc3_ltpf_get_nbits(bool pitch); 75 76 /** 77 * Put bitstream data 78 * bits Bitstream context 79 * data LTPF data 80 */ 81 void lc3_ltpf_put_data(lc3_bits_t *bits, const lc3_ltpf_data_t *data); 82 83 84 /* ---------------------------------------------------------------------------- 85 * Decoding 86 * -------------------------------------------------------------------------- */ 87 /** 88 * Get bitstream data 89 * bits Bitstream context 90 * data Return bitstream data 91 */ 92 void lc3_ltpf_get_data(lc3_bits_t *bits, lc3_ltpf_data_t *data); 93 94 /** 95 * LTPF synthesis 96 * dt, sr Duration and samplerate of the frame 97 * nbytes Size in bytes of the frame 98 * ltpf Context of synthesis 99 * data Bitstream data, NULL when pitch not present 100 * xr Base address of ring buffer of decoded samples 101 * x Samples to proceed in the ring buffer, filtered as output 102 * 103 * The size of the ring buffer is `nh + ns`. 104 * The filtering needs an history of at least 18 ms. 105 */ 106 void lc3_ltpf_synthesize(enum lc3_dt dt, enum lc3_srate sr, int nbytes, 107 lc3_ltpf_synthesis_t *ltpf, const lc3_ltpf_data_t *data, 108 const float *xr, float *x); 109 110 111 #endif /* __LC3_LTPF_H */ 112