package c.i.a.c.v1; import androidx.annotation.Nullable; import com.google.android.exoplayer2.audio.AudioProcessor; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.ShortBuffer; import java.util.Objects; /* compiled from: SonicAudioProcessor */ public final class d0 implements AudioProcessor { public int b; /* renamed from: c reason: collision with root package name */ public float f985c = 1.0f; public float d = 1.0f; public AudioProcessor.a e; public AudioProcessor.a f; public AudioProcessor.a g; public AudioProcessor.a h; public boolean i; @Nullable public c0 j; public ByteBuffer k; public ShortBuffer l; public ByteBuffer m; public long n; public long o; public boolean p; public d0() { AudioProcessor.a aVar = AudioProcessor.a.a; this.e = aVar; this.f = aVar; this.g = aVar; this.h = aVar; ByteBuffer byteBuffer = AudioProcessor.a; this.k = byteBuffer; this.l = byteBuffer.asShortBuffer(); this.m = byteBuffer; this.b = -1; } @Override // com.google.android.exoplayer2.audio.AudioProcessor public boolean a() { return this.f.b != -1 && (Math.abs(this.f985c - 1.0f) >= 1.0E-4f || Math.abs(this.d - 1.0f) >= 1.0E-4f || this.f.b != this.e.b); } @Override // com.google.android.exoplayer2.audio.AudioProcessor public boolean b() { c0 c0Var; return this.p && ((c0Var = this.j) == null || (c0Var.m * c0Var.b) * 2 == 0); } @Override // com.google.android.exoplayer2.audio.AudioProcessor public void c(ByteBuffer byteBuffer) { if (byteBuffer.hasRemaining()) { c0 c0Var = this.j; Objects.requireNonNull(c0Var); ShortBuffer asShortBuffer = byteBuffer.asShortBuffer(); int remaining = byteBuffer.remaining(); this.n += (long) remaining; int remaining2 = asShortBuffer.remaining(); int i = c0Var.b; int i2 = remaining2 / i; short[] c2 = c0Var.c(c0Var.j, c0Var.k, i2); c0Var.j = c2; asShortBuffer.get(c2, c0Var.k * c0Var.b, ((i * i2) * 2) / 2); c0Var.k += i2; c0Var.f(); byteBuffer.position(byteBuffer.position() + remaining); } } @Override // com.google.android.exoplayer2.audio.AudioProcessor public AudioProcessor.a d(AudioProcessor.a aVar) throws AudioProcessor.UnhandledAudioFormatException { if (aVar.d == 2) { int i = this.b; if (i == -1) { i = aVar.b; } this.e = aVar; AudioProcessor.a aVar2 = new AudioProcessor.a(i, aVar.f2202c, 2); this.f = aVar2; this.i = true; return aVar2; } throw new AudioProcessor.UnhandledAudioFormatException(aVar); } @Override // com.google.android.exoplayer2.audio.AudioProcessor public void e() { int i; c0 c0Var = this.j; if (c0Var != null) { int i2 = c0Var.k; float f = c0Var.f983c; float f2 = c0Var.d; float f3 = c0Var.e * f2; int i3 = c0Var.m + ((int) ((((((float) i2) / (f / f2)) + ((float) c0Var.o)) / f3) + 0.5f)); c0Var.j = c0Var.c(c0Var.j, i2, (c0Var.h * 2) + i2); int i4 = 0; while (true) { i = c0Var.h * 2; int i5 = c0Var.b; if (i4 >= i * i5) { break; } c0Var.j[(i5 * i2) + i4] = 0; i4++; } c0Var.k = i + c0Var.k; c0Var.f(); if (c0Var.m > i3) { c0Var.m = i3; } c0Var.k = 0; c0Var.r = 0; c0Var.o = 0; } this.p = true; } @Override // com.google.android.exoplayer2.audio.AudioProcessor public void flush() { if (a()) { AudioProcessor.a aVar = this.e; this.g = aVar; AudioProcessor.a aVar2 = this.f; this.h = aVar2; if (this.i) { this.j = new c0(aVar.b, aVar.f2202c, this.f985c, this.d, aVar2.b); } else { c0 c0Var = this.j; if (c0Var != null) { c0Var.k = 0; c0Var.m = 0; c0Var.o = 0; c0Var.p = 0; c0Var.q = 0; c0Var.r = 0; c0Var.f984s = 0; c0Var.t = 0; c0Var.u = 0; c0Var.v = 0; } } } this.m = AudioProcessor.a; this.n = 0; this.o = 0; this.p = false; } @Override // com.google.android.exoplayer2.audio.AudioProcessor public ByteBuffer getOutput() { int i; c0 c0Var = this.j; if (c0Var != null && (i = c0Var.m * c0Var.b * 2) > 0) { if (this.k.capacity() < i) { ByteBuffer order = ByteBuffer.allocateDirect(i).order(ByteOrder.nativeOrder()); this.k = order; this.l = order.asShortBuffer(); } else { this.k.clear(); this.l.clear(); } ShortBuffer shortBuffer = this.l; int min = Math.min(shortBuffer.remaining() / c0Var.b, c0Var.m); shortBuffer.put(c0Var.l, 0, c0Var.b * min); int i2 = c0Var.m - min; c0Var.m = i2; short[] sArr = c0Var.l; int i3 = c0Var.b; System.arraycopy(sArr, min * i3, sArr, 0, i2 * i3); this.o += (long) i; this.k.limit(i); this.m = this.k; } ByteBuffer byteBuffer = this.m; this.m = AudioProcessor.a; return byteBuffer; } @Override // com.google.android.exoplayer2.audio.AudioProcessor public void reset() { this.f985c = 1.0f; this.d = 1.0f; AudioProcessor.a aVar = AudioProcessor.a.a; this.e = aVar; this.f = aVar; this.g = aVar; this.h = aVar; ByteBuffer byteBuffer = AudioProcessor.a; this.k = byteBuffer; this.l = byteBuffer.asShortBuffer(); this.m = byteBuffer; this.b = -1; this.i = false; this.j = null; this.n = 0; this.o = 0; this.p = false; } }