You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
79 lines
2.4 KiB
Java
79 lines
2.4 KiB
Java
package com.dowse.base.audio;
|
|
|
|
import com.dowse.base.audio.AudioCapturer;
|
|
|
|
/* loaded from: ds_base_2.0.9_23030112.aar:classes.jar:com/dowse/base/audio/DSAudioManager.class */
|
|
public class DSAudioManager implements AudioCapturer.OnAudioFrameCapturedListener {
|
|
private static final String TAG = "DSAudioManager";
|
|
private static DSAudioManager instance;
|
|
private AudioCapturer mAudioCapturer;
|
|
private AudioPlayer mAudioPlayer;
|
|
private DSCircleQueue mDSCircleQueue;
|
|
|
|
public static DSAudioManager getInstance() {
|
|
if (instance == null) {
|
|
instance = new DSAudioManager();
|
|
}
|
|
return instance;
|
|
}
|
|
|
|
private DSAudioManager() {
|
|
this.mAudioCapturer = null;
|
|
this.mAudioPlayer = null;
|
|
this.mAudioCapturer = new AudioCapturer();
|
|
this.mAudioCapturer.setOnAudioFrameCapturedListener(this);
|
|
this.mAudioPlayer = new AudioPlayer();
|
|
this.mDSCircleQueue = new DSCircleQueue();
|
|
}
|
|
|
|
public boolean startCapture() {
|
|
if (this.mAudioCapturer != null && !this.mAudioCapturer.isCaptureStarted()) {
|
|
return this.mAudioCapturer.startCapture();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public boolean stopCapture() {
|
|
if (this.mAudioCapturer != null && this.mAudioCapturer.isCaptureStarted()) {
|
|
return this.mAudioCapturer.stopCapture();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public boolean startPlayer() {
|
|
if (this.mAudioPlayer != null) {
|
|
return this.mAudioPlayer.startPlayer();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public boolean stopPlayer() {
|
|
if (this.mAudioPlayer != null) {
|
|
return this.mAudioPlayer.stopPlayer();
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public boolean play(byte[] pcmData) {
|
|
if (this.mAudioPlayer != null) {
|
|
return this.mAudioPlayer.play(pcmData, 0, pcmData.length);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
@Override // com.dowse.base.audio.AudioCapturer.OnAudioFrameCapturedListener
|
|
public void onAudioFrameCaptured(byte[] audioData) {
|
|
if (this.mDSCircleQueue != null) {
|
|
this.mDSCircleQueue.add(new DSAudioFrame(G711Alaw.encode(audioData)));
|
|
}
|
|
}
|
|
|
|
public DSElement getAudioFrame(int readIndex) {
|
|
DSElement element = null;
|
|
if (this.mDSCircleQueue != null) {
|
|
element = this.mDSCircleQueue.get(readIndex);
|
|
}
|
|
return element;
|
|
}
|
|
}
|