samplebrain/brain/src/block.h

92 lines
2.5 KiB
C
Raw Normal View History

2022-09-08 08:21:53 -03:00
// Copyright (C) 2022 Then Try This
2015-07-21 10:58:13 -03:00
//
// This program 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 2 of the License, or
// (at your option) any later version.
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2015-07-09 17:50:03 -03:00
#include <string>
#include <vector>
2022-09-04 07:38:20 -03:00
#include "spiralcore/sample.h"
#include "spiralcore/types.h"
2015-07-09 17:50:03 -03:00
#include "fft.h"
#include "mfcc.h"
2015-07-11 08:29:51 -03:00
#include "search_params.h"
2015-07-18 20:34:56 -03:00
#include "window.h"
2022-09-04 07:38:20 -03:00
#include "spiralcore/stream.h"
2015-07-09 17:50:03 -03:00
#ifndef BLOCK
#define BLOCK
namespace spiralcore {
2015-09-23 14:35:13 -03:00
class block {
public:
2015-07-09 17:50:03 -03:00
// runs analysis on pcm
block(u64 id, const std::string &filename, const sample &pcm, u32 rate, const window &w, bool ditchpcm=false);
2015-08-03 05:18:20 -03:00
block() {}
2015-07-09 17:50:03 -03:00
// returns distance based on ratio of fft-mfcc values
2015-07-11 08:29:51 -03:00
double compare(const block &other, const search_params &params) const;
2015-07-09 17:50:03 -03:00
static void init_fft(u32 block_size, u32 rate);
2015-07-09 17:50:03 -03:00
static bool unit_test();
const sample &get_pcm() const { return m_pcm; }
const sample &get_n_pcm() const { return m_n_pcm; }
2015-07-09 17:50:03 -03:00
std::vector<u32> &get_synapse() { return m_synapse; }
const std::vector<u32> &get_synapse_const() const { return m_synapse; }
float &get_usage() { return m_usage; }
2015-09-23 14:35:13 -03:00
float get_freq() const { return m_dominant_freq; }
float get_n_freq() const { return m_n_dominant_freq; }
2015-09-23 14:35:13 -03:00
private:
2015-07-21 14:13:39 -03:00
2015-09-23 14:35:13 -03:00
void process(const sample &pcm, sample &fft, sample &mfcc, float &freq);
2015-07-21 14:13:39 -03:00
double _compare(const sample &fft_a, const sample &mfcc_a,
const sample &fft_b, const sample &mfcc_b,
const search_params &params) const;
u64 m_id;
2015-07-09 17:50:03 -03:00
sample m_pcm;
sample m_fft;
sample m_mfcc;
2015-07-21 14:13:39 -03:00
sample m_n_pcm;
sample m_n_fft;
sample m_n_mfcc;
2015-07-09 17:50:03 -03:00
u32 m_block_size;
u32 m_rate;
std::string m_orig_filename;
static FFT *m_fftw;
static Aquila::Mfcc *m_mfcc_proc;
std::vector<u32> m_synapse;
float m_usage;
2015-09-23 14:35:13 -03:00
float m_dominant_freq;
float m_n_dominant_freq;
2015-08-03 05:18:20 -03:00
friend ios &operator||(ios &s, block &b);
2015-09-23 14:35:13 -03:00
};
2015-07-09 17:50:03 -03:00
2015-09-23 14:35:13 -03:00
ios &operator||(ios &s, block &b);
2015-08-03 05:18:20 -03:00
2015-07-09 17:50:03 -03:00
}
#endif