Sbs2Spectrogram::Sbs2Spectrogram(int length_, QObject *parent) :
    QObject(parent), length(length_)
{
    setWindowType(RECT);
    fft = new FFTReal(length);
    x = new flt_t [length];
    f = new flt_t [length];
}
void Sbs2DataHandler::turnChannelSpectrogramOn(int spectrogramChannelSamples_, int spectrogramChannelLength_, int spectrogramChannelDelta_)
{
    spectrogramChannelSamples = spectrogramChannelSamples_;
    spectrogramChannelLength = spectrogramChannelLength_;
    spectrogramChannelDelta = spectrogramChannelDelta_;
    spectrogramChannelDeltaCollected = 0;

    if (!(toSpectrogramValues == 0))
    {
        delete toSpectrogramValues;
        toSpectrogramValues = 0;
    }
    if (!(spectrogramValues == 0))
    {
        delete spectrogramValues;
        spectrogramValues = 0;
    }
    if (!(powerValues == 0))
    {
        delete powerValues;
        powerValues = 0;
    }
    if (!(sbs2Spectrogram == 0))
    {
        delete sbs2Spectrogram;
        sbs2Spectrogram = 0;
    }

    toSpectrogramValues = new DTU::DtuArray2D<double>(Sbs2Common::channelsNo(),spectrogramChannelSamples);
    spectrogramValues = new DTU::DtuArray2D<double>(Sbs2Common::channelsNo(),spectrogramChannelLength);
    powerValues = new DTU::DtuArray2D<double>(Sbs2Common::channelsNo(),spectrogramChannelLength/2);
    sbs2Spectrogram = new Sbs2Spectrogram(spectrogramChannelLength,this);

    connect(this, SIGNAL(setWindowTypeSignal(Sbs2Spectrogram::WindowType)),
            sbs2Spectrogram, SLOT(setWindowType(Sbs2Spectrogram::WindowType)));

    (*toSpectrogramValues) = 0;
    (*spectrogramValues) = 0;

    spectrogramChannelOn = 1;

}
pdsp::GrainWindow::GrainWindow(){
    
        addInput("signal", input_signal);
        addInput("trig", input_trigger);
        addInput("length", input_length_ms);

        addOutput("signal", output);
        
        updateOutputNodes();

        //interpolatorShell.changeInterpolator(Linear);
        setWindowType(Triangular);
        
        input_length_ms.setDefaultValue(200.0f);

        windowMeter.store(0.0f);
        
        if(dynamicConstruction){
                prepareToPlay(globalBufferSize, globalSampleRate);
        }
}
void ofxFft::setup(int signalSize, fftWindowType windowType) {
	this->signalSize = signalSize;
	this->binSize = (signalSize / 2) + 1;

	signalNormalized = true;
	signal = new float[signalSize];

	cartesianUpdated = true;
	cartesianNormalized = true;
	real = new float[binSize];
	imag = new float[binSize];

	polarUpdated = true;
	polarNormalized = true;
	amplitude = new float[binSize];
	phase = new float[binSize];

	clear();

	window = new float[signalSize];
	inverseWindow = new float[signalSize];
	setWindowType(windowType);
}
pdsp::Patchable& pdsp::GrainWindow::set(float grainLengthMs, Window_t type, int window_length){
    input_length_ms.setDefaultValue(grainLengthMs);  
    setWindowType(type, window_length);
    return *this;
}