/* Copyright 2018 The TensorFlow Authors. All Rights Reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ // This code resamples the FFT bins, and smooths then with triangle-shaped // weights to create a mel-frequency filter bank. For filter i centered at f_i, // there is a triangular weighting of the FFT bins that extends from // filter f_i-1 (with a value of zero at the left edge of the triangle) to f_i // (where the filter value is 1) to f_i+1 (where the filter values returns to // zero). // Note: this code fails if you ask for too many channels. The algorithm used // here assumes that each FFT bin contributes to at most two channels: the // right side of a triangle for channel i, and the left side of the triangle // for channel i+1. If you ask for so many channels that some of the // resulting mel triangle filters are smaller than a single FFT bin, these // channels may end up with no contributing FFT bins. The resulting mel // spectrum output will have some channels that are always zero. #include "tensorflow/lite/kernels/internal/mfcc_mel_filterbank.h" #include <math.h> namespace tflite { namespace internal { MfccMelFilterbank::MfccMelFilterbank() : … { … } bool MfccMelFilterbank::Initialize(int input_length, double input_sample_rate, int output_channel_count, double lower_frequency_limit, double upper_frequency_limit) { … } // Compute the mel spectrum from the squared-magnitude FFT input by taking the // square root, then summing FFT magnitudes under triangular integration windows // whose widths increase with frequency. void MfccMelFilterbank::Compute(const std::vector<double> &input, std::vector<double> *output) const { … } double MfccMelFilterbank::FreqToMel(double freq) const { … } } // namespace internal } // namespace tflite