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