1 /* Copyright 2018 The TensorFlow Authors. All Rights Reserved. 2 3 Licensed under the Apache License, Version 2.0 (the "License"); 4 you may not use this file except in compliance with the License. 5 You may obtain a copy of the License at 6 7 http://www.apache.org/licenses/LICENSE-2.0 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 ==============================================================================*/ 15 #ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_PCAN_GAIN_CONTROL_UTIL_H_ 16 #define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_PCAN_GAIN_CONTROL_UTIL_H_ 17 18 #include "tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.h" 19 20 #define kWideDynamicFunctionBits 32 21 #define kWideDynamicFunctionLUTSize (4 * kWideDynamicFunctionBits - 3) 22 23 #ifdef __cplusplus 24 extern "C" { 25 #endif 26 27 struct PcanGainControlConfig { 28 // set to false (0) to disable this module 29 int enable_pcan; 30 // gain normalization exponent (0.0 disables, 1.0 full strength) 31 float strength; 32 // positive value added in the normalization denominator 33 float offset; 34 // number of fractional bits in the gain 35 int gain_bits; 36 }; 37 38 void PcanGainControlFillConfigWithDefaults( 39 struct PcanGainControlConfig* config); 40 41 int16_t PcanGainLookupFunction(const struct PcanGainControlConfig* config, 42 int32_t input_bits, uint32_t x); 43 44 int PcanGainControlPopulateState(const struct PcanGainControlConfig* config, 45 struct PcanGainControlState* state, 46 uint32_t* noise_estimate, 47 const int num_channels, 48 const uint16_t smoothing_bits, 49 const int32_t input_correction_bits); 50 51 void PcanGainControlFreeStateContents(struct PcanGainControlState* state); 52 53 #ifdef __cplusplus 54 } // extern "C" 55 #endif 56 57 #endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_PCAN_GAIN_CONTROL_UTIL_H_ 58