/* 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. ==============================================================================*/ // Class for generating spectrogram slices from a waveform. // Initialize() should be called before calls to other functions. Once // Initialize() has been called and returned true, The Compute*() functions can // be called repeatedly with sequential input data (ie. the first element of the // next input vector directly follows the last element of the previous input // vector). Whenever enough audio samples are buffered to produce a // new frame, it will be placed in output. Output is cleared on each // call to Compute*(). This class is thread-unsafe, and should only be // called from one thread at a time. // With the default parameters, the output of this class should be very // close to the results of the following MATLAB code: // overlap_samples = window_length_samples - step_samples; // window = hann(window_length_samples, 'periodic'); // S = abs(spectrogram(audio, window, overlap_samples)).^2; #ifndef TENSORFLOW_LITE_KERNELS_INTERNAL_SPECTROGRAM_H_ #define TENSORFLOW_LITE_KERNELS_INTERNAL_SPECTROGRAM_H_ #include <complex> #include <deque> #include <vector> #include "third_party/fft2d/fft.h" namespace tflite { namespace internal { class Spectrogram { … }; // Explicit instantiations in spectrogram.cc. extern template bool Spectrogram::ComputeComplexSpectrogram( const std::vector<float>& input, std::vector<std::vector<std::complex<float>>>*); extern template bool Spectrogram::ComputeComplexSpectrogram( const std::vector<double>& input, std::vector<std::vector<std::complex<float>>>*); extern template bool Spectrogram::ComputeComplexSpectrogram( const std::vector<float>& input, std::vector<std::vector<std::complex<double>>>*); extern template bool Spectrogram::ComputeComplexSpectrogram( const std::vector<double>& input, std::vector<std::vector<std::complex<double>>>*); extern template bool Spectrogram::ComputeSquaredMagnitudeSpectrogram( const std::vector<float>& input, std::vector<std::vector<float>>*); extern template bool Spectrogram::ComputeSquaredMagnitudeSpectrogram( const std::vector<double>& input, std::vector<std::vector<float>>*); extern template bool Spectrogram::ComputeSquaredMagnitudeSpectrogram( const std::vector<float>& input, std::vector<std::vector<double>>*); extern template bool Spectrogram::ComputeSquaredMagnitudeSpectrogram( const std::vector<double>& input, std::vector<std::vector<double>>*); } // namespace internal } // namespace tflite #endif // TENSORFLOW_LITE_KERNELS_INTERNAL_SPECTROGRAM_H_