package party.bami.eqfix.transientGenerator;

import party.bami.eqfix.analysis.WhiteNoise;

public class TransientGenerator {

    private Envelope e;
    private Generator g;
    private WhiteNoise wn;

    public TransientGenerator(int sampleRate) {
        this.g = new Generator(sampleRate);
        this.e = new Envelope(100, 300, 0 ,0);
        this.wn = new WhiteNoise();
    }

    // generates n number of transients with peaks on the specified interval
    public float[] generate(int n, int interval, float volume) {

        int size = 400 * n + n * interval;
        float[] output = new float[size*2];

        float[] t = e.filter(wn.gen(400));

        float[] part = new float[600 + interval];

        for (int i = 0; i < t.length; i++) {
            part[i] = t[i];
        }

        for (int i = 0; i < output.length; i++) {
            output[i] = part[i % part.length];
        }

        return output;

    }


    /***** GETTERS and SETTERS *****/
    public void setSampleRate(int sampleRate){
        g.setSampleRate(sampleRate);
    }

    public int getSampleRate(){
        return g.getSampleRate();
    }

}
