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