Initial commit
This commit is contained in:
128
sources/org/fmod/FMODAudioDevice.java
Normal file
128
sources/org/fmod/FMODAudioDevice.java
Normal file
@@ -0,0 +1,128 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
90
sources/org/fmod/a.java
Normal file
90
sources/org/fmod/a.java
Normal file
@@ -0,0 +1,90 @@
|
||||
package org.fmod;
|
||||
|
||||
import android.media.AudioRecord;
|
||||
import android.util.Log;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/* loaded from: classes2.dex */
|
||||
final class a implements Runnable {
|
||||
private final FMODAudioDevice a;
|
||||
private final ByteBuffer b;
|
||||
private final int c;
|
||||
private final int d;
|
||||
private final int e = 2;
|
||||
private volatile Thread f;
|
||||
private volatile boolean g;
|
||||
private AudioRecord h;
|
||||
private boolean i;
|
||||
|
||||
a(FMODAudioDevice fMODAudioDevice, int i, int i2) {
|
||||
this.a = fMODAudioDevice;
|
||||
this.c = i;
|
||||
this.d = i2;
|
||||
this.b = ByteBuffer.allocateDirect(AudioRecord.getMinBufferSize(i, i2, 2));
|
||||
}
|
||||
|
||||
private void d() {
|
||||
AudioRecord audioRecord = this.h;
|
||||
if (audioRecord != null) {
|
||||
if (audioRecord.getState() == 1) {
|
||||
this.h.stop();
|
||||
}
|
||||
this.h.release();
|
||||
this.h = null;
|
||||
}
|
||||
this.b.position(0);
|
||||
this.i = false;
|
||||
}
|
||||
|
||||
public final int a() {
|
||||
return this.b.capacity();
|
||||
}
|
||||
|
||||
public final void b() {
|
||||
if (this.f != null) {
|
||||
c();
|
||||
}
|
||||
this.g = true;
|
||||
this.f = new Thread(this);
|
||||
this.f.start();
|
||||
}
|
||||
|
||||
public final void c() {
|
||||
while (this.f != null) {
|
||||
this.g = false;
|
||||
try {
|
||||
this.f.join();
|
||||
this.f = null;
|
||||
} catch (InterruptedException unused) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override // java.lang.Runnable
|
||||
public final void run() {
|
||||
int i = 3;
|
||||
while (this.g) {
|
||||
if (!this.i && i > 0) {
|
||||
d();
|
||||
this.h = new AudioRecord(1, this.c, this.d, this.e, this.b.capacity());
|
||||
this.i = this.h.getState() == 1;
|
||||
if (this.i) {
|
||||
this.b.position(0);
|
||||
this.h.startRecording();
|
||||
i = 3;
|
||||
} else {
|
||||
Log.e("FMOD", "AudioRecord failed to initialize (status " + this.h.getState() + ")");
|
||||
i += -1;
|
||||
d();
|
||||
}
|
||||
}
|
||||
if (this.i && this.h.getRecordingState() == 3) {
|
||||
AudioRecord audioRecord = this.h;
|
||||
ByteBuffer byteBuffer = this.b;
|
||||
this.a.fmodProcessMicData(this.b, audioRecord.read(byteBuffer, byteBuffer.capacity()));
|
||||
this.b.position(0);
|
||||
}
|
||||
}
|
||||
d();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user