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 #ifndef __LC3_LTPF_H 20 #define __LC3_LTPF_H 21 22 #include "common.h" 23 #include "bits.h" 24 25 26 /** 27 * LTPF data 28 */ 29 30 typedef struct lc3_ltpf_data { 31 bool active; 32 int pitch_index; 33 } lc3_ltpf_data_t; 34 35 36 /* ---------------------------------------------------------------------------- 37 * Encoding 38 * -------------------------------------------------------------------------- */ 39 40 /** 41 * LTPF analysis 42 * dt, sr Duration and samplerate of the frame 43 * ltpf Context of analysis 44 * allowed True when activation of LTPF is allowed 45 * x [-d..-1] Previous, [0..ns-1] Current samples 46 * data Return bitstream data 47 * return True when pitch present, False otherwise 48 * 49 * The `x` vector is aligned on 32 bits 50 * The number of previous samples `d` accessed on `x` is : 51 * d: { 10, 20, 30, 40, 60 } - 1 for samplerates from 8KHz to 48KHz 52 */ 53 bool lc3_ltpf_analyse(enum lc3_dt dt, enum lc3_srate sr, 54 lc3_ltpf_analysis_t *ltpf, const int16_t *x, lc3_ltpf_data_t *data); 55 56 /** 57 * LTPF disable 58 * data LTPF data, disabled activation on return 59 */ 60 void lc3_ltpf_disable(lc3_ltpf_data_t *data); 61 62 /** 63 * Return number of bits coding the bitstream data 64 * pitch True when pitch present, False otherwise 65 * return Bit consumption, including the pitch present flag 66 */ 67 int lc3_ltpf_get_nbits(bool pitch); 68 69 /** 70 * Put bitstream data 71 * bits Bitstream context 72 * data LTPF data 73 */ 74 void lc3_ltpf_put_data(lc3_bits_t *bits, const lc3_ltpf_data_t *data); 75 76 77 /* ---------------------------------------------------------------------------- 78 * Decoding 79 * -------------------------------------------------------------------------- */ 80 /** 81 * Get bitstream data 82 * bits Bitstream context 83 * data Return bitstream data 84 */ 85 void lc3_ltpf_get_data(lc3_bits_t *bits, lc3_ltpf_data_t *data); 86 87 /** 88 * LTPF synthesis 89 * dt, sr Duration and samplerate of the frame 90 * nbytes Size in bytes of the frame 91 * ltpf Context of synthesis 92 * data Bitstream data, NULL when pitch not present 93 * xr Base address of ring buffer of decoded samples 94 * x Samples to proceed in the ring buffer, filtered as output 95 * 96 * The size of the ring buffer is `nh + ns`. 97 * The filtering needs an history of at least 18 ms. 98 */ 99 void lc3_ltpf_synthesize(enum lc3_dt dt, enum lc3_srate sr, int nbytes, 100 lc3_ltpf_synthesis_t *ltpf, const lc3_ltpf_data_t *data, 101 const float *xr, float *x); 102 103 104 #endif /* __LC3_LTPF_H */ 105