diff --git a/app/src/main/java/xdsopl/robot36/MainActivity.java b/app/src/main/java/xdsopl/robot36/MainActivity.java
index 5f048bd..75264c8 100644
--- a/app/src/main/java/xdsopl/robot36/MainActivity.java
+++ b/app/src/main/java/xdsopl/robot36/MainActivity.java
@@ -71,6 +71,7 @@ public class MainActivity extends AppCompatActivity {
private PixelBuffer peakMeterBuffer;
private ImageView peakMeterView;
private PixelBuffer imageBuffer;
+ private short[] shortBuffer;
private float[] recordBuffer;
private AudioRecord audioRecord;
private Decoder decoder;
@@ -80,6 +81,7 @@ public class MainActivity extends AppCompatActivity {
private int recordRate;
private int recordChannel;
private int audioSource;
+ private int audioFormat;
private int fgColor;
private int thinColor;
private int tintColor;
@@ -126,7 +128,13 @@ public void onMarkerReached(AudioRecord ignore) {
@Override
public void onPeriodicNotification(AudioRecord audioRecord) {
- audioRecord.read(recordBuffer, 0, recordBuffer.length, AudioRecord.READ_BLOCKING);
+ if (shortBuffer == null) {
+ audioRecord.read(recordBuffer, 0, recordBuffer.length, AudioRecord.READ_BLOCKING);
+ } else {
+ audioRecord.read(shortBuffer, 0, shortBuffer.length, AudioRecord.READ_BLOCKING);
+ for (int i = 0; i < shortBuffer.length; ++i)
+ recordBuffer[i] = .000030517578125f * shortBuffer[i];
+ }
processPeakMeter();
boolean newLines = decoder.process(recordBuffer, recordChannel);
processFreqPlot();
@@ -199,7 +207,8 @@ private void initAudioRecord() {
rateChanged = audioRecord.getSampleRate() != recordRate;
boolean channelChanged = audioRecord.getChannelCount() != (recordChannel == 0 ? 1 : 2);
boolean sourceChanged = audioRecord.getAudioSource() != audioSource;
- if (!rateChanged && !channelChanged && !sourceChanged)
+ boolean formatChanged = audioRecord.getAudioFormat() != audioFormat;
+ if (!rateChanged && !channelChanged && !sourceChanged && !formatChanged)
return;
stopListening();
audioRecord.release();
@@ -211,13 +220,14 @@ private void initAudioRecord() {
channelCount = 2;
channelConfig = AudioFormat.CHANNEL_IN_STEREO;
}
- int sampleSize = 4;
+ int sampleSize = audioFormat == AudioFormat.ENCODING_PCM_FLOAT ? 4 : 2;
int frameSize = sampleSize * channelCount;
- int audioFormat = AudioFormat.ENCODING_PCM_FLOAT;
int readsPerSecond = 50;
int bufferSize = Integer.highestOneBit(recordRate) * frameSize;
int frameCount = recordRate / readsPerSecond;
- recordBuffer = new float[frameCount * channelCount];
+ int bufferCount = frameCount * channelCount;
+ recordBuffer = new float[bufferCount];
+ shortBuffer = audioFormat == AudioFormat.ENCODING_PCM_FLOAT ? null : new short[bufferCount];
try {
audioRecord = new AudioRecord(audioSource, recordRate, channelConfig, audioFormat, bufferSize);
if (audioRecord.getState() == AudioRecord.STATE_INITIALIZED) {
@@ -244,7 +254,10 @@ private void startListening() {
if (audioRecord != null) {
audioRecord.startRecording();
if (audioRecord.getRecordingState() == AudioRecord.RECORDSTATE_RECORDING) {
- audioRecord.read(recordBuffer, 0, recordBuffer.length, AudioRecord.READ_BLOCKING);
+ if (shortBuffer == null)
+ audioRecord.read(recordBuffer, 0, recordBuffer.length, AudioRecord.READ_BLOCKING);
+ else
+ audioRecord.read(shortBuffer, 0, recordBuffer.length, AudioRecord.READ_BLOCKING);
setStatus(R.string.listening);
} else {
setStatus(R.string.audio_recording_error);
@@ -281,6 +294,14 @@ private void setAudioSource(int newAudioSource) {
initAudioRecord();
}
+ private void setAudioFormat(int newAudioFormat) {
+ if (audioFormat == newAudioFormat)
+ return;
+ audioFormat = newAudioFormat;
+ updateAudioFormatMenu();
+ initAudioRecord();
+ }
+
private void updateRecordRateMenu() {
switch (recordRate) {
case 8000:
@@ -341,6 +362,10 @@ private void updateAudioSourceMenu() {
}
}
+ private void updateAudioFormatMenu() {
+ menu.findItem(audioFormat == AudioFormat.ENCODING_PCM_FLOAT ? R.id.action_set_floating_point : R.id.action_set_fixed_point).setChecked(true);
+ }
+
private final int permissionID = 1;
@Override
@@ -359,6 +384,7 @@ protected void onSaveInstanceState(@NonNull Bundle state) {
state.putInt("recordRate", recordRate);
state.putInt("recordChannel", recordChannel);
state.putInt("audioSource", audioSource);
+ state.putInt("audioFormat", audioFormat);
state.putString("language", language);
super.onSaveInstanceState(state);
}
@@ -370,6 +396,7 @@ private void storeSettings() {
edit.putInt("recordRate", recordRate);
edit.putInt("recordChannel", recordChannel);
edit.putInt("audioSource", audioSource);
+ edit.putInt("audioFormat", audioFormat);
edit.putString("language", language);
edit.apply();
}
@@ -379,6 +406,7 @@ protected void onCreate(Bundle state) {
final int defaultSampleRate = 44100;
final int defaultChannelSelect = 0;
final int defaultAudioSource = MediaRecorder.AudioSource.MIC;
+ final int defaultAudioFormat = AudioFormat.ENCODING_PCM_FLOAT;
final String defaultLanguage = "system";
if (state == null) {
SharedPreferences pref = getPreferences(Context.MODE_PRIVATE);
@@ -386,12 +414,14 @@ protected void onCreate(Bundle state) {
recordRate = pref.getInt("recordRate", defaultSampleRate);
recordChannel = pref.getInt("recordChannel", defaultChannelSelect);
audioSource = pref.getInt("audioSource", defaultAudioSource);
+ audioFormat = pref.getInt("audioFormat", defaultAudioFormat);
language = pref.getString("language", defaultLanguage);
} else {
AppCompatDelegate.setDefaultNightMode(state.getInt("nightMode", AppCompatDelegate.getDefaultNightMode()));
recordRate = state.getInt("recordRate", defaultSampleRate);
recordChannel = state.getInt("recordChannel", defaultChannelSelect);
audioSource = state.getInt("audioSource", defaultAudioSource);
+ audioFormat = state.getInt("audioFormat", defaultAudioFormat);
language = state.getString("language", defaultLanguage);
}
super.onCreate(state);
@@ -438,6 +468,7 @@ public boolean onCreateOptionsMenu(Menu menu) {
updateRecordRateMenu();
updateRecordChannelMenu();
updateAudioSourceMenu();
+ updateAudioFormatMenu();
return true;
}
@@ -576,6 +607,14 @@ public boolean onOptionsItemSelected(MenuItem item) {
setAudioSource(MediaRecorder.AudioSource.UNPROCESSED);
return true;
}
+ if (id == R.id.action_set_floating_point) {
+ setAudioFormat(AudioFormat.ENCODING_PCM_FLOAT);
+ return true;
+ }
+ if (id == R.id.action_set_fixed_point) {
+ setAudioFormat(AudioFormat.ENCODING_PCM_16BIT);
+ return true;
+ }
if (id == R.id.action_enable_night_mode) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
return true;
diff --git a/app/src/main/res/menu/menu_main.xml b/app/src/main/res/menu/menu_main.xml
index 7130ce3..3628a32 100644
--- a/app/src/main/res/menu/menu_main.xml
+++ b/app/src/main/res/menu/menu_main.xml
@@ -174,6 +174,18 @@
+ -
+
+
- Videokamera
Spracherkennung
Unbearbeitet
+ Audioformat
+ Festkomma
+ Gleitkomma
Audioinitialisierung fehlgeschlagen
Audioeinrichtung fehlgeschlagen
Audioberechtigung verweigert
diff --git a/app/src/main/res/values-pt-rBR/strings.xml b/app/src/main/res/values-pt-rBR/strings.xml
index 88af49c..2f0eace 100755
--- a/app/src/main/res/values-pt-rBR/strings.xml
+++ b/app/src/main/res/values-pt-rBR/strings.xml
@@ -23,6 +23,9 @@
Filmadora
Reconhecimento de voz
Não processado
+ Formato de Áudio
+ Ponto Fixo
+ Ponto Flutuante
Falha ao iniciar o áudio
Falha na configuração de áudio
Permissão de áudio negada
diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml
index 2433575..7c9c9b5 100644
--- a/app/src/main/res/values-ru/strings.xml
+++ b/app/src/main/res/values-ru/strings.xml
@@ -23,6 +23,9 @@
Камера
Распознавание голоса
Необработанный
+ Аудио формат
+ Фиксированная точка
+ Плавающая точка
Ошибка инициализации аудио
Ошибка настройки аудио
Аудио - отказано в доступе
diff --git a/app/src/main/res/values-zh-rCN/strings.xml b/app/src/main/res/values-zh-rCN/strings.xml
index 00ef6e5..e111861 100644
--- a/app/src/main/res/values-zh-rCN/strings.xml
+++ b/app/src/main/res/values-zh-rCN/strings.xml
@@ -23,6 +23,9 @@
摄录机
音频识别
不处理
+ 音频格式
+ 定点数
+ 浮点数
初始化音频失败
音频设定失败
音频权限被拒绝
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 128ed6d..755d474 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -54,6 +54,9 @@
Camcorder
Voice Recognition
Unprocessed
+ Audio Format
+ Fixed Point
+ Floating Point
Audio init failed
Audio setup failed
Audio permission denied