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_FRONTEND_H_
16 #define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FRONTEND_H_
17 
18 #include <stdint.h>
19 #include <stdlib.h>
20 
21 #include "tensorflow/lite/experimental/microfrontend/lib/fft.h"
22 #include "tensorflow/lite/experimental/microfrontend/lib/filterbank.h"
23 #include "tensorflow/lite/experimental/microfrontend/lib/log_scale.h"
24 #include "tensorflow/lite/experimental/microfrontend/lib/noise_reduction.h"
25 #include "tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.h"
26 #include "tensorflow/lite/experimental/microfrontend/lib/window.h"
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 struct FrontendState {
33   struct WindowState window;
34   struct FftState fft;
35   struct FilterbankState filterbank;
36   struct NoiseReductionState noise_reduction;
37   struct PcanGainControlState pcan_gain_control;
38   struct LogScaleState log_scale;
39 };
40 
41 struct FrontendOutput {
42   const uint16_t* values;
43   size_t size;
44 };
45 
46 // Main entry point to processing frontend samples. Updates num_samples_read to
47 // contain the number of samples that have been consumed from the input array.
48 // Returns a struct containing the generated output. If not enough samples were
49 // added to generate a feature vector, the returned size will be 0 and the
50 // values pointer will be NULL. Note that the output pointer will be invalidated
51 // as soon as FrontendProcessSamples is called again, so copy the contents
52 // elsewhere if you need to use them later.
53 struct FrontendOutput FrontendProcessSamples(struct FrontendState* state,
54                                              const int16_t* samples,
55                                              size_t num_samples,
56                                              size_t* num_samples_read);
57 
58 void FrontendReset(struct FrontendState* state);
59 
60 #ifdef __cplusplus
61 }  // extern "C"
62 #endif
63 
64 #endif  // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FRONTEND_H_
65