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_FILTERBANK_H_ 16 #define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FILTERBANK_H_ 17 18 #include <stdint.h> 19 #include <stdlib.h> 20 21 #include "tensorflow/lite/experimental/microfrontend/lib/fft.h" 22 23 #define kFilterbankBits 12 24 25 #ifdef __cplusplus 26 extern "C" { 27 #endif 28 29 struct FilterbankState { 30 int num_channels; 31 int start_index; 32 int end_index; 33 int16_t* channel_frequency_starts; 34 int16_t* channel_weight_starts; 35 int16_t* channel_widths; 36 int16_t* weights; 37 int16_t* unweights; 38 uint64_t* work; 39 }; 40 41 // Converts the relevant complex values of an FFT output into energy (the 42 // square magnitude). 43 void FilterbankConvertFftComplexToEnergy(struct FilterbankState* state, 44 struct complex_int16_t* fft_output, 45 int32_t* energy); 46 47 // Computes the mel-scale filterbank on the given energy array. Output is cached 48 // internally - to fetch it, you need to call FilterbankSqrt. 49 void FilterbankAccumulateChannels(struct FilterbankState* state, 50 const int32_t* energy); 51 52 // Applies an integer square root to the 64 bit intermediate values of the 53 // filterbank, and returns a pointer to them. Memory will be invalidated the 54 // next time FilterbankAccumulateChannels is called. 55 uint32_t* FilterbankSqrt(struct FilterbankState* state, int scale_down_shift); 56 57 void FilterbankReset(struct FilterbankState* state); 58 59 #ifdef __cplusplus 60 } // extern "C" 61 #endif 62 63 #endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FILTERBANK_H_ 64