Mercurial > hg > gpsynth
view src/feature_extractor.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/. // FeatureExtractor - responsible for managing the retrieval of features from // audio data. Caches feature data to avoid recalculations when accessing // different features that have the same dependencies. #pragma once #include "mfcc_analyzer.hpp" #include "spectrum_analyzer.hpp" #include <complex> #include <vector> namespace dsp { typedef double Value; typedef std::vector<Value> ValueList; typedef std::complex<Value> ComplexValue; typedef std::vector<ComplexValue> ComplexValueList; class FeatureExtractor { std::string file_path_; ValueList window_; ValueList frame_; ValueList file_data_; ValueList bin_frequencies_; Value bin_size_; std::vector<ComplexValueList> spectrum_; std::vector<ValueList> magnitude_spectrum_; std::vector<ValueList> log_magnitude_spectrum_; std::vector<ValueList> mfccs_; std::vector<ValueList> delta_mfccs_; std::vector<ValueList> double_delta_mfccs_; std::vector<ValueList> spectral_flux_; ValueList pitch_; ValueList spectral_centroid_; ValueList spectral_spread_; ValueList energy_; int frames_; int window_size_; int hop_size_; Value sample_rate_; dsp::SpectrumAnalyzer spectrum_analyzer_; dsp::MFCCAnalyzer mfcc_analyzer_; public: FeatureExtractor(const std::string& file_path = "", int frame_size = 2048, int hop_size = 512); void LoadFile(const std::string& file_path); void ClearCaches(); int Frames() const { return frames_; } int WindowSize() const { return window_size_; } int HopSize() const { return hop_size_; } void SetWindowSize(int window_size); void SetHopSize(int hop_size); Value Duration() const; const std::vector<ComplexValueList>& Spectrum(); const std::vector<ValueList>& MagnitudeSpectrum(); const std::vector<ValueList>& LogMagnitudeSpectrum(); const ValueList& Pitch(); const ValueList& SpectralCentroid(); const ValueList& SpectralSpread(); const std::vector<ValueList>& SpectralFlux(); const ValueList& Energy(); const std::vector<ValueList>& MFCCs(); const std::vector<ValueList>& DeltaMFCCs(); const std::vector<ValueList>& DoubleDeltaMFCCs(); private: void GenerateWindow(); }; } // dsp namespace