This commit is contained in:
parent
a579fa75a5
commit
24ffa5d278
|
@ -0,0 +1,45 @@
|
|||
package com.rusefi.app;
|
||||
|
||||
import android.media.AudioFormat;
|
||||
import android.media.AudioRecord;
|
||||
import android.media.MediaRecorder;
|
||||
import android.media.audiofx.AcousticEchoCanceler;
|
||||
import android.media.audiofx.NoiseSuppressor;
|
||||
|
||||
public class SoundBroadcast {
|
||||
private static final int sampleRate = 16000; // 44100 for music
|
||||
private static final int channelConfig = AudioFormat.CHANNEL_CONFIGURATION_MONO;
|
||||
private static final int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
|
||||
private static final int minBufSize = AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioFormat) + 2048;
|
||||
private byte[] buffer = new byte[minBufSize];
|
||||
|
||||
|
||||
public void start() {
|
||||
|
||||
|
||||
Thread streamThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
AudioRecord recorder;
|
||||
recorder = new AudioRecord(MediaRecorder.AudioSource.MIC, sampleRate, channelConfig, audioFormat, minBufSize * 10);
|
||||
if (NoiseSuppressor.isAvailable()) {
|
||||
NoiseSuppressor.create(recorder.getAudioSessionId()).setEnabled(true);
|
||||
}
|
||||
if (AcousticEchoCanceler.isAvailable()) {
|
||||
AcousticEchoCanceler.create(recorder.getAudioSessionId()).setEnabled(true);
|
||||
}
|
||||
|
||||
recorder.startRecording();
|
||||
|
||||
while (true) {
|
||||
|
||||
int bytes = recorder.read(buffer, 0, buffer.length);
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
streamThread.start();
|
||||
}
|
||||
|
||||
}
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package com.rusefi.app;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.BroadcastReceiver;
|
||||
|
@ -49,11 +50,12 @@ import java.util.List;
|
|||
public class rusEFI extends Activity {
|
||||
private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
|
||||
|
||||
private static final byte REQUEST_TYPE_CLASS = 32;
|
||||
private static final byte RECIPIENT_INTERFACE = 0x01;
|
||||
// private static final byte REQUEST_TYPE_CLASS = 32;
|
||||
// private static final byte RECIPIENT_INTERFACE = 0x01;
|
||||
//
|
||||
// protected static final int DFU_DETACH_TIMEOUT = 1000;
|
||||
|
||||
|
||||
protected static final int DFU_DETACH_TIMEOUT = 1000;
|
||||
private static final String VERSION = "rusEFI app v0.0000004\n";
|
||||
|
||||
/* UI elements */
|
||||
private TextView mStatusView;
|
||||
|
@ -62,6 +64,7 @@ public class rusEFI extends Activity {
|
|||
private UsbManager usbManager;
|
||||
private DfuUpload dfuUpload;
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -72,8 +75,8 @@ public class rusEFI extends Activity {
|
|||
// turn on scree while ADB debugging idle phone
|
||||
turnScreenOn();
|
||||
|
||||
mStatusView = (TextView) findViewById(R.id.text_status);
|
||||
mResultView = (TextView) findViewById(R.id.text_result);
|
||||
mStatusView = findViewById(R.id.text_status);
|
||||
mResultView = findViewById(R.id.text_result);
|
||||
|
||||
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
|
||||
registerReceiver(mUsbReceiver, filter);
|
||||
|
@ -116,7 +119,7 @@ public class rusEFI extends Activity {
|
|||
};
|
||||
|
||||
private void handleButton() {
|
||||
mResultView.append("rusEFI app v0.0000003\n");
|
||||
mResultView.append(VERSION);
|
||||
|
||||
UsbDevice dfuDevice = DfuDeviceLocator.findDevice(usbManager);
|
||||
|
||||
|
@ -129,6 +132,7 @@ public class rusEFI extends Activity {
|
|||
// listDevices(manager);
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private void handleSerialDevice() {
|
||||
List<UsbSerialDriver> availableDrivers = AndroidSerial.findUsbSerial(usbManager);
|
||||
if (availableDrivers.isEmpty()) {
|
||||
|
@ -169,6 +173,7 @@ public class rusEFI extends Activity {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private void dfuUpdate(UsbDevice dfuDevice, TextView mResultView) {
|
||||
mStatusView.setText("rusEFI: DFU detected");
|
||||
DfuDeviceLocator.Result dfu = new DfuDeviceLocator().openDfu(usbManager, dfuDevice);
|
||||
|
@ -194,7 +199,12 @@ public class rusEFI extends Activity {
|
|||
* Called when the user touches the button
|
||||
*/
|
||||
public void sendMessage(View view) {
|
||||
if (view.getId() == R.id.button) {
|
||||
handleButton();
|
||||
} else if (view.getId() == R.id.buttonSound) {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -17,9 +17,22 @@
|
|||
android:id="@+id/button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Try"
|
||||
android:onClick="sendMessage"
|
||||
/>
|
||||
android:text="Try" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/buttonSound"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="sendMessage"
|
||||
android:text="Sound" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/button3"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="sendMessage"
|
||||
android:text="Try" />
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
|
|
Loading…
Reference in New Issue