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/window_io.h"
16
WindowWriteMemmapPreamble(FILE * fp,const struct WindowState * state)17 void WindowWriteMemmapPreamble(FILE* fp, const struct WindowState* state) {
18 fprintf(fp, "static int16_t window_coefficients[] = {\n");
19 int i;
20 for (i = 0; i < state->size; ++i) {
21 fprintf(fp, "%d", state->coefficients[i]);
22 if (i < state->size - 1) {
23 fprintf(fp, ", ");
24 }
25 }
26 fprintf(fp, "};\n");
27 fprintf(fp, "static int16_t window_input[%zu];\n", state->size);
28 fprintf(fp, "static int16_t window_output[%zu];\n", state->size);
29 fprintf(fp, "\n");
30 }
31
WindowWriteMemmap(FILE * fp,const struct WindowState * state,const char * variable)32 void WindowWriteMemmap(FILE* fp, const struct WindowState* state,
33 const char* variable) {
34 fprintf(fp, "%s->size = %zu;\n", variable, state->size);
35 fprintf(fp, "%s->coefficients = window_coefficients;\n", variable);
36 fprintf(fp, "%s->step = %zu;\n", variable, state->step);
37
38 fprintf(fp, "%s->input = window_input;\n", variable);
39 fprintf(fp, "%s->input_used = %zu;\n", variable, state->input_used);
40 fprintf(fp, "%s->output = window_output;\n", variable);
41 fprintf(fp, "%s->max_abs_output_value = %d;\n", variable,
42 state->max_abs_output_value);
43 }
44