jimu-decompiled/sources/org/fmod/FMODAudioDevice.java
2025-05-13 19:24:51 +02:00

129 lines
3.7 KiB
Java

package org.fmod;
import android.media.AudioTrack;
import android.util.Log;
import java.nio.ByteBuffer;
/* loaded from: classes2.dex */
public class FMODAudioDevice implements Runnable {
private static int h = 0;
private static int i = 1;
private static int j = 2;
private static int k = 3;
private volatile Thread a = null;
private volatile boolean b = false;
private AudioTrack c = null;
private boolean d = false;
private ByteBuffer e = null;
private byte[] f = null;
private volatile a g;
private native int fmodGetInfo(int i2);
private native int fmodProcess(ByteBuffer byteBuffer);
private void releaseAudioTrack() {
AudioTrack audioTrack = this.c;
if (audioTrack != null) {
if (audioTrack.getState() == 1) {
this.c.stop();
}
this.c.release();
this.c = null;
}
this.e = null;
this.f = null;
this.d = false;
}
public synchronized void close() {
stop();
}
native int fmodProcessMicData(ByteBuffer byteBuffer, int i2);
public boolean isRunning() {
return this.a != null && this.a.isAlive();
}
@Override // java.lang.Runnable
public void run() {
int i2 = 3;
while (this.b) {
if (!this.d && i2 > 0) {
releaseAudioTrack();
int fmodGetInfo = fmodGetInfo(h);
int round = Math.round(AudioTrack.getMinBufferSize(fmodGetInfo, 3, 2) * 1.1f) & (-4);
int fmodGetInfo2 = fmodGetInfo(i);
int fmodGetInfo3 = fmodGetInfo(j) * fmodGetInfo2 * 4;
this.c = new AudioTrack(3, fmodGetInfo, 3, 2, fmodGetInfo3 > round ? fmodGetInfo3 : round, 1);
this.d = this.c.getState() == 1;
if (this.d) {
this.e = ByteBuffer.allocateDirect(fmodGetInfo2 * 2 * 2);
this.f = new byte[this.e.capacity()];
this.c.play();
i2 = 3;
} else {
Log.e("FMOD", "AudioTrack failed to initialize (status " + this.c.getState() + ")");
releaseAudioTrack();
i2 += -1;
}
}
if (this.d) {
if (fmodGetInfo(k) == 1) {
fmodProcess(this.e);
ByteBuffer byteBuffer = this.e;
byteBuffer.get(this.f, 0, byteBuffer.capacity());
this.c.write(this.f, 0, this.e.capacity());
this.e.position(0);
} else {
releaseAudioTrack();
}
}
}
releaseAudioTrack();
}
public synchronized void start() {
if (this.a != null) {
stop();
}
this.a = new Thread(this, "FMODAudioDevice");
this.a.setPriority(10);
this.b = true;
this.a.start();
if (this.g != null) {
this.g.b();
}
}
public synchronized int startAudioRecord(int i2, int i3, int i4) {
if (this.g == null) {
this.g = new a(this, i2, i3);
this.g.b();
}
return this.g.a();
}
public synchronized void stop() {
while (this.a != null) {
this.b = false;
try {
this.a.join();
this.a = null;
} catch (InterruptedException unused) {
}
}
if (this.g != null) {
this.g.c();
}
}
public synchronized void stopAudioRecord() {
if (this.g != null) {
this.g.c();
this.g = null;
}
}
}