19a19cd78SMatthias Ringwald /****************************************************************************** 29a19cd78SMatthias Ringwald * 3*4930cef6SMatthias Ringwald * Copyright 2022 Google LLC 49a19cd78SMatthias Ringwald * 59a19cd78SMatthias Ringwald * Licensed under the Apache License, Version 2.0 (the "License"); 69a19cd78SMatthias Ringwald * you may not use this file except in compliance with the License. 79a19cd78SMatthias Ringwald * You may obtain a copy of the License at: 89a19cd78SMatthias Ringwald * 99a19cd78SMatthias Ringwald * http://www.apache.org/licenses/LICENSE-2.0 109a19cd78SMatthias Ringwald * 119a19cd78SMatthias Ringwald * Unless required by applicable law or agreed to in writing, software 129a19cd78SMatthias Ringwald * distributed under the License is distributed on an "AS IS" BASIS, 139a19cd78SMatthias Ringwald * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 149a19cd78SMatthias Ringwald * See the License for the specific language governing permissions and 159a19cd78SMatthias Ringwald * limitations under the License. 169a19cd78SMatthias Ringwald * 179a19cd78SMatthias Ringwald ******************************************************************************/ 189a19cd78SMatthias Ringwald 199a19cd78SMatthias Ringwald #ifndef __LC3_LTPF_H 209a19cd78SMatthias Ringwald #define __LC3_LTPF_H 219a19cd78SMatthias Ringwald 229a19cd78SMatthias Ringwald #include "common.h" 239a19cd78SMatthias Ringwald #include "bits.h" 249a19cd78SMatthias Ringwald 259a19cd78SMatthias Ringwald 269a19cd78SMatthias Ringwald /** 279a19cd78SMatthias Ringwald * LTPF data 289a19cd78SMatthias Ringwald */ 299a19cd78SMatthias Ringwald 309a19cd78SMatthias Ringwald typedef struct lc3_ltpf_data { 319a19cd78SMatthias Ringwald bool active; 329a19cd78SMatthias Ringwald int pitch_index; 339a19cd78SMatthias Ringwald } lc3_ltpf_data_t; 349a19cd78SMatthias Ringwald 359a19cd78SMatthias Ringwald 369a19cd78SMatthias Ringwald /* ---------------------------------------------------------------------------- 379a19cd78SMatthias Ringwald * Encoding 389a19cd78SMatthias Ringwald * -------------------------------------------------------------------------- */ 399a19cd78SMatthias Ringwald 409a19cd78SMatthias Ringwald /** 419a19cd78SMatthias Ringwald * LTPF analysis 429a19cd78SMatthias Ringwald * dt, sr Duration and samplerate of the frame 439a19cd78SMatthias Ringwald * ltpf Context of analysis 449a19cd78SMatthias Ringwald * allowed True when activation of LTPF is allowed 459a19cd78SMatthias Ringwald * x [-d..-1] Previous, [0..ns-1] Current samples 469a19cd78SMatthias Ringwald * data Return bitstream data 479a19cd78SMatthias Ringwald * return True when pitch present, False otherwise 489a19cd78SMatthias Ringwald * 49*4930cef6SMatthias Ringwald * The `x` vector is aligned on 32 bits 509a19cd78SMatthias Ringwald * The number of previous samples `d` accessed on `x` is : 519a19cd78SMatthias Ringwald * d: { 10, 20, 30, 40, 60 } - 1 for samplerates from 8KHz to 48KHz 529a19cd78SMatthias Ringwald */ 539a19cd78SMatthias Ringwald bool lc3_ltpf_analyse(enum lc3_dt dt, enum lc3_srate sr, 54*4930cef6SMatthias Ringwald lc3_ltpf_analysis_t *ltpf, const int16_t *x, lc3_ltpf_data_t *data); 559a19cd78SMatthias Ringwald 569a19cd78SMatthias Ringwald /** 579a19cd78SMatthias Ringwald * LTPF disable 589a19cd78SMatthias Ringwald * data LTPF data, disabled activation on return 599a19cd78SMatthias Ringwald */ 609a19cd78SMatthias Ringwald void lc3_ltpf_disable(lc3_ltpf_data_t *data); 619a19cd78SMatthias Ringwald 629a19cd78SMatthias Ringwald /** 639a19cd78SMatthias Ringwald * Return number of bits coding the bitstream data 649a19cd78SMatthias Ringwald * pitch True when pitch present, False otherwise 659a19cd78SMatthias Ringwald * return Bit consumption, including the pitch present flag 669a19cd78SMatthias Ringwald */ 679a19cd78SMatthias Ringwald int lc3_ltpf_get_nbits(bool pitch); 689a19cd78SMatthias Ringwald 699a19cd78SMatthias Ringwald /** 709a19cd78SMatthias Ringwald * Put bitstream data 719a19cd78SMatthias Ringwald * bits Bitstream context 729a19cd78SMatthias Ringwald * data LTPF data 739a19cd78SMatthias Ringwald */ 749a19cd78SMatthias Ringwald void lc3_ltpf_put_data(lc3_bits_t *bits, const lc3_ltpf_data_t *data); 759a19cd78SMatthias Ringwald 769a19cd78SMatthias Ringwald 779a19cd78SMatthias Ringwald /* ---------------------------------------------------------------------------- 789a19cd78SMatthias Ringwald * Decoding 799a19cd78SMatthias Ringwald * -------------------------------------------------------------------------- */ 809a19cd78SMatthias Ringwald /** 819a19cd78SMatthias Ringwald * Get bitstream data 829a19cd78SMatthias Ringwald * bits Bitstream context 839a19cd78SMatthias Ringwald * data Return bitstream data 849a19cd78SMatthias Ringwald */ 859a19cd78SMatthias Ringwald void lc3_ltpf_get_data(lc3_bits_t *bits, lc3_ltpf_data_t *data); 869a19cd78SMatthias Ringwald 879a19cd78SMatthias Ringwald /** 889a19cd78SMatthias Ringwald * LTPF synthesis 899a19cd78SMatthias Ringwald * dt, sr Duration and samplerate of the frame 909a19cd78SMatthias Ringwald * nbytes Size in bytes of the frame 919a19cd78SMatthias Ringwald * ltpf Context of synthesis 929a19cd78SMatthias Ringwald * data Bitstream data, NULL when pitch not present 93*4930cef6SMatthias Ringwald * xr Base address of ring buffer of decoded samples 94*4930cef6SMatthias Ringwald * x Samples to proceed in the ring buffer, filtered as output 959a19cd78SMatthias Ringwald * 96*4930cef6SMatthias Ringwald * The size of the ring buffer is `nh + ns`. 97*4930cef6SMatthias Ringwald * The filtering needs an history of at least 18 ms. 989a19cd78SMatthias Ringwald */ 999a19cd78SMatthias Ringwald void lc3_ltpf_synthesize(enum lc3_dt dt, enum lc3_srate sr, int nbytes, 100*4930cef6SMatthias Ringwald lc3_ltpf_synthesis_t *ltpf, const lc3_ltpf_data_t *data, 101*4930cef6SMatthias Ringwald const float *xr, float *x); 1029a19cd78SMatthias Ringwald 1039a19cd78SMatthias Ringwald 1049a19cd78SMatthias Ringwald #endif /* __LC3_LTPF_H */ 105