1 #pragma once
2 
3 #ifndef OPENSHOT_STFT_AUDIO_EFFECT_H
4 #define OPENSHOT_STFT_AUDIO_EFFECT_H
5 #define _USE_MATH_DEFINES
6 
7 #include "../EffectBase.h"
8 #include "../Enums.h"
9 
10 namespace openshot
11 {
12 
13     class STFT
14     {
15     public:
STFT()16         STFT() : num_channels (1) { }
17 
~STFT()18         virtual ~STFT() { }
19 
20         void setup(const int num_input_channels);
21 
22         void process(juce::AudioSampleBuffer &block);
23 
24         void updateParameters(const int new_fft_size, const int new_overlap, const int new_window_type);
25 
26         virtual void updateFftSize(const int new_fft_size);
27 
28         virtual void updateHopSize(const int new_overlap);
29 
30         virtual void updateWindow(const int new_window_type);
31 
32     private:
33 
34         virtual void modification(const int channel);
35 
36         virtual void analysis(const int channel);
37 
38         virtual void synthesis(const int channel);
39 
40     protected:
41         int num_channels;
42         int num_samples;
43 
44         int fft_size;
45         std::unique_ptr<juce::dsp::FFT> fft;
46 
47         int input_buffer_length;
48         juce::AudioSampleBuffer input_buffer;
49 
50         int output_buffer_length;
51         juce::AudioSampleBuffer output_buffer;
52 
53         juce::HeapBlock<float> fft_window;
54         juce::HeapBlock<juce::dsp::Complex<float>> time_domain_buffer;
55         juce::HeapBlock<juce::dsp::Complex<float>> frequency_domain_buffer;
56 
57         int overlap;
58         int hop_size;
59         int window_type;
60         float window_scale_factor;
61 
62         int input_buffer_write_position;
63         int output_buffer_write_position;
64         int output_buffer_read_position;
65         int samples_since_last_FFT;
66 
67         int current_input_buffer_write_position;
68         int current_output_buffer_write_position;
69         int current_output_buffer_read_position;
70         int current_samples_since_last_FFT;
71     };
72 }
73 
74 #endif
75