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;
|
package com.rusefi.app;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
|
@ -49,11 +50,12 @@ import java.util.List;
|
||||||
public class rusEFI extends Activity {
|
public class rusEFI extends Activity {
|
||||||
private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
|
private static final String ACTION_USB_PERMISSION = "com.android.example.USB_PERMISSION";
|
||||||
|
|
||||||
private static final byte REQUEST_TYPE_CLASS = 32;
|
// private static final byte REQUEST_TYPE_CLASS = 32;
|
||||||
private static final byte RECIPIENT_INTERFACE = 0x01;
|
// private static final byte RECIPIENT_INTERFACE = 0x01;
|
||||||
|
//
|
||||||
|
// protected static final int DFU_DETACH_TIMEOUT = 1000;
|
||||||
|
|
||||||
|
private static final String VERSION = "rusEFI app v0.0000004\n";
|
||||||
protected static final int DFU_DETACH_TIMEOUT = 1000;
|
|
||||||
|
|
||||||
/* UI elements */
|
/* UI elements */
|
||||||
private TextView mStatusView;
|
private TextView mStatusView;
|
||||||
|
@ -62,6 +64,7 @@ public class rusEFI extends Activity {
|
||||||
private UsbManager usbManager;
|
private UsbManager usbManager;
|
||||||
private DfuUpload dfuUpload;
|
private DfuUpload dfuUpload;
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
@ -72,8 +75,8 @@ public class rusEFI extends Activity {
|
||||||
// turn on scree while ADB debugging idle phone
|
// turn on scree while ADB debugging idle phone
|
||||||
turnScreenOn();
|
turnScreenOn();
|
||||||
|
|
||||||
mStatusView = (TextView) findViewById(R.id.text_status);
|
mStatusView = findViewById(R.id.text_status);
|
||||||
mResultView = (TextView) findViewById(R.id.text_result);
|
mResultView = findViewById(R.id.text_result);
|
||||||
|
|
||||||
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
|
IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
|
||||||
registerReceiver(mUsbReceiver, filter);
|
registerReceiver(mUsbReceiver, filter);
|
||||||
|
@ -116,7 +119,7 @@ public class rusEFI extends Activity {
|
||||||
};
|
};
|
||||||
|
|
||||||
private void handleButton() {
|
private void handleButton() {
|
||||||
mResultView.append("rusEFI app v0.0000003\n");
|
mResultView.append(VERSION);
|
||||||
|
|
||||||
UsbDevice dfuDevice = DfuDeviceLocator.findDevice(usbManager);
|
UsbDevice dfuDevice = DfuDeviceLocator.findDevice(usbManager);
|
||||||
|
|
||||||
|
@ -129,6 +132,7 @@ public class rusEFI extends Activity {
|
||||||
// listDevices(manager);
|
// listDevices(manager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
private void handleSerialDevice() {
|
private void handleSerialDevice() {
|
||||||
List<UsbSerialDriver> availableDrivers = AndroidSerial.findUsbSerial(usbManager);
|
List<UsbSerialDriver> availableDrivers = AndroidSerial.findUsbSerial(usbManager);
|
||||||
if (availableDrivers.isEmpty()) {
|
if (availableDrivers.isEmpty()) {
|
||||||
|
@ -169,6 +173,7 @@ public class rusEFI extends Activity {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("SetTextI18n")
|
||||||
private void dfuUpdate(UsbDevice dfuDevice, TextView mResultView) {
|
private void dfuUpdate(UsbDevice dfuDevice, TextView mResultView) {
|
||||||
mStatusView.setText("rusEFI: DFU detected");
|
mStatusView.setText("rusEFI: DFU detected");
|
||||||
DfuDeviceLocator.Result dfu = new DfuDeviceLocator().openDfu(usbManager, dfuDevice);
|
DfuDeviceLocator.Result dfu = new DfuDeviceLocator().openDfu(usbManager, dfuDevice);
|
||||||
|
@ -194,7 +199,12 @@ public class rusEFI extends Activity {
|
||||||
* Called when the user touches the button
|
* Called when the user touches the button
|
||||||
*/
|
*/
|
||||||
public void sendMessage(View view) {
|
public void sendMessage(View view) {
|
||||||
handleButton();
|
if (view.getId() == R.id.button) {
|
||||||
|
handleButton();
|
||||||
|
} else if (view.getId() == R.id.buttonSound) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -17,9 +17,22 @@
|
||||||
android:id="@+id/button"
|
android:id="@+id/button"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="Try"
|
|
||||||
android:onClick="sendMessage"
|
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
|
<ScrollView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
Loading…
Reference in New Issue