frontend.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* Copyright 2018 The TensorFlow Authors. All Rights Reserved.
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. ==============================================================================*/
  12. #ifndef TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FRONTEND_H_
  13. #define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FRONTEND_H_
  14. #include <stdint.h>
  15. #include <stdlib.h>
  16. #include "tensorflow/lite/experimental/microfrontend/lib/fft.h"
  17. #include "tensorflow/lite/experimental/microfrontend/lib/filterbank.h"
  18. #include "tensorflow/lite/experimental/microfrontend/lib/log_scale.h"
  19. #include "tensorflow/lite/experimental/microfrontend/lib/noise_reduction.h"
  20. #include "tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.h"
  21. #include "tensorflow/lite/experimental/microfrontend/lib/window.h"
  22. #ifdef __cplusplus
  23. extern "C" {
  24. #endif
  25. struct FrontendState {
  26. struct WindowState window;
  27. struct FftState fft;
  28. struct FilterbankState filterbank;
  29. struct NoiseReductionState noise_reduction;
  30. struct PcanGainControlState pcan_gain_control;
  31. struct LogScaleState log_scale;
  32. };
  33. struct FrontendOutput {
  34. const uint16_t* values;
  35. size_t size;
  36. };
  37. // Main entry point to processing frontend samples. Updates num_samples_read to
  38. // contain the number of samples that have been consumed from the input array.
  39. // Returns a struct containing the generated output. If not enough samples were
  40. // added to generate a feature vector, the returned size will be 0 and the
  41. // values pointer will be NULL. Note that the output pointer will be invalidated
  42. // as soon as FrontendProcessSamples is called again, so copy the contents
  43. // elsewhere if you need to use them later.
  44. struct FrontendOutput FrontendProcessSamples(struct FrontendState* state,
  45. const int16_t* samples,
  46. size_t num_samples,
  47. size_t* num_samples_read);
  48. void FrontendReset(struct FrontendState* state);
  49. #ifdef __cplusplus
  50. } // extern "C"
  51. #endif
  52. #endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FRONTEND_H_