package defpackage;

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

/* JADX INFO: renamed from: ˊˋʞ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes3.dex */
public final class C1330 extends AbstractC1776 {

    /* JADX INFO: renamed from: ˉᵲ, reason: contains not printable characters */
    public byte[] f5531;

    /* JADX INFO: renamed from: ˋˈ, reason: contains not printable characters */
    public int f5534;

    /* JADX INFO: renamed from: ˌᴵ, reason: contains not printable characters */
    public byte[] f5535;

    /* JADX INFO: renamed from: ᵟᵹᵙ, reason: contains not printable characters */
    public int f5538;

    /* JADX INFO: renamed from: ᵪᵹᵥᵻ, reason: contains not printable characters */
    public boolean f5539;

    /* JADX INFO: renamed from: ᵱʡˏ, reason: contains not printable characters */
    public long f5541;

    /* JADX INFO: renamed from: ˊᵙᵾᵲ, reason: contains not printable characters */
    public int f5532 = 0;

    /* JADX INFO: renamed from: ˏːˆ, reason: contains not printable characters */
    public int f5536 = 0;

    /* JADX INFO: renamed from: ˊᵨᵧ, reason: contains not printable characters */
    public int f5533 = 0;

    /* JADX INFO: renamed from: ᵮᵣᵗˈ, reason: contains not printable characters */
    public final long f5540 = 100000;

    /* JADX INFO: renamed from: ᵻʽᵯ, reason: contains not printable characters */
    public final float f5544 = 0.2f;

    /* JADX INFO: renamed from: ᵝᵶ, reason: contains not printable characters */
    public final long f5537 = 2000000;

    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public final int f5543 = 10;

    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public final short f5542 = 1024;

    public C1330() {
        byte[] bArr = AbstractC0956.f4216;
        this.f5531 = bArr;
        this.f5535 = bArr;
    }

    /* JADX INFO: renamed from: ˋˈ, reason: contains not printable characters */
    public final int m3846(int i) {
        int length = ((((int) ((this.f5537 * ((long) this.f7116.f11222)) / 1000000)) - this.f5532) * this.f5534) - (this.f5531.length / 2);
        ᵻᵪ.ˌᴵ(length >= 0);
        int iMin = (int) Math.min((i * this.f5544) + 0.5f, length);
        int i2 = this.f5534;
        return (iMin / i2) * i2;
    }

    @Override // defpackage.AbstractC1776, defpackage.InterfaceC2497
    /* JADX INFO: renamed from: ːˏᵟᵯ, reason: contains not printable characters */
    public final boolean mo3847() {
        return super.mo3847() && this.f5539;
    }

