19a19cd78SMatthias Ringwald /****************************************************************************** 29a19cd78SMatthias Ringwald * 34930cef6SMatthias 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_SNS_H 209a19cd78SMatthias Ringwald #define __LC3_SNS_H 219a19cd78SMatthias Ringwald 229a19cd78SMatthias Ringwald #include "common.h" 239a19cd78SMatthias Ringwald #include "bits.h" 249a19cd78SMatthias Ringwald 259a19cd78SMatthias Ringwald 269a19cd78SMatthias Ringwald /** 279a19cd78SMatthias Ringwald * Bitstream data 289a19cd78SMatthias Ringwald */ 299a19cd78SMatthias Ringwald 309a19cd78SMatthias Ringwald typedef struct lc3_sns_data { 319a19cd78SMatthias Ringwald int lfcb, hfcb; 329a19cd78SMatthias Ringwald int shape, gain; 339a19cd78SMatthias Ringwald int idx_a, idx_b; 349a19cd78SMatthias Ringwald bool ls_a, ls_b; 359a19cd78SMatthias Ringwald } lc3_sns_data_t; 369a19cd78SMatthias Ringwald 379a19cd78SMatthias Ringwald 389a19cd78SMatthias Ringwald /* ---------------------------------------------------------------------------- 399a19cd78SMatthias Ringwald * Encoding 409a19cd78SMatthias Ringwald * -------------------------------------------------------------------------- */ 419a19cd78SMatthias Ringwald 429a19cd78SMatthias Ringwald /** 439a19cd78SMatthias Ringwald * SNS analysis 449a19cd78SMatthias Ringwald * dt, sr Duration and samplerate of the frame 45*6897da5cSDirk Helbig * nbytes Size in bytes of the frame 469a19cd78SMatthias Ringwald * eb Energy estimation per bands, and count of bands 479a19cd78SMatthias Ringwald * att 1: Attack detected 0: Otherwise 489a19cd78SMatthias Ringwald * data Return bitstream data 499a19cd78SMatthias Ringwald * x Spectral coefficients 509a19cd78SMatthias Ringwald * y Return shapped coefficients 519a19cd78SMatthias Ringwald * 529a19cd78SMatthias Ringwald * `x` and `y` can be the same buffer 539a19cd78SMatthias Ringwald */ 54*6897da5cSDirk Helbig void lc3_sns_analyze( 55*6897da5cSDirk Helbig enum lc3_dt dt, enum lc3_srate sr, int nbytes, 569a19cd78SMatthias Ringwald const float *eb, bool att, lc3_sns_data_t *data, 579a19cd78SMatthias Ringwald const float *x, float *y); 589a19cd78SMatthias Ringwald 599a19cd78SMatthias Ringwald /** 609a19cd78SMatthias Ringwald * Return number of bits coding the bitstream data 619a19cd78SMatthias Ringwald * return Bit consumption 629a19cd78SMatthias Ringwald */ 639a19cd78SMatthias Ringwald int lc3_sns_get_nbits(void); 649a19cd78SMatthias Ringwald 659a19cd78SMatthias Ringwald /** 669a19cd78SMatthias Ringwald * Put bitstream data 679a19cd78SMatthias Ringwald * bits Bitstream context 689a19cd78SMatthias Ringwald * data Bitstream data 699a19cd78SMatthias Ringwald */ 709a19cd78SMatthias Ringwald void lc3_sns_put_data(lc3_bits_t *bits, const lc3_sns_data_t *data); 719a19cd78SMatthias Ringwald 729a19cd78SMatthias Ringwald 739a19cd78SMatthias Ringwald /* ---------------------------------------------------------------------------- 749a19cd78SMatthias Ringwald * Decoding 759a19cd78SMatthias Ringwald * -------------------------------------------------------------------------- */ 769a19cd78SMatthias Ringwald 779a19cd78SMatthias Ringwald /** 789a19cd78SMatthias Ringwald * Get bitstream data 799a19cd78SMatthias Ringwald * bits Bitstream context 809a19cd78SMatthias Ringwald * data Return SNS data 819a19cd78SMatthias Ringwald * return 0: Ok -1: Invalid SNS data 829a19cd78SMatthias Ringwald */ 839a19cd78SMatthias Ringwald int lc3_sns_get_data(lc3_bits_t *bits, lc3_sns_data_t *data); 849a19cd78SMatthias Ringwald 859a19cd78SMatthias Ringwald /** 869a19cd78SMatthias Ringwald * SNS synthesis 879a19cd78SMatthias Ringwald * dt, sr Duration and samplerate of the frame 889a19cd78SMatthias Ringwald * data Bitstream data 899a19cd78SMatthias Ringwald * x Spectral coefficients 909a19cd78SMatthias Ringwald * y Return shapped coefficients 919a19cd78SMatthias Ringwald * 929a19cd78SMatthias Ringwald * `x` and `y` can be the same buffer 939a19cd78SMatthias Ringwald */ 949a19cd78SMatthias Ringwald void lc3_sns_synthesize(enum lc3_dt dt, enum lc3_srate sr, 959a19cd78SMatthias Ringwald const lc3_sns_data_t *data, const float *x, float *y); 969a19cd78SMatthias Ringwald 979a19cd78SMatthias Ringwald 989a19cd78SMatthias Ringwald #endif /* __LC3_SNS_H */ 99