view src/mfcc_analyzer.hpp @ 0:add35537fdbb tip

Initial import
author irh <ian.r.hobson@gmail.com>
date Thu, 25 Aug 2011 11:05:55 +0100
parents
children
line wrap: on
line source
//  Copyright 2011, Ian Hobson.
//
//  This file is part of gpsynth.
//
//  gpsynth is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  gpsynth is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with gpsynth in the file COPYING. 
//  If not, see http://www.gnu.org/licenses/.

// MFCCAnalyzer - extracts MFCCs from a provided magnitude spectrum

#pragma once

#include "fftw3.h"

#include <vector>

namespace dsp {

class MFCCAnalyzer {  
  fftw_plan dct_plan_;
  int frame_size_;
  double sample_rate_;
  double frequency_min_;
  double frequency_max_;
  std::vector< std::vector<double> > mel_filters_;
  int mel_bands_;
  int number_of_mfccs_;
  std::vector<double> mfccs_;
  double* mel_bands_dct_in_;
  double* mel_bands_dct_out_;
  
public:
  MFCCAnalyzer(int frame_size,
               int mel_bands,
               int number_of_mfccs,
               double frequency_min,
               double frequency_max);
  
  ~MFCCAnalyzer();
  
  void SetSampleRate(double sample_rate);
  
  // extracts mfccs from a magnitude spectrum
  const std::vector<double>& ExtractMFCCS(const std::vector<double>& spectrum);
  
private:
  void InitializeMelDCT();
  void InitializeFilters();  
};

} // dsp namespace