    /* JADX INFO: renamed from: ᵟᵹᵙ, reason: contains not printable characters */
    public final void m3848(int i, int i2) {
        if (i == 0) {
            return;
        }
        ᵻᵪ.ᵱᵽʡᵚ(this.f5533 >= i);
        int i3 = this.f5536;
        if (i2 == 2) {
            int i4 = this.f5533;
            int i5 = i3 + i4;
            byte[] bArr = this.f5531;
            if (i5 <= bArr.length) {
                System.arraycopy(bArr, i5 - i, this.f5535, 0, i);
            } else {
                int length = i4 - (bArr.length - i3);
                byte[] bArr2 = this.f5535;
                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.f5531, 0, this.f5535, i6, length);
                }
            }
        } else {
            int i7 = i3 + i;
            byte[] bArr3 = this.f5531;
            int length2 = bArr3.length;
            byte[] bArr4 = this.f5535;
            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.f5531, 0, this.f5535, length3, i - length3);
            }
        }
        ᵻᵪ.ᵻˈᵦʼ(i, "sizeToOutput is not aligned to frame size: %s", i % this.f5534 == 0);
        ᵻᵪ.ˌᴵ(this.f5536 < this.f5531.length);
        byte[] bArr5 = this.f5535;
        ᵻᵪ.ᵻˈᵦʼ(i, "byteOutput size is not aligned to frame size %s", i % this.f5534 == 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.f5543;
                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] = 127;
                } else if (i12 <= -32768) {
                    bArr5[i8] = 0;
                    bArr5[i9] = -128;
                } else {
                    bArr5[i8] = (byte) (i12 & 255);
                    bArr5[i9] = (byte) (i12 >> 8);
                }
            }
        }
        m4910(i).put(bArr5, 0, i).flip();
    }

    /* JADX INFO: renamed from: ᵪᵹᵥᵻ, reason: contains not printable characters */
    public final void m3849(boolean z) {
        int length;
        int iM3846;
        int i = this.f5533;
        byte[] bArr = this.f5531;
        if (i == bArr.length || z) {
            if (this.f5532 == 0) {
                if (z) {
                    m3848(i, 3);
                    length = i;
                } else {
                    ᵻᵪ.ˌᴵ(i >= bArr.length / 2);
                    length = this.f5531.length / 2;
                    m3848(length, 0);
                }
                iM3846 = length;
            } else if (z) {
                int length2 = i - (bArr.length / 2);
                int length3 = (bArr.length / 2) + length2;
                int iM38462 = m3846(length2) + (this.f5531.length / 2);
                m3848(iM38462, 2);
                iM3846 = iM38462;
                length = length3;
            } else {
                length = i - (bArr.length / 2);
                iM3846 = m3846(length);
                m3848(iM3846, 1);
            }
            if (!(length % this.f5534 == 0)) {
                ᵕᵩʽᵲ.ᵪᵹᵥᵻ(ᵱˉˈ.ᵸˆˁ("bytesConsumed is not aligned to frame size: %s", new Object[]{Integer.valueOf(length)}));
                return;
            }
            ᵻᵪ.ˌᴵ(i >= iM3846);
            this.f5533 -= length;
            int i2 = this.f5536 + length;
            this.f5536 = i2;
            this.f5536 = i2 % this.f5531.length;
            int i3 = this.f5532;
            int i4 = this.f5534;
            this.f5532 = (iM3846 / i4) + i3;
            this.f5541 += (long) ((length - iM3846) / i4);
        }
    }

    @Override // defpackage.AbstractC1776
    /* JADX INFO: renamed from: ᵮᵣᵗˈ, reason: contains not printable characters */
    public final void mo3850() {
        this.f5539 = false;
        byte[] bArr = AbstractC0956.f4216;
        this.f5531 = bArr;
        this.f5535 = bArr;
    }

    @Override // defpackage.AbstractC1776
    /* JADX INFO: renamed from: ᵱᵽʡᵚ, reason: contains not printable characters */
    public final void mo3851() {
        if (mo3847()) {
            C2917 c2917 = this.f7116;
            int i = c2917.f11220 * 2;
            this.f5534 = i;
            int i2 = ((((int) ((this.f5540 * ((long) c2917.f11222)) / 1000000)) / 2) / i) * i * 2;
            if (this.f5531.length != i2) {
                this.f5531 = new byte[i2];
                this.f5535 = new byte[i2];
            }
        }
        this.f5538 = 0;
        this.f5541 = 0L;
        this.f5532 = 0;
        this.f5536 = 0;
        this.f5533 = 0;
    }

    @Override // defpackage.AbstractC1776
    /* JADX INFO: renamed from: ᵲᵶᵳˈ */
    public final C2917 mo3788(C2917 c2917) throws AudioProcessor$UnhandledAudioFormatException {
        if (c2917.f11221 == 2) {
            return c2917.f11222 == -1 ? C2917.f11219 : c2917;
        }
        throw new AudioProcessor$UnhandledAudioFormatException(c2917);
    }

    @Override // defpackage.AbstractC1776
    /* JADX INFO: renamed from: ᵶᵥᵝ, reason: contains not printable characters */
    public final void mo3852() {
        if (this.f5533 > 0) {
            m3849(true);
            this.f5532 = 0;
        }
    }

    @Override // defpackage.InterfaceC2497
    /* JADX INFO: renamed from: ᵻˈᵦʼ */
    public final void mo3789(ByteBuffer byteBuffer) {
        int iLimit;
        int iPosition;
        while (byteBuffer.hasRemaining() && !this.f7120.hasRemaining()) {
            int i = this.f5538;
            short s = this.f5542;
            if (i == 0) {
                int iLimit2 = byteBuffer.limit();
                byteBuffer.limit(Math.min(iLimit2, byteBuffer.position() + this.f5531.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.f5534;
                        iPosition = ((iLimit3 / i2) * i2) + i2;
                        break;
                    }
                    iLimit3 -= 2;
                }
                if (iPosition == byteBuffer.position()) {
                    this.f5538 = 1;
                } else {
                    byteBuffer.limit(Math.min(iPosition, byteBuffer.capacity()));
                    m4910(byteBuffer.remaining()).put(byteBuffer).flip();
                }
                byteBuffer.limit(iLimit2);
            } else {
                if (i != 1) {
                    ᵷᵝˎ.ᵱʡˏ();
                    return;
                }
                ᵻᵪ.ˌᴵ(this.f5536 < this.f5531.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.f5534;
                        iLimit = (iPosition2 / i3) * i3;
                        break;
                    }
                    iPosition2 += 2;
                }
                int iPosition3 = iLimit - byteBuffer.position();
                int length = this.f5536;
                int i4 = this.f5533;
                int length2 = length + i4;
                byte[] bArr = this.f5531;
                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.f5531, length2, iMin);
                int i6 = this.f5533 + iMin;
                this.f5533 = i6;
                ᵻᵪ.ˌᴵ(i6 <= this.f5531.length);
                boolean z2 = z && iPosition3 < i5;
                m3849(z2);
                if (z2) {
                    this.f5538 = 0;
                    this.f5532 = 0;
                }
                byteBuffer.limit(iLimit4);
            }
        }
    }
}
