ian@0: // Copyright 2011, Ian Hobson. ian@0: // ian@0: // This file is part of gpsynth. ian@0: // ian@0: // gpsynth is free software: you can redistribute it and/or modify ian@0: // it under the terms of the GNU General Public License as published by ian@0: // the Free Software Foundation, either version 3 of the License, or ian@0: // (at your option) any later version. ian@0: // ian@0: // gpsynth is distributed in the hope that it will be useful, ian@0: // but WITHOUT ANY WARRANTY; without even the implied warranty of ian@0: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ian@0: // GNU General Public License for more details. ian@0: // ian@0: // You should have received a copy of the GNU General Public License ian@0: // along with gpsynth in the file COPYING. ian@0: // If not, see http://www.gnu.org/licenses/. ian@0: ian@0: // MFCCAnalyzer - extracts MFCCs from a provided magnitude spectrum ian@0: ian@0: #pragma once ian@0: ian@0: #include "fftw3.h" ian@0: ian@0: #include ian@0: ian@0: namespace dsp { ian@0: ian@0: class MFCCAnalyzer { ian@0: fftw_plan dct_plan_; ian@0: int frame_size_; ian@0: double sample_rate_; ian@0: double frequency_min_; ian@0: double frequency_max_; ian@0: std::vector< std::vector > mel_filters_; ian@0: int mel_bands_; ian@0: int number_of_mfccs_; ian@0: std::vector mfccs_; ian@0: double* mel_bands_dct_in_; ian@0: double* mel_bands_dct_out_; ian@0: ian@0: public: ian@0: MFCCAnalyzer(int frame_size, ian@0: int mel_bands, ian@0: int number_of_mfccs, ian@0: double frequency_min, ian@0: double frequency_max); ian@0: ian@0: ~MFCCAnalyzer(); ian@0: ian@0: void SetSampleRate(double sample_rate); ian@0: ian@0: // extracts mfccs from a magnitude spectrum ian@0: const std::vector& ExtractMFCCS(const std::vector& spectrum); ian@0: ian@0: private: ian@0: void InitializeMelDCT(); ian@0: void InitializeFilters(); ian@0: }; ian@0: ian@0: } // dsp namespace