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 #include "tensorflow/lite/experimental/microfrontend/lib/fft.h"
16
17 #include <string.h>
18
19 #define FIXED_POINT 16
20 #include "kiss_fft.h"
21 // Internal test dependency placeholder1
22 // Internal test dependency placeholder2
23 #include "tools/kiss_fftr.h"
24 // Internal test dependency placeholder3
25
FftCompute(struct FftState * state,const int16_t * input,int input_scale_shift)26 void FftCompute(struct FftState* state, const int16_t* input,
27 int input_scale_shift) {
28 const size_t input_size = state->input_size;
29 const size_t fft_size = state->fft_size;
30
31 int16_t* fft_input = state->input;
32 // First, scale the input by the given shift.
33 int i;
34 for (i = 0; i < input_size; ++i) {
35 *fft_input++ = (*input++) << input_scale_shift;
36 }
37 // Zero out whatever else remains in the top part of the input.
38 for (; i < fft_size; ++i) {
39 *fft_input++ = 0;
40 }
41
42 // Apply the FFT.
43 kiss_fftr((const kiss_fftr_cfg)state->scratch, state->input,
44 (kiss_fft_cpx*)state->output);
45 }
46
FftInit(struct FftState * state)47 void FftInit(struct FftState* state) {
48 // All the initialization is done in FftPopulateState()
49 }
50
FftReset(struct FftState * state)51 void FftReset(struct FftState* state) {
52 memset(state->input, 0, state->fft_size * sizeof(*state->input));
53 memset(state->output, 0, (state->fft_size / 2 + 1) * sizeof(*state->output));
54 }
55