kopia lustrzana https://github.com/sh123/codec2_talkie
Enable dynamic mode set
rodzic
2d1e04ea28
commit
77125218ef
|
@ -26,11 +26,11 @@ public class Codec2Player extends Thread {
|
||||||
private final int AUDIO_SAMPLE_SIZE = 8000;
|
private final int AUDIO_SAMPLE_SIZE = 8000;
|
||||||
private final int SLEEP_DELAY_MS = 10;
|
private final int SLEEP_DELAY_MS = 10;
|
||||||
|
|
||||||
private final long _codec2Con;
|
private long _codec2Con;
|
||||||
|
|
||||||
private final BluetoothSocket _btSocket;
|
private final BluetoothSocket _btSocket;
|
||||||
|
|
||||||
private final int _audioBufferSize;
|
private int _audioBufferSize;
|
||||||
|
|
||||||
private boolean _isRecording = false;
|
private boolean _isRecording = false;
|
||||||
|
|
||||||
|
@ -39,22 +39,22 @@ public class Codec2Player extends Thread {
|
||||||
|
|
||||||
private final AudioTrack _audioPlayer;
|
private final AudioTrack _audioPlayer;
|
||||||
|
|
||||||
private final short[] _playbackAudioBuffer;
|
private short[] _playbackAudioBuffer;
|
||||||
|
|
||||||
// output data., mic -> bt
|
// output data., mic -> bt
|
||||||
private final OutputStream _btOutputStream;
|
private final OutputStream _btOutputStream;
|
||||||
|
|
||||||
private final AudioRecord _audioRecorder;
|
private final AudioRecord _audioRecorder;
|
||||||
|
|
||||||
private final short[] _recordAudioBuffer;
|
private short[] _recordAudioBuffer;
|
||||||
private final char[] _recordAudioEncodedBuffer;
|
private char[] _recordAudioEncodedBuffer;
|
||||||
|
|
||||||
// loopback mode
|
// loopback mode
|
||||||
private boolean _isLoopbackMode;
|
private boolean _isLoopbackMode;
|
||||||
private final ByteBuffer _loopbackBuffer;
|
private ByteBuffer _loopbackBuffer;
|
||||||
|
|
||||||
// callbacks
|
// callbacks
|
||||||
private final KissProcessor _kissProcessor;
|
private KissProcessor _kissProcessor;
|
||||||
private final Handler _onPlayerStateChanged;
|
private final Handler _onPlayerStateChanged;
|
||||||
|
|
||||||
public Codec2Player(BluetoothSocket btSocket, Handler onPlayerStateChanged, int codec2Mode) throws IOException {
|
public Codec2Player(BluetoothSocket btSocket, Handler onPlayerStateChanged, int codec2Mode) throws IOException {
|
||||||
|
@ -97,7 +97,28 @@ public class Codec2Player extends Thread {
|
||||||
.build();
|
.build();
|
||||||
_audioPlayer.play();
|
_audioPlayer.play();
|
||||||
|
|
||||||
_codec2Con = Codec2.create(codec2Mode);
|
setCodecModeInternal(codec2Mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLoopbackMode(boolean isLoopbackMode) {
|
||||||
|
_isLoopbackMode = isLoopbackMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCodecMode(int codecMode) {
|
||||||
|
Codec2.destroy(_codec2Con);
|
||||||
|
setCodecModeInternal(codecMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startPlayback() {
|
||||||
|
_isRecording = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void startRecording() {
|
||||||
|
_isRecording = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setCodecModeInternal(int codecMode) {
|
||||||
|
_codec2Con = Codec2.create(codecMode);
|
||||||
|
|
||||||
_audioBufferSize = Codec2.getSamplesPerFrame(_codec2Con);
|
_audioBufferSize = Codec2.getSamplesPerFrame(_codec2Con);
|
||||||
int _audioEncodedBufferSize = Codec2.getBitsSize(_codec2Con); // returns number of bytes
|
int _audioEncodedBufferSize = Codec2.getBitsSize(_codec2Con); // returns number of bytes
|
||||||
|
@ -112,18 +133,6 @@ public class Codec2Player extends Thread {
|
||||||
_kissProcessor = new KissProcessor(_audioEncodedBufferSize, _kissCallback);
|
_kissProcessor = new KissProcessor(_audioEncodedBufferSize, _kissCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLoopbackMode(boolean isLoopbackMode) {
|
|
||||||
_isLoopbackMode = isLoopbackMode;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startPlayback() {
|
|
||||||
_isRecording = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startRecording() {
|
|
||||||
_isRecording = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private final KissCallback _kissCallback = new KissCallback() {
|
private final KissCallback _kissCallback = new KissCallback() {
|
||||||
@Override
|
@Override
|
||||||
protected void sendByte(byte b) {
|
protected void sendByte(byte b) {
|
||||||
|
|
|
@ -14,7 +14,9 @@ import android.os.Looper;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.AdapterView;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
import android.widget.Spinner;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
@ -31,6 +33,9 @@ public class MainActivity extends AppCompatActivity {
|
||||||
private final static int REQUEST_CONNECT_BT = 1;
|
private final static int REQUEST_CONNECT_BT = 1;
|
||||||
private final static int REQUEST_PERMISSIONS = 2;
|
private final static int REQUEST_PERMISSIONS = 2;
|
||||||
|
|
||||||
|
private final static int CODEC2_DEFAULT_MODE = Codec2.CODEC2_MODE_450;
|
||||||
|
private final static int CODEC2_DEFAULT_MODE_POS = 0;
|
||||||
|
|
||||||
private final String[] _requiredPermissions = new String[] {
|
private final String[] _requiredPermissions = new String[] {
|
||||||
Manifest.permission.BLUETOOTH,
|
Manifest.permission.BLUETOOTH,
|
||||||
Manifest.permission.RECORD_AUDIO
|
Manifest.permission.RECORD_AUDIO
|
||||||
|
@ -50,6 +55,10 @@ public class MainActivity extends AppCompatActivity {
|
||||||
Button _btnPtt = (Button) findViewById(R.id.btnPtt);
|
Button _btnPtt = (Button) findViewById(R.id.btnPtt);
|
||||||
_btnPtt.setOnTouchListener(onBtnPttTouchListener);
|
_btnPtt.setOnTouchListener(onBtnPttTouchListener);
|
||||||
|
|
||||||
|
Spinner _spinnerCodec2Mode = (Spinner) findViewById(R.id.spinnerCodecMode);
|
||||||
|
_spinnerCodec2Mode.setSelection(CODEC2_DEFAULT_MODE_POS);
|
||||||
|
_spinnerCodec2Mode.setOnItemSelectedListener(onCodecModeSelectedListener);
|
||||||
|
|
||||||
if (requestPermissions()) {
|
if (requestPermissions()) {
|
||||||
startBluetoothConnectActivity();
|
startBluetoothConnectActivity();
|
||||||
}
|
}
|
||||||
|
@ -78,6 +87,20 @@ public class MainActivity extends AppCompatActivity {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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]));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onNothingSelected(AdapterView<?> parent) {
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private final View.OnTouchListener onBtnPttTouchListener = new View.OnTouchListener() {
|
private final View.OnTouchListener onBtnPttTouchListener = new View.OnTouchListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
|
@ -137,7 +160,7 @@ public class MainActivity extends AppCompatActivity {
|
||||||
_codec2Player = new Codec2Player(
|
_codec2Player = new Codec2Player(
|
||||||
SocketHandler.getSocket(),
|
SocketHandler.getSocket(),
|
||||||
onPlayerStateChanged,
|
onPlayerStateChanged,
|
||||||
Codec2.CODEC2_MODE_450);
|
CODEC2_DEFAULT_MODE);
|
||||||
_codec2Player.setLoopbackMode(true);
|
_codec2Player.setLoopbackMode(true);
|
||||||
_codec2Player.start();
|
_codec2Player.start();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
|
@ -12,7 +12,9 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="16dp"
|
android:layout_marginStart="16dp"
|
||||||
android:layout_marginTop="16dp"
|
android:layout_marginTop="16dp"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
android:text="Connected bluetooth"
|
||||||
|
android:textAppearance="@style/TextAppearance.AppCompat.Large"
|
||||||
|
android:textSize="14sp"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
@ -34,4 +36,24 @@
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/loopbackMode"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="48dp"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:text="Codec2 loopback test"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/spinnerCodecMode" />
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/spinnerCodecMode"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginTop="16dp"
|
||||||
|
android:entries="@array/codec2_modes"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toBottomOf="@id/textBtName" />
|
||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -1,4 +1,14 @@
|
||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Codec2Talkie</string>
|
<string name="app_name">Codec2Talkie</string>
|
||||||
<string name="push_to_talk">push-to-talk</string>
|
<string name="push_to_talk">push-to-talk</string>
|
||||||
|
<string-array name="codec2_modes">
|
||||||
|
<item>CODEC2_MODE_450=10</item>
|
||||||
|
<item>CODEC2_MODE_700C=8</item>
|
||||||
|
<item>CODEC2_MODE_1200=5</item>
|
||||||
|
<item>CODEC2_MODE_1300=4</item>
|
||||||
|
<item>CODEC2_MODE_1400=3</item>
|
||||||
|
<item>CODEC2_MODE_1600=2</item>
|
||||||
|
<item>CODEC2_MODE_2400=1</item>
|
||||||
|
<item>CODEC2_MODE_3200=0</item>
|
||||||
|
</string-array>
|
||||||
</resources>
|
</resources>
|
|
@ -16,10 +16,7 @@ public class Codec2 {
|
||||||
public static final int CODEC2_MODE_1400 = 3;
|
public static final int CODEC2_MODE_1400 = 3;
|
||||||
public static final int CODEC2_MODE_1300 = 4;
|
public static final int CODEC2_MODE_1300 = 4;
|
||||||
public static final int CODEC2_MODE_1200 = 5;
|
public static final int CODEC2_MODE_1200 = 5;
|
||||||
public static final int CODEC2_MODE_700 = 6;
|
|
||||||
public static final int CODEC2_MODE_700B = 7;
|
|
||||||
public static final int CODEC2_MODE_700C = 8;
|
public static final int CODEC2_MODE_700C = 8;
|
||||||
public static final int CODEC2_MODE_WB = 9;
|
|
||||||
public static final int CODEC2_MODE_450=10;
|
public static final int CODEC2_MODE_450=10;
|
||||||
public static final int CODEC2_MODE_450PWB=11;
|
public static final int CODEC2_MODE_450PWB=11;
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue