package v0;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.ShortBuffer;
import x0.AbstractC1709a;

/* JADX INFO: loaded from: classes.dex */
public final class j implements InterfaceC1668g {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public int f18050b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public float f18051c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public float f18052d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public C1666e f18053e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public C1666e f18054f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public C1666e f18055g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public C1666e f18056h;
    public boolean i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public i f18057j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public ByteBuffer f18058k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public ShortBuffer f18059l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public ByteBuffer f18060m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public long f18061n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public long f18062o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public boolean f18063p;

    @Override // v0.InterfaceC1668g
    public final boolean a() {
        if (this.f18054f.f18016a != -1) {
            return Math.abs(this.f18051c - 1.0f) >= 1.0E-4f || Math.abs(this.f18052d - 1.0f) >= 1.0E-4f || this.f18054f.f18016a != this.f18053e.f18016a;
        }
        return false;
    }

    @Override // v0.InterfaceC1668g
    public final ByteBuffer b() {
        i iVar = this.f18057j;
        if (iVar != null) {
            AbstractC1709a.j(iVar.f18039m >= 0);
            int i = iVar.f18039m;
            int i5 = iVar.f18029b;
            int i8 = i * i5 * 2;
            if (i8 > 0) {
                if (this.f18058k.capacity() < i8) {
                    ByteBuffer byteBufferOrder = ByteBuffer.allocateDirect(i8).order(ByteOrder.nativeOrder());
                    this.f18058k = byteBufferOrder;
                    this.f18059l = byteBufferOrder.asShortBuffer();
                } else {
                    this.f18058k.clear();
                    this.f18059l.clear();
                }
                ShortBuffer shortBuffer = this.f18059l;
                AbstractC1709a.j(iVar.f18039m >= 0);
                int iMin = Math.min(shortBuffer.remaining() / i5, iVar.f18039m);
                int i9 = iMin * i5;
                shortBuffer.put(iVar.f18038l, 0, i9);
                int i10 = iVar.f18039m - iMin;
                iVar.f18039m = i10;
                short[] sArr = iVar.f18038l;
                System.arraycopy(sArr, i9, sArr, 0, i10 * i5);
                this.f18062o += (long) i8;
                this.f18058k.limit(i8);
                this.f18060m = this.f18058k;
            }
        }
        ByteBuffer byteBuffer = this.f18060m;
        this.f18060m = InterfaceC1668g.f18020a;
        return byteBuffer;
    }

    @Override // v0.InterfaceC1668g
    public final void c() {
        i iVar = this.f18057j;
        if (iVar != null) {
            int i = iVar.f18037k;
            float f3 = iVar.f18030c;
            float f7 = iVar.f18031d;
            double d8 = f3 / f7;
            double d9 = iVar.f18032e * f7;
            int i5 = iVar.f18044r;
            int i8 = iVar.f18039m + ((int) ((((((((double) (i - i5)) / d8) + ((double) i5)) + iVar.f18049w) + ((double) iVar.f18041o)) / d9) + 0.5d));
            iVar.f18049w = 0.0d;
            short[] sArr = iVar.f18036j;
            int i9 = iVar.f18035h * 2;
            iVar.f18036j = iVar.c(sArr, i, i9 + i);
            int i10 = 0;
            while (true) {
                int i11 = iVar.f18029b;
                if (i10 >= i9 * i11) {
                    break;
                }
                iVar.f18036j[(i11 * i) + i10] = 0;
                i10++;
            }
            iVar.f18037k = i9 + iVar.f18037k;
            iVar.f();
            if (iVar.f18039m > i8) {
                iVar.f18039m = Math.max(i8, 0);
            }
            iVar.f18037k = 0;
            iVar.f18044r = 0;
            iVar.f18041o = 0;
        }
        this.f18063p = true;
    }

    @Override // v0.InterfaceC1668g
    public final boolean d() {
        if (this.f18063p) {
            i iVar = this.f18057j;
            if (iVar != null) {
                AbstractC1709a.j(iVar.f18039m >= 0);
                if (iVar.f18039m * iVar.f18029b * 2 == 0) {
                }
            }
            return true;
        }
        return false;
    }

    @Override // v0.InterfaceC1668g
    public final void e(ByteBuffer byteBuffer) {
        if (byteBuffer.hasRemaining()) {
            i iVar = this.f18057j;
            iVar.getClass();
            ShortBuffer shortBufferAsShortBuffer = byteBuffer.asShortBuffer();
            int iRemaining = byteBuffer.remaining();
            this.f18061n += (long) iRemaining;
            int iRemaining2 = shortBufferAsShortBuffer.remaining();
            int i = iVar.f18029b;
            int i5 = iRemaining2 / i;
            short[] sArrC = iVar.c(iVar.f18036j, iVar.f18037k, i5);
            iVar.f18036j = sArrC;
            shortBufferAsShortBuffer.get(sArrC, iVar.f18037k * i, ((i5 * i) * 2) / 2);
            iVar.f18037k += i5;
            iVar.f();
            byteBuffer.position(byteBuffer.position() + iRemaining);
        }
    }

    @Override // v0.InterfaceC1668g
    public final C1666e f(C1666e c1666e) throws C1667f {
        if (c1666e.f18018c != 2) {
            throw new C1667f(c1666e);
        }
        int i = this.f18050b;
        if (i == -1) {
            i = c1666e.f18016a;
        }
        this.f18053e = c1666e;
        C1666e c1666e2 = new C1666e(i, c1666e.f18017b, 2);
        this.f18054f = c1666e2;
        this.i = true;
        return c1666e2;
    }

    @Override // v0.InterfaceC1668g
    public final void flush() {
        if (a()) {
            C1666e c1666e = this.f18053e;
            this.f18055g = c1666e;
            C1666e c1666e2 = this.f18054f;
            this.f18056h = c1666e2;
            if (this.i) {
                this.f18057j = new i(c1666e.f18016a, c1666e.f18017b, this.f18051c, this.f18052d, c1666e2.f18016a);
            } else {
                i iVar = this.f18057j;
                if (iVar != null) {
                    iVar.f18037k = 0;
                    iVar.f18039m = 0;
                    iVar.f18041o = 0;
                    iVar.f18042p = 0;
                    iVar.f18043q = 0;
                    iVar.f18044r = 0;
                    iVar.f18045s = 0;
                    iVar.f18046t = 0;
                    iVar.f18047u = 0;
                    iVar.f18048v = 0;
                    iVar.f18049w = 0.0d;
                }
            }
        }
        this.f18060m = InterfaceC1668g.f18020a;
        this.f18061n = 0L;
        this.f18062o = 0L;
        this.f18063p = false;
    }

    @Override // v0.InterfaceC1668g
    public final void reset() {
        this.f18051c = 1.0f;
        this.f18052d = 1.0f;
        C1666e c1666e = C1666e.f18015e;
        this.f18053e = c1666e;
        this.f18054f = c1666e;
        this.f18055g = c1666e;
        this.f18056h = c1666e;
        ByteBuffer byteBuffer = InterfaceC1668g.f18020a;
        this.f18058k = byteBuffer;
        this.f18059l = byteBuffer.asShortBuffer();
        this.f18060m = byteBuffer;
        this.f18050b = -1;
        this.i = false;
        this.f18057j = null;
        this.f18061n = 0L;
        this.f18062o = 0L;
        this.f18063p = false;
    }
}
