view AddressPlugin/PluginProcessor.h @ 1:d8c7b69cb4c9

(none)
author Yannick JACOB <y.jacob@se12.qmul.ac.uk>
date Tue, 03 Sep 2013 15:32:51 +0100
parents 2cd427e000b0
children
line wrap: on
line source
/*
  ==============================================================================

    This file was auto-generated!

    It contains the basic startup code for a Juce application.

  ==============================================================================
*/

#ifndef __PLUGINPROCESSOR_H_4693CB6E__
#define __PLUGINPROCESSOR_H_4693CB6E__

#include "../JuceLibraryCode/JuceHeader.h"
#include <fftw3.h>
#include <complex>
//==============================================================================
/**
*/
class ADRessAudioProcessor  : public AudioProcessor
{
public:
    //==============================================================================
    ADRessAudioProcessor();
    ~ADRessAudioProcessor();

    //==============================================================================
    void prepareToPlay (double sampleRate, int samplesPerBlock);
    void releaseResources();


    void processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages);

    //==============================================================================
    AudioProcessorEditor* createEditor();
    bool hasEditor() const;

    //==============================================================================
    const String getName() const;

    int getNumParameters();

    float getParameter (int index);
    void setParameter (int index, float newValue);

    const String getParameterName (int index);
    const String getParameterText (int index);

    const String getInputChannelName (int channelIndex) const;
    const String getOutputChannelName (int channelIndex) const;
    bool isInputChannelStereoPair (int index) const;
    bool isOutputChannelStereoPair (int index) const;

    bool silenceInProducesSilenceOut() const;
    bool acceptsMidi() const;
    bool producesMidi() const;
    
    double getTailLengthSeconds() const;

    //==============================================================================
    int getNumPrograms();
    int getCurrentProgram();
    void setCurrentProgram (int index);
    const String getProgramName (int index);
    void changeProgramName (int index, const String& newName);

    //==============================================================================
    void getStateInformation (MemoryBlock& destData);
    void setStateInformation (const void* data, int sizeInBytes);
    
    //==============================================================================
    
    // these are used to persist the UI's size - the values are stored along with the
    // filter's other parameters, and the UI component will update them when it gets
    // resized.
    int lastUIWidth_, lastUIHeight_;
    
    enum Parameters
    {
        kFFTSizeParam = 0,
        kHopSizeParam,
        kWindowTypeParam,
		kWidthParam,
		kAzimuthParam,
        kNumParameters
    };
    
    enum Window
    {
        kWindowRectangular = 1,
        kWindowBartlett,
        kWindowHann,
        kWindowHamming
    };
    
    enum HopSize
    {
        kHopSize1Window = 1,
        kHopSize1_2Window,
        kHopSize1_4Window,
        kHopSize1_8Window
    };
    
    // This parameter indicates the FFT size for phase vocoder computation. It is selected
    // by the GUI and may temporarily differ from the actual size used in calculations.
    int fftSelectedSize_;
    int hopSelectedSize_;       // Hop size, chosen from one of the options above
    int windowType_;            // Type of window used
    
	int /*indL_, indR_,*/ width_, azimuth_, beta_;
	int indMinL_,indMinR_,indMaxL_,indMaxR_;
	float invGain_;

	bool computeR_, computeL_;
	float invBeta_;
	std::complex<double> i1;

private:

	double azr_[2049][11];
	double azl_[2049][11];
	double realR_[2049];
	double imagR_[2049];
	double realL_[2049];
	double imagL_[2049];

    // Methods to initialise and de-initialise the FFT machinery
    void initFFT(int length);
    void deinitFFT();
    
    // Methods to initialise and de-initialise the window
    void initWindow(int length, int windowType);
    void deinitWindow();
    
    // Methods to update the buffering for the given hop size and the output scaling
    void updateHopSize();
    void updateScaleFactor();
    
    // Whether the FFT has been initialised and is therefore ready to go
    bool fftInitialised_;
    
    // Variables for calculating the FFT and IFFT: complex data structures and the
    // "plan" used by the fftw library to calculate the transforms.
    fftw_complex *fftTimeDomain_, *fftFrequencyDomain_;
    fftw_plan fftForwardPlan_, fftBackwardPlan_;
    
    // Size of the FFT (generally a power of two) and the hop size (in samples, generally a fraction of FFT size)
    int fftActualTransformSize_;
    int hopActualSize_;
    
    // Amount by which to scale_ the inverse FFT to return to original amplitude: depends on the
    // transform size (because of fftw implementation) and the hop size (because of inherent overlap)
    double fftScaleFactor_;
    
    // Circular buffer gathers audio samples from the input until enough are available
    // for the FFT calculation
    AudioSampleBuffer inputBuffer_;
    int inputBufferLength_;
    int inputBufferWritePosition_;
    
    // Circular buffer that collects output samples from the FFT overlap-add process
    // before they are ready to be sent to the output stream
    AudioSampleBuffer outputBuffer_;
    int outputBufferLength_;
    int outputBufferReadPosition_, outputBufferWritePosition_;
    
    // How many samples since the last FFT?
    int samplesSinceLastFFT_;
    
    // Stored window function for pre-processing input frames
    double *windowBuffer_;
    int windowBufferLength_;
    
    // Whether or not prepareToPlay() has been called, i.e. that resources are in use
    bool preparedToPlay_;
    
    // Spin lock that prevents the FFT settings from changing in the middle of the audio
    // thread.
    SpinLock fftSpinLock_;

	void changeParams();
    
    //==============================================================================
    JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ADRessAudioProcessor);
};

#endif  // __PLUGINPROCESSOR_H_4693CB6E__