kopia lustrzana https://github.com/sh123/codec2_talkie
Enable dynamic loopback selection
rodzic
77125218ef
commit
0538bfc583
|
@ -28,21 +28,21 @@ public class Codec2Player extends Thread {
|
|||
|
||||
private long _codec2Con;
|
||||
|
||||
private final BluetoothSocket _btSocket;
|
||||
private BluetoothSocket _btSocket;
|
||||
|
||||
private int _audioBufferSize;
|
||||
|
||||
private boolean _isRecording = false;
|
||||
|
||||
// input data, bt -> audio
|
||||
private final InputStream _btInputStream;
|
||||
private InputStream _btInputStream;
|
||||
|
||||
private final AudioTrack _audioPlayer;
|
||||
|
||||
private short[] _playbackAudioBuffer;
|
||||
|
||||
// output data., mic -> bt
|
||||
private final OutputStream _btOutputStream;
|
||||
private OutputStream _btOutputStream;
|
||||
|
||||
private final AudioRecord _audioRecorder;
|
||||
|
||||
|
@ -57,15 +57,11 @@ public class Codec2Player extends Thread {
|
|||
private KissProcessor _kissProcessor;
|
||||
private final Handler _onPlayerStateChanged;
|
||||
|
||||
public Codec2Player(BluetoothSocket btSocket, Handler onPlayerStateChanged, int codec2Mode) throws IOException {
|
||||
public Codec2Player(Handler onPlayerStateChanged, int codec2Mode) {
|
||||
|
||||
_onPlayerStateChanged = onPlayerStateChanged;
|
||||
_isLoopbackMode = false;
|
||||
|
||||
_btSocket = btSocket;
|
||||
_btInputStream = _btSocket.getInputStream();
|
||||
_btOutputStream = _btSocket.getOutputStream();
|
||||
|
||||
int _audioRecorderMinBufferSize = AudioRecord.getMinBufferSize(
|
||||
AUDIO_SAMPLE_SIZE,
|
||||
AudioFormat.CHANNEL_IN_MONO,
|
||||
|
@ -100,6 +96,12 @@ public class Codec2Player extends Thread {
|
|||
setCodecModeInternal(codec2Mode);
|
||||
}
|
||||
|
||||
public void setSocket(BluetoothSocket btSocket) throws IOException {
|
||||
_btSocket = btSocket;
|
||||
_btInputStream = _btSocket.getInputStream();
|
||||
_btOutputStream = _btSocket.getOutputStream();
|
||||
}
|
||||
|
||||
public void setLoopbackMode(boolean isLoopbackMode) {
|
||||
_isLoopbackMode = isLoopbackMode;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@ import android.view.MotionEvent;
|
|||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
@ -52,12 +54,17 @@ public class MainActivity extends AppCompatActivity {
|
|||
setContentView(R.layout.activity_main);
|
||||
|
||||
_textBtName = (TextView)findViewById(R.id.textBtName);
|
||||
Button _btnPtt = (Button) findViewById(R.id.btnPtt);
|
||||
_btnPtt.setOnTouchListener(onBtnPttTouchListener);
|
||||
Button btnPtt = (Button)findViewById(R.id.btnPtt);
|
||||
btnPtt.setOnTouchListener(onBtnPttTouchListener);
|
||||
|
||||
Spinner _spinnerCodec2Mode = (Spinner) findViewById(R.id.spinnerCodecMode);
|
||||
_spinnerCodec2Mode.setSelection(CODEC2_DEFAULT_MODE_POS);
|
||||
_spinnerCodec2Mode.setOnItemSelectedListener(onCodecModeSelectedListener);
|
||||
Spinner spinnerCodec2Mode = (Spinner)findViewById(R.id.spinnerCodecMode);
|
||||
spinnerCodec2Mode.setSelection(CODEC2_DEFAULT_MODE_POS);
|
||||
spinnerCodec2Mode.setOnItemSelectedListener(onCodecModeSelectedListener);
|
||||
|
||||
CheckBox checkBoxLoopback = (CheckBox)findViewById(R.id.checkBoxLoopback);
|
||||
checkBoxLoopback.setOnCheckedChangeListener(onLoopbackCheckedChangeListener);
|
||||
|
||||
_codec2Player = new Codec2Player(onPlayerStateChanged, CODEC2_DEFAULT_MODE);
|
||||
|
||||
if (requestPermissions()) {
|
||||
startBluetoothConnectActivity();
|
||||
|
@ -87,13 +94,19 @@ public class MainActivity extends AppCompatActivity {
|
|||
return true;
|
||||
}
|
||||
|
||||
private final CompoundButton.OnCheckedChangeListener onLoopbackCheckedChangeListener = new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
_codec2Player.setLoopbackMode(isChecked);
|
||||
}
|
||||
};
|
||||
|
||||
private final AdapterView.OnItemSelectedListener onCodecModeSelectedListener = new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
||||
String selectedCodec = getResources().getStringArray(R.array.codec2_modes)[position];
|
||||
String [] codecNameCodecId = selectedCodec.split("=");
|
||||
if (_codec2Player != null)
|
||||
_codec2Player.setCodecMode(Integer.parseInt(codecNameCodecId[1]));
|
||||
_codec2Player.setCodecMode(Integer.parseInt(codecNameCodecId[1]));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -155,17 +168,13 @@ public class MainActivity extends AppCompatActivity {
|
|||
if (resultCode == RESULT_CANCELED) {
|
||||
finish();
|
||||
} else if (resultCode == RESULT_OK) {
|
||||
_textBtName.setText(data.getStringExtra("name"));
|
||||
_textBtName.setText(String.format("BT: %s", data.getStringExtra("name")));
|
||||
try {
|
||||
_codec2Player = new Codec2Player(
|
||||
SocketHandler.getSocket(),
|
||||
onPlayerStateChanged,
|
||||
CODEC2_DEFAULT_MODE);
|
||||
_codec2Player.setLoopbackMode(true);
|
||||
_codec2Player.start();
|
||||
_codec2Player.setSocket(SocketHandler.getSocket());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
_codec2Player.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/loopbackMode"
|
||||
android:id="@+id/checkBoxLoopback"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginStart="16dp"
|
||||
|
|
Ładowanie…
Reference in New Issue