package defpackage;

import androidx.media3.common.audio.AudioProcessor$UnhandledAudioFormatException;
import java.nio.ByteBuffer;

/* renamed from: ᵟʩ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C3016 extends AbstractC3190 {

    /* renamed from: ˌʾˀ, reason: contains not printable characters */
    public int f11611;

    /* renamed from: ᵞʡ, reason: contains not printable characters */
    public byte[] f11615;

    /* renamed from: ᵡʠ, reason: contains not printable characters */
    public long f11616;

    /* renamed from: ᵧᵾˀˈ, reason: contains not printable characters */
    public byte[] f11617;

    /* renamed from: ᵪʩ, reason: contains not printable characters */
    public int f11619;

    /* renamed from: ᵳٴᵶ, reason: contains not printable characters */
    public boolean f11621;

    /* renamed from: ᵸʓᵠ, reason: contains not printable characters */
    public int f11623 = 0;

    /* renamed from: ᵨᵳʝ, reason: contains not printable characters */
    public int f11618 = 0;

    /* renamed from: ˑᵱ, reason: contains not printable characters */
    public int f11613 = 0;

    /* renamed from: ˌᵜᵹᵩ, reason: contains not printable characters */
    public final long f11612 = 100000;

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public final float f11614 = 0.2f;

    /* renamed from: ᵯٴᵦ, reason: contains not printable characters */
    public final long f11620 = 2000000;

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public final int f11624 = 10;

    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public final short f11622 = 1024;

    public C3016() {
        byte[] bArr = AbstractC3558.f13330;
        this.f11615 = bArr;
        this.f11617 = bArr;
    }

    /* renamed from: ˌʾˀ, reason: contains not printable characters */
    public final void m7359(int i, int i2) {
        if (i == 0) {
            return;
        }
        ᵛᵾˏ.ᵯٴᵦ(this.f11613 >= i);
        int i3 = this.f11618;
        if (i2 == 2) {
            int i4 = this.f11613;
            int i5 = i3 + i4;
            byte[] bArr = this.f11615;
            if (i5 <= bArr.length) {
                System.arraycopy(bArr, i5 - i, this.f11617, 0, i);
            } else {
                int length = i4 - (bArr.length - i3);
                byte[] bArr2 = this.f11617;
                if (length >= i) {
                    System.arraycopy(bArr, length - i, bArr2, 0, i);
                } else {
                    int i6 = i - length;
                    System.arraycopy(bArr, bArr.length - i6, bArr2, 0, i6);
                    System.arraycopy(this.f11615, 0, this.f11617, i6, length);
                }
            }
        } else {
            int i7 = i3 + i;
            byte[] bArr3 = this.f11615;
            int length2 = bArr3.length;
            byte[] bArr4 = this.f11617;
            if (i7 <= length2) {
                System.arraycopy(bArr3, i3, bArr4, 0, i);
            } else {
                int length3 = bArr3.length - i3;
                System.arraycopy(bArr3, i3, bArr4, 0, length3);
                System.arraycopy(this.f11615, 0, this.f11617, length3, i - length3);
            }
        }
        ᵛᵾˏ.ᵶᵷᵕ(i, "sizeToOutput is not aligned to frame size: %s", i % this.f11619 == 0);
        ᵛᵾˏ.ᵿʗᵝʽ(this.f11618 < this.f11615.length);
        byte[] bArr5 = this.f11617;
        ᵛᵾˏ.ᵶᵷᵕ(i, "byteOutput size is not aligned to frame size %s", i % this.f11619 == 0);
        if (i2 != 3) {
            for (int i8 = 0; i8 < i; i8 += 2) {
                int i9 = i8 + 1;
                int i10 = (bArr5[i9] << 8) | (bArr5[i8] & 255);
                int i11 = this.f11624;
                if (i2 == 0) {
                    i11 = ((((i8 * 1000) / (i - 1)) * (i11 - 100)) / 1000) + 100;
                } else if (i2 == 2) {
                    i11 += (((i8 * 1000) * (100 - i11)) / (i - 1)) / 1000;
                }
                int i12 = (i10 * i11) / 100;
                if (i12 >= 32767) {
                    bArr5[i8] = -1;
                    bArr5[i9] = Byte.MAX_VALUE;
                } else if (i12 <= -32768) {
                    bArr5[i8] = 0;
                    bArr5[i9] = Byte.MIN_VALUE;
                } else {
                    bArr5[i8] = (byte) (i12 & 255);
                    bArr5[i9] = (byte) (i12 >> 8);
                }
            }
        }
        m7540(i).put(bArr5, 0, i).flip();
    }

    @Override // defpackage.AbstractC3190
    /* renamed from: ˌᵜᵹᵩ, reason: contains not printable characters */
    public final void mo7360() {
        this.f11621 = false;
        byte[] bArr = AbstractC3558.f13330;
        this.f11615 = bArr;
        this.f11617 = bArr;
    }

    @Override // defpackage.InterfaceC0240
    /* renamed from: ˏˋٴ */
    public final void mo1540(ByteBuffer byteBuffer) {
        int iLimit;
        int iPosition;
        while (byteBuffer.hasRemaining() && !this.f12079.hasRemaining()) {
            int i = this.f11611;
            short s = this.f11622;
            if (i == 0) {
                int iLimit2 = byteBuffer.limit();
                byteBuffer.limit(Math.min(iLimit2, byteBuffer.position() + this.f11615.length));
                int iLimit3 = byteBuffer.limit() - 1;
                while (true) {
                    if (iLimit3 < byteBuffer.position()) {
                        iPosition = byteBuffer.position();
                        break;
                    }
                    if (Math.abs((byteBuffer.get(iLimit3) << 8) | (byteBuffer.get(iLimit3 - 1) & 255)) > s) {
                        int i2 = this.f11619;
                        iPosition = ((iLimit3 / i2) * i2) + i2;
                        break;
                    }
                    iLimit3 -= 2;
                }
                if (iPosition == byteBuffer.position()) {
                    this.f11611 = 1;
                } else {
                    byteBuffer.limit(Math.min(iPosition, byteBuffer.capacity()));
                    m7540(byteBuffer.remaining()).put(byteBuffer).flip();
                }
                byteBuffer.limit(iLimit2);
            } else {
                if (i != 1) {
                    ᵨᴵᵺ.ˌʾˀ();
                    return;
                }
                ᵛᵾˏ.ᵿʗᵝʽ(this.f11618 < this.f11615.length);
                int iLimit4 = byteBuffer.limit();
                int iPosition2 = byteBuffer.position() + 1;
                while (true) {
                    if (iPosition2 >= byteBuffer.limit()) {
                        iLimit = byteBuffer.limit();
                        break;
                    }
                    if (Math.abs((byteBuffer.get(iPosition2) << 8) | (byteBuffer.get(iPosition2 - 1) & 255)) > s) {
                        int i3 = this.f11619;
                        iLimit = (iPosition2 / i3) * i3;
                        break;
                    }
                    iPosition2 += 2;
                }
                int iPosition3 = iLimit - byteBuffer.position();
                int length = this.f11618;
                int i4 = this.f11613;
                int length2 = length + i4;
                byte[] bArr = this.f11615;
                if (length2 < bArr.length) {
                    length = bArr.length;
                } else {
                    length2 = i4 - (bArr.length - length);
                }
                int i5 = length - length2;
                boolean z = iLimit < iLimit4;
                int iMin = Math.min(iPosition3, i5);
                byteBuffer.limit(byteBuffer.position() + iMin);
                byteBuffer.get(this.f11615, length2, iMin);
                int i6 = this.f11613 + iMin;
                this.f11613 = i6;
                ᵛᵾˏ.ᵿʗᵝʽ(i6 <= this.f11615.length);
                boolean z2 = z && iPosition3 < i5;
                m7362(z2);
                if (z2) {
                    this.f11611 = 0;
                    this.f11623 = 0;
                }
                byteBuffer.limit(iLimit4);
            }
        }
    }

    @Override // defpackage.AbstractC3190, defpackage.InterfaceC0240
    /* renamed from: ˏᵙ */
    public final boolean mo1541() {
        return super.mo1541() && this.f11621;
    }

    @Override // defpackage.AbstractC3190
    /* renamed from: ᵥᵯˎ */
    public final C2263 mo2173(C2263 c2263) throws AudioProcessor$UnhandledAudioFormatException {
        if (c2263.f8839 == 2) {
            return c2263.f8840 == -1 ? C2263.f8838 : c2263;
        }
        throw new AudioProcessor$UnhandledAudioFormatException(c2263);
    }

    /* renamed from: ᵪʩ, reason: contains not printable characters */
    public final int m7361(int i) {
        int length = ((((int) ((this.f11620 * this.f12082.f8840) / 1000000)) - this.f11623) * this.f11619) - (this.f11615.length / 2);
        ᵛᵾˏ.ᵿʗᵝʽ(length >= 0);
        int iMin = (int) Math.min((i * this.f11614) + 0.5f, length);
        int i2 = this.f11619;
        return (iMin / i2) * i2;
    }

    /* renamed from: ᵳٴᵶ, reason: contains not printable characters */
    public final void m7362(boolean z) {
        int length;
        int iM7361;
        int i = this.f11613;
        byte[] bArr = this.f11615;
        if (i == bArr.length || z) {
            if (this.f11623 == 0) {
                if (z) {
                    m7359(i, 3);
                    length = i;
                } else {
                    ᵛᵾˏ.ᵿʗᵝʽ(i >= bArr.length / 2);
                    length = this.f11615.length / 2;
                    m7359(length, 0);
                }
                iM7361 = length;
            } else if (z) {
                int length2 = i - (bArr.length / 2);
                int length3 = (bArr.length / 2) + length2;
                int iM73612 = m7361(length2) + (this.f11615.length / 2);
                m7359(iM73612, 2);
                iM7361 = iM73612;
                length = length3;
            } else {
                length = i - (bArr.length / 2);
                iM7361 = m7361(length);
                m7359(iM7361, 1);
            }
            if (!(length % this.f11619 == 0)) {
                ᵹˉᵞ.ᵳٴᵶ(ˊˉʤﹳ.ˁˑᵰ("bytesConsumed is not aligned to frame size: %s", new Object[]{Integer.valueOf(length)}));
                return;
            }
            ᵛᵾˏ.ᵿʗᵝʽ(i >= iM7361);
            this.f11613 -= length;
            int i2 = this.f11618 + length;
            this.f11618 = i2;
            this.f11618 = i2 % this.f11615.length;
            this.f11623 = (iM7361 / this.f11619) + this.f11623;
            this.f11616 += (length - iM7361) / r2;
        }
    }

    @Override // defpackage.AbstractC3190
    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public final void mo7363() {
        if (mo1541()) {
            int i = this.f12082.f8841 * 2;
            this.f11619 = i;
            int i2 = ((((int) ((this.f11612 * r0.f8840) / 1000000)) / 2) / i) * i * 2;
            if (this.f11615.length != i2) {
                this.f11615 = new byte[i2];
                this.f11617 = new byte[i2];
            }
        }
        this.f11611 = 0;
        this.f11616 = 0L;
        this.f11623 = 0;
        this.f11618 = 0;
        this.f11613 = 0;
    }

    @Override // defpackage.AbstractC3190
    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public final void mo7364() {
        if (this.f11613 > 0) {
            m7362(true);
            this.f11623 = 0;
        }
    }
}
