spek

Acoustic spectrum analyser https://github.com/alexkay/spek spek.cc
git clone http://git.hanabi.in/repos/spek.git
Log | Files | Refs | README

spek-fft.h (1184B)


      1 #pragma once
      2 
      3 #include <memory>
      4 #include <vector>
      5 
      6 extern "C" {
      7 #include <libavutil/mem.h>
      8 }
      9 
     10 
     11 class FFTPlan;
     12 
     13 class FFT
     14 {
     15 public:
     16     FFT() {}
     17     std::unique_ptr<FFTPlan> create(int nbits);
     18 };
     19 
     20 class FFTPlan
     21 {
     22 public:
     23     FFTPlan(int nbits) :
     24         input_size(1 << nbits), output_size((1 << (nbits - 1)) + 1),
     25         output(output_size)
     26     {
     27         // FFmpeg uses various assembly optimizations which expect
     28         // input data to be aligned by up to 32 bytes (e.g. AVX)
     29         this->input = (float*) av_malloc(sizeof(float) * input_size);
     30     }
     31 
     32     virtual ~FFTPlan()
     33     {
     34         av_freep(&this->input);
     35     }
     36 
     37     int get_input_size() const { return this->input_size; }
     38     int get_output_size() const { return this->output_size; }
     39     float get_input(int i) const { return this->input[i]; }
     40     void set_input(int i, float v) { this->input[i] = v; }
     41     float get_output(int i) const { return this->output[i]; }
     42     void set_output(int i, float v) { this->output[i] = v; }
     43 
     44     virtual void execute() = 0;
     45 
     46 protected:
     47     float *get_input() { return this->input; }
     48 
     49 private:
     50     int input_size;
     51     int output_size;
     52     float *input;
     53     std::vector<float> output;
     54 };