Merge branch 'audiorecorder-3.5.4'

This commit is contained in:
Alexey Kuznetsov 2022-03-01 21:21:45 +03:00
commit 07e51485ac
10 changed files with 70 additions and 31 deletions

View file

@ -9,8 +9,8 @@ android {
applicationId "com.github.axet.audiorecorder"
minSdkVersion 9
targetSdkVersion 30
versionCode 359
versionName "3.5.3"
versionCode 360
versionName "3.5.4"
}
signingConfigs {
release {
@ -53,7 +53,7 @@ android {
dependencies {
testImplementation 'junit:junit:4.12'
implementation ('com.github.axet:android-audio-library:1.1.5') // implementation project(':android-audio-library')
implementation ('com.github.axet:android-audio-library:1.1.6') // implementation project(':android-audio-library')
implementation ('com.github.axet:wget:1.7.0') { exclude group: 'org.json', module: 'json' }
assets('com.google.android.exoplayer:exoplayer:2.7.3') { exclude group: 'com.android.support' }
}

View file

@ -929,14 +929,14 @@ public class RecordingActivity extends AppCompatThemeActivity {
boolean startRecording() {
try {
final SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this);
String source = shared.getString(AudioApplication.PREFERENCE_SOURCE, getString(R.string.source_mic));
String source = shared.getString(AudioApplication.PREFERENCE_SOURCE, AudioApplication.PREFERENCE_SOURCE_MIC);
int user;
if (source.equals(getString(R.string.source_raw))) {
if (source.equals(AudioApplication.PREFERENCE_SOURCE_RAW)) {
if (Sound.isUnprocessedSupported(this))
user = MediaRecorder.AudioSource.UNPROCESSED;
else
user = MediaRecorder.AudioSource.VOICE_RECOGNITION;
} else if (source.equals(this.getString(R.string.source_internal))) {
} else if (source.equals(AudioApplication.PREFERENCE_SOURCE_INTERNAL)) {
user = Sound.SOURCE_INTERNAL_AUDIO;
} else {
user = MediaRecorder.AudioSource.MIC;

View file

@ -138,25 +138,6 @@ public class SettingsActivity extends AppCompatSettingsThemeActivity implements
void initPrefs(PreferenceManager pm, PreferenceScreen screen) {
final Context context = screen.getContext();
ListPreference enc = (ListPreference) pm.findPreference(AudioApplication.PREFERENCE_ENCODING);
String v = enc.getValue();
CharSequence[] ee = Factory.getEncodingTexts(context);
CharSequence[] vv = Factory.getEncodingValues(context);
if (ee.length > 1) {
enc.setEntries(ee);
enc.setEntryValues(vv);
int i = enc.findIndexOfValue(v);
if (i == -1) {
enc.setValueIndex(0);
} else {
enc.setValueIndex(i);
}
bindPreferenceSummaryToValue(enc);
} else {
screen.removePreference(enc);
}
bindPreferenceSummaryToValue(pm.findPreference(AudioApplication.PREFERENCE_RATE));
bindPreferenceSummaryToValue(pm.findPreference(AudioApplication.PREFERENCE_THEME));

View file

@ -11,6 +11,7 @@ import android.util.Log;
import android.view.View;
import com.github.axet.androidlibrary.app.NotificationManagerCompat;
import com.github.axet.androidlibrary.app.Prefs;
import com.github.axet.androidlibrary.widgets.NotificationChannelCompat;
import com.github.axet.androidlibrary.widgets.RemoteNotificationCompat;
import com.github.axet.audiolibrary.encoders.FormatFLAC;
@ -26,6 +27,10 @@ public class AudioApplication extends com.github.axet.audiolibrary.app.MainAppli
public static final String PREFERENCE_TARGET = "target";
public static final String PREFERENCE_FLY = "fly";
public static final String PREFERENCE_SOURCE = "bluetooth";
public static final String PREFERENCE_SOURCE_MIC = Prefs.PrefString(R.string.source_mic);
public static final String PREFERENCE_SOURCE_BLUETOOTH = Prefs.PrefString(R.string.source_bluetooth);
public static final String PREFERENCE_SOURCE_RAW = Prefs.PrefString(R.string.source_raw);
public static final String PREFERENCE_SOURCE_INTERNAL = Prefs.PrefString(R.string.source_internal);
public static final String PREFERENCE_VERSION = "version";

View file

@ -84,7 +84,17 @@ public class EncodingStorage extends HashMap<File, EncodingStorage.Info> {
public void load() {
clear();
File storage = this.storage.getTempRecording().getParentFile();
load(storage.getTempEncoding().getParentFile());
Context context = storage.getContext();
load(context.getCacheDir());
load(context.getExternalCacheDir());
load(Storage.getFilesDir(context, Storage.RAW));
load(context.getExternalFilesDir(Storage.RAW));
}
public void load(File storage) {
if (storage == null)
return;
File[] ff = storage.listFiles(new FilenameFilter() {
String start = Storage.getNameNoExt(Storage.TMP_ENC);
String ext = "." + Storage.getExt(Storage.TMP_ENC);

View file

@ -139,7 +139,7 @@ public class BluetoothReceiver extends BroadcastReceiver {
public boolean isRecordingReady() {
final SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(context);
if (shared.getString(AudioApplication.PREFERENCE_SOURCE, context.getString(R.string.source_mic)).equals(context.getString(R.string.source_bluetooth))) {
if (shared.getString(AudioApplication.PREFERENCE_SOURCE, AudioApplication.PREFERENCE_SOURCE_MIC).equals(AudioApplication.PREFERENCE_SOURCE_BLUETOOTH)) {
bluetoothSource = true;
if (!startBluetooth())
return false;

View file

@ -55,8 +55,8 @@ public class RecordingSourcePreferenceCompat extends ListPreference {
CharSequence[] values = getEntryValues();
ArrayList<CharSequence> tt = new ArrayList<>();
ArrayList<CharSequence> vv = new ArrayList<>();
String raw = getContext().getString(R.string.source_raw);
String internal = getContext().getString(R.string.source_internal);
String raw = AudioApplication.PREFERENCE_SOURCE_RAW;
String internal = AudioApplication.PREFERENCE_SOURCE_INTERNAL;
for (int i = 0; i < values.length; i++) {
String v = values[i].toString();
String t = text[i].toString();

View file

@ -37,7 +37,7 @@
android:summary="44100"
android:title="@string/pref_rate_title" />
<ListPreference
<com.github.axet.audiolibrary.widgets.EncodingsPreferenceCompat
android:defaultValue="ogg"
android:entries="@array/encodings_text"
android:entryValues="@array/encodings_values"

View file

@ -32,11 +32,17 @@ For example:
# Raw format
* Signed 16-bit PCM
* Signed 16-bit PCM or float (depends on user settings)
* Big Endian
* 1 or 2 channels (depends on user settings). First 2 bytes for left channel, Second 2 bytes for right channel.
* 16hz to 48hz Sample Rate / Frequincy (depends on user settings)
Android supports 16-bit PCM format or PCM float. Android recomends to use PCM float over 24-bit PCM format or 16-bit PCM if possible.
* https://developer.android.com/reference/android/media/AudioFormat#encoding
float mantisa is 23 bits (plus sign bit and float point bits) persition in range from -1..1 can hold about 2130706431 unique numbers which is equivalent to 31 bits integer. When 24-bit PCM only gives you 2^24=16,777,216 unique values.
# Adb commands
# adb shell am start -n com.github.axet.audiorecorder/.activities.RecordingActivity

37
docs/float.py Normal file
View file

@ -0,0 +1,37 @@
#
# simple float test to calculate float unique numbers in range from -1..1
#
# output:
#
# 1 -0.99999994
# 2 -0.9999999
# 3 -0.9999998
# 4 -0.99999976
# 5 -0.9999997
# 6 -0.99999964
# 7 -0.9999996
# 8 -0.9999995
# 9 -0.99999946
# 10 -0.9999994
# ...
# 2130706425 0.9999996
# 2130706426 0.99999964
# 2130706427 0.9999997
# 2130706428 0.99999976
# 2130706429 0.9999998
# 2130706430 0.9999999
# 2130706431 0.99999994
# 2130706432 1.0
#
import numpy as np
i = 0
f = np.float32(-1.)
while ( f < 1. ):
f = np.nextafter(f, np.float32(2))
i += 1
print(i, f)
type(f)