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 - Spectral Noise Shaping 21 * 22 * Reference : Low Complexity Communication Codec (LC3) 23 * Bluetooth Specification v1.0 24 */ 25 26 #ifndef __LC3_SNS_H 27 #define __LC3_SNS_H 28 29 #include "common.h" 30 #include "bits.h" 31 32 33 /** 34 * Bitstream data 35 */ 36 37 typedef struct lc3_sns_data { 38 int lfcb, hfcb; 39 int shape, gain; 40 int idx_a, idx_b; 41 bool ls_a, ls_b; 42 } lc3_sns_data_t; 43 44 45 /* ---------------------------------------------------------------------------- 46 * Encoding 47 * -------------------------------------------------------------------------- */ 48 49 /** 50 * SNS analysis 51 * dt, sr Duration and samplerate of the frame 52 * eb Energy estimation per bands, and count of bands 53 * att 1: Attack detected 0: Otherwise 54 * data Return bitstream data 55 * x Spectral coefficients 56 * y Return shapped coefficients 57 * 58 * `x` and `y` can be the same buffer 59 */ 60 void lc3_sns_analyze(enum lc3_dt dt, enum lc3_srate sr, 61 const float *eb, bool att, lc3_sns_data_t *data, 62 const float *x, float *y); 63 64 /** 65 * Return number of bits coding the bitstream data 66 * return Bit consumption 67 */ 68 int lc3_sns_get_nbits(void); 69 70 /** 71 * Put bitstream data 72 * bits Bitstream context 73 * data Bitstream data 74 */ 75 void lc3_sns_put_data(lc3_bits_t *bits, const lc3_sns_data_t *data); 76 77 78 /* ---------------------------------------------------------------------------- 79 * Decoding 80 * -------------------------------------------------------------------------- */ 81 82 /** 83 * Get bitstream data 84 * bits Bitstream context 85 * data Return SNS data 86 * return 0: Ok -1: Invalid SNS data 87 */ 88 int lc3_sns_get_data(lc3_bits_t *bits, lc3_sns_data_t *data); 89 90 /** 91 * SNS synthesis 92 * dt, sr Duration and samplerate of the frame 93 * data Bitstream data 94 * x Spectral coefficients 95 * y Return shapped coefficients 96 * 97 * `x` and `y` can be the same buffer 98 */ 99 void lc3_sns_synthesize(enum lc3_dt dt, enum lc3_srate sr, 100 const lc3_sns_data_t *data, const float *x, float *y); 101 102 103 #endif /* __LC3_SNS_H */ 104