| 93 | // of these values. |
| 94 | template <KernelType kernel_type> |
| 95 | TfLiteStatus Eval(TfLiteContext* context, TfLiteNode* node) { |
| 96 | auto* params = reinterpret_cast<TfLiteMfccParams*>(node->user_data); |
| 97 | |
| 98 | const TfLiteTensor* input_wav = GetInput(context, node, kInputTensorWav); |
| 99 | const TfLiteTensor* input_rate = GetInput(context, node, kInputTensorRate); |
| 100 | TfLiteTensor* output = GetOutput(context, node, kOutputTensor); |
| 101 | |
| 102 | const int32 sample_rate = *GetTensorData<int>(input_rate); |
| 103 | |
| 104 | const int spectrogram_channels = input_wav->dims->data[2]; |
| 105 | const int spectrogram_samples = input_wav->dims->data[1]; |
| 106 | const int audio_channels = input_wav->dims->data[0]; |
| 107 | |
| 108 | internal::Mfcc mfcc; |
| 109 | mfcc.set_upper_frequency_limit(params->upper_frequency_limit); |
| 110 | mfcc.set_lower_frequency_limit(params->lower_frequency_limit); |
| 111 | mfcc.set_filterbank_channel_count(params->filterbank_channel_count); |
| 112 | mfcc.set_dct_coefficient_count(params->dct_coefficient_count); |
| 113 | |
| 114 | mfcc.Initialize(spectrogram_channels, sample_rate); |
| 115 | |
| 116 | const float* spectrogram_flat = GetTensorData<float>(input_wav); |
| 117 | float* output_flat = GetTensorData<float>(output); |
| 118 | |
| 119 | for (int audio_channel = 0; audio_channel < audio_channels; ++audio_channel) { |
| 120 | for (int spectrogram_sample = 0; spectrogram_sample < spectrogram_samples; |
| 121 | ++spectrogram_sample) { |
| 122 | const float* sample_data = |
| 123 | spectrogram_flat + |
| 124 | (audio_channel * spectrogram_samples * spectrogram_channels) + |
| 125 | (spectrogram_sample * spectrogram_channels); |
| 126 | std::vector<double> mfcc_input(sample_data, |
| 127 | sample_data + spectrogram_channels); |
| 128 | std::vector<double> mfcc_output; |
| 129 | mfcc.Compute(mfcc_input, &mfcc_output); |
| 130 | TF_LITE_ENSURE_EQ(context, params->dct_coefficient_count, |
| 131 | mfcc_output.size()); |
| 132 | float* output_data = output_flat + |
| 133 | (audio_channel * spectrogram_samples * |
| 134 | params->dct_coefficient_count) + |
| 135 | (spectrogram_sample * params->dct_coefficient_count); |
| 136 | for (int i = 0; i < params->dct_coefficient_count; ++i) { |
| 137 | output_data[i] = mfcc_output[i]; |
| 138 | } |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | return kTfLiteOk; |
| 143 | } |
| 144 | |
| 145 | } // namespace mfcc |
| 146 |
nothing calls this directly
no test coverage detected