package com.jsyn.unitgen;

/* JADX INFO: loaded from: classes.dex */
public class c extends t implements w {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public x0.k f3227c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public x0.k f3228d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public x0.k f3229e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public x0.k f3230f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public x0.k f3231g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public x0.k f3232h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public x0.k f3233i;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private double f3235k;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    private double f3237m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    private double f3238n;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private b f3234j = b.IDLE;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    private double f3236l = 1.0d;

    static /* synthetic */ class a {

        /* JADX INFO: renamed from: a, reason: collision with root package name */
        static final /* synthetic */ int[] f3239a;

        static {
            int[] iArr = new int[b.values().length];
            f3239a = iArr;
            try {
                iArr[b.IDLE.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                f3239a[b.DELAYING.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                f3239a[b.ATTACKING.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                f3239a[b.HOLDING.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                f3239a[b.DECAYING.ordinal()] = 5;
            } catch (NoSuchFieldError unused5) {
            }
            try {
                f3239a[b.SUSTAINING.ordinal()] = 6;
            } catch (NoSuchFieldError unused6) {
            }
            try {
                f3239a[b.RELEASING.ordinal()] = 7;
            } catch (NoSuchFieldError unused7) {
            }
        }
    }

    enum b {
        IDLE,
        DELAYING,
        ATTACKING,
        HOLDING,
        DECAYING,
        SUSTAINING,
        RELEASING
    }

    public c() {
        x0.k kVar = new x0.k("Delay", u.FALSE);
        this.f3227c = kVar;
        addPort(kVar);
        this.f3227c.D(u.FALSE, u.FALSE, 2.0d);
        x0.k kVar2 = new x0.k("Attack", 0.1d);
        this.f3228d = kVar2;
        addPort(kVar2);
        this.f3228d.D(0.01d, 0.1d, 8.0d);
        x0.k kVar3 = new x0.k("Hold", u.FALSE);
        this.f3229e = kVar3;
        addPort(kVar3);
        this.f3229e.D(u.FALSE, u.FALSE, 2.0d);
        x0.k kVar4 = new x0.k("Decay", 0.2d);
        this.f3230f = kVar4;
        addPort(kVar4);
        this.f3230f.D(0.01d, 0.2d, 8.0d);
        x0.k kVar5 = new x0.k("Sustain", 0.5d);
        this.f3231g = kVar5;
        addPort(kVar5);
        this.f3231g.D(u.FALSE, 0.5d, 1.0d);
        x0.k kVar6 = new x0.k("Release", 0.3d);
        this.f3232h = kVar6;
        addPort(kVar6);
        this.f3232h.D(0.01d, 0.3d, 8.0d);
        x0.k kVar7 = new x0.k(u.PORT_NAME_AMPLITUDE, 1.0d);
        this.f3233i = kVar7;
        addPort(kVar7);
    }

    private void c(int i2) {
        double d2 = this.f3228d.l()[i2];
        if (d2 < 1.0E-5d) {
            this.f3237m = 1.0d;
            f(i2);
        } else {
            this.f3238n = getFramePeriod() / d2;
            this.f3234j = b.ATTACKING;
        }
    }

    private void d(int i2) {
        double d2 = this.f3230f.l()[i2];
        if (d2 < 1.0E-5d) {
            i(i2);
        } else {
            this.f3236l = getSynthesisEngine().q(d2);
            this.f3234j = b.DECAYING;
        }
    }

    private void e(int i2) {
        if (this.f3227c.l()[i2] <= u.FALSE) {
            c(i2);
        } else {
            this.f3235k = (int) (r1 * ((double) getFrameRate()));
            this.f3234j = b.DELAYING;
        }
    }

    private void f(int i2) {
        if (this.f3229e.l()[i2] <= u.FALSE) {
            d(i2);
        } else {
            this.f3235k = (int) (r1 * ((double) getFrameRate()));
            this.f3234j = b.HOLDING;
        }
    }

    private void g() {
        this.f3234j = b.IDLE;
        this.f3237m = u.FALSE;
    }

    private void h(int i2) {
        double d2 = this.f3232h.l()[i2];
        if (d2 < 1.0E-5d) {
            d2 = 1.0E-5d;
        }
        this.f3236l = getSynthesisEngine().q(d2);
        this.f3234j = b.RELEASING;
    }

    private void i(int i2) {
        this.f3234j = b.SUSTAINING;
    }

    public void b(AbstractC0420b abstractC0420b, String str) {
        abstractC0420b.addPort(this.f3228d, str + this.f3228d.b());
        abstractC0420b.addPort(this.f3230f, str + this.f3230f.b());
        abstractC0420b.addPort(this.f3231g, str + this.f3231g.b());
        abstractC0420b.addPort(this.f3232h, str + this.f3232h.b());
    }

    @Override // com.jsyn.unitgen.u
    public void generate(int i2, int i3) {
        double[] dArrL = this.f3231g.l();
        double[] dArrL2 = this.f3233i.l();
        double[] dArrL3 = this.f3291b.l();
        while (i2 < i3) {
            boolean zH = this.f3290a.H(i2);
            switch (a.f3239a[this.f3234j.ordinal()]) {
                case 1:
                    while (true) {
                        if (i2 < i3) {
                            dArrL3[i2] = this.f3237m * dArrL2[i2];
                            if (zH) {
                                e(i2);
                            } else {
                                i2++;
                            }
                        }
                        break;
                    }
                    break;
                case 2:
                    while (true) {
                        if (i2 < i3) {
                            dArrL3[i2] = this.f3237m * dArrL2[i2];
                            if (this.f3290a.J()) {
                                h(i2);
                            } else {
                                double d2 = this.f3235k - 1.0d;
                                this.f3235k = d2;
                                if (d2 <= u.FALSE) {
                                    c(i2);
                                } else {
                                    i2++;
                                }
                            }
                        }
                        break;
                    }
                    break;
                case 3:
                    while (true) {
                        if (i2 < i3) {
                            double d3 = this.f3237m + this.f3238n;
                            this.f3237m = d3;
                            if (d3 >= 1.0d) {
                                this.f3237m = 1.0d;
                                dArrL3[i2] = 1.0d * dArrL2[i2];
                                f(i2);
                            } else {
                                dArrL3[i2] = d3 * dArrL2[i2];
                                if (this.f3290a.J()) {
                                    h(i2);
                                } else {
                                    i2++;
                                }
                            }
                        }
                        break;
                    }
                    break;
                case 4:
                    while (true) {
                        if (i2 < i3) {
                            dArrL3[i2] = dArrL2[i2];
                            double d4 = this.f3235k - 1.0d;
                            this.f3235k = d4;
                            if (d4 <= u.FALSE) {
                                d(i2);
                            } else if (this.f3290a.J()) {
                                h(i2);
                            } else {
                                i2++;
                            }
                        }
                        break;
                    }
                    break;
                case 5:
                    while (true) {
                        if (i2 < i3) {
                            double d5 = this.f3237m;
                            dArrL3[i2] = dArrL2[i2] * d5;
                            double d6 = d5 * this.f3236l;
                            this.f3237m = d6;
                            if (zH) {
                                e(i2);
                            } else {
                                double d7 = dArrL[i2];
                                if (d6 < d7) {
                                    this.f3237m = d7;
                                    i(i2);
                                } else if (d6 < 1.5848931924611107E-5d) {
                                    this.f3290a.G();
                                    g();
                                } else if (this.f3290a.J()) {
                                    h(i2);
                                } else {
                                    i2++;
                                }
                            }
                        }
                        break;
                    }
                    break;
                case 6:
                    while (true) {
                        if (i2 < i3) {
                            double d8 = dArrL[i2];
                            this.f3237m = d8;
                            dArrL3[i2] = d8 * dArrL2[i2];
                            if (zH) {
                                e(i2);
                            } else if (this.f3290a.J()) {
                                h(i2);
                            } else {
                                i2++;
                            }
                        }
                        break;
                    }
                    break;
                case 7:
                    while (true) {
                        if (i2 < i3) {
                            double d9 = this.f3237m;
                            dArrL3[i2] = dArrL2[i2] * d9;
                            double d10 = d9 * this.f3236l;
                            this.f3237m = d10;
                            if (zH) {
                                e(i2);
                            } else if (d10 < 1.5848931924611107E-5d) {
                                this.f3290a.G();
                                g();
                            } else {
                                i2++;
                            }
                        }
                        break;
                    }
                    break;
            }
        }
    }
}
