| 66 | } |
| 67 | |
| 68 | TfLiteStatus Prepare(TfLiteContext* context, TfLiteNode* node) { |
| 69 | auto* params = |
| 70 | reinterpret_cast<TfLiteAudioSpectrogramParams*>(node->user_data); |
| 71 | |
| 72 | TF_LITE_ENSURE_EQ(context, NumInputs(node), 1); |
| 73 | TF_LITE_ENSURE_EQ(context, NumOutputs(node), 1); |
| 74 | |
| 75 | const TfLiteTensor* input = GetInput(context, node, kInputTensor); |
| 76 | TfLiteTensor* output = GetOutput(context, node, kOutputTensor); |
| 77 | |
| 78 | TF_LITE_ENSURE_EQ(context, NumDimensions(input), 2); |
| 79 | |
| 80 | TF_LITE_ENSURE_EQ(context, output->type, kTfLiteFloat32); |
| 81 | TF_LITE_ENSURE_EQ(context, input->type, output->type); |
| 82 | |
| 83 | TF_LITE_ENSURE(context, params->spectrogram->Initialize(params->window_size, |
| 84 | params->stride)); |
| 85 | const int64_t sample_count = input->dims->data[0]; |
| 86 | const int64_t length_minus_window = (sample_count - params->window_size); |
| 87 | if (length_minus_window < 0) { |
| 88 | params->output_height = 0; |
| 89 | } else { |
| 90 | params->output_height = 1 + (length_minus_window / params->stride); |
| 91 | } |
| 92 | TfLiteIntArray* output_size = TfLiteIntArrayCreate(3); |
| 93 | output_size->data[0] = input->dims->data[1]; |
| 94 | output_size->data[1] = params->output_height; |
| 95 | output_size->data[2] = params->spectrogram->output_frequency_channels(); |
| 96 | |
| 97 | return context->ResizeTensor(context, output, output_size); |
| 98 | } |
| 99 | |
| 100 | template <KernelType kernel_type> |
| 101 | TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) { |
nothing calls this directly
no test coverage detected