package party.bami.eqfix.transientGenerator;

// this class creates a basic envelope filter used for transient generation
public class Envelope {

    // adsr times in samples
    private int attack, decay, sustain, release;

    public Envelope(int attack, int decay, int sustain, int release) {
        this.attack = attack;
        this.decay = decay;
        this.sustain = sustain;
        this.release = release;
    }

    // apply the envelope filter
    public float[] filter(float[] input) {
        float[] output = new float[input.length];

        // apply attack
        for (int i = 0; i < attack; i++) {
            float factor = (float) i / (float)attack;
            output[i] = factor * input[i];
        }

        // apply decay
        for (int i = 0; i < decay; i++) {
            float factor = 1f - ((float) i / (float)decay);
            output[i + attack] = factor * input[i + attack];
        }

//        for (int i = 0; i < output.length - decay - attack; i++) {
//            output
//        }

        return output;

    }

    /******* GETTERS and SETTERS *******/
    public void setAttack(int attack) {
        this.attack = attack;
    }

    public int getAttack() {
        return attack;
    }

    public void setDecay(int decay) {
        this.decay = decay;
    }

    public int getDecay() {
        return decay;
    }

    public void setRelease(int release) {
        this.release = release;
    }

    public int getRelease() {
        return release;
    }

    public void setSustain(int sustain) {
        this.sustain = sustain;
    }

    public int getSustain() {
        return sustain;
    }
}
