add audioformat pref

This commit is contained in:
Alexey Kuznetsov 2022-02-27 12:16:25 +03:00
commit b8a1268c20
8 changed files with 32 additions and 7 deletions

View file

@ -40,6 +40,7 @@ import com.github.axet.androidlibrary.widgets.ErrorDialog;
import com.github.axet.androidlibrary.widgets.OpenFileDialog;
import com.github.axet.androidlibrary.widgets.SearchView;
import com.github.axet.audiolibrary.app.RawSamples;
import com.github.axet.audiolibrary.app.Sound;
import com.github.axet.audiolibrary.encoders.FormatWAV;
import com.github.axet.audiorecorder.R;
import com.github.axet.audiorecorder.app.AudioApplication;
@ -663,7 +664,7 @@ public class MainActivity extends AppCompatThemeActivity {
void updateHeader() {
Uri uri = storage.getStoragePath();
long free = Storage.getFree(this, uri);
long sec = Storage.average(this, free);
long sec = Storage.average(this, Sound.getAudioFormat(this), free);
TextView text = (TextView) findViewById(R.id.space_left);
text.setText(AudioApplication.formatFree(this, free, sec));
}

View file

@ -519,7 +519,7 @@ public class RecordingActivity extends AppCompatThemeActivity {
editor.commit();
}
Log.d(TAG, "create recording at: " + targetUri);
app.recording = new RecordingStorage(this, pitch.getPitchTime(), targetUri);
app.recording = new RecordingStorage(this, Sound.getAudioFormat(this), pitch.getPitchTime(), targetUri);
}
recording = app.recording;
synchronized (recording.handlers) {
@ -754,7 +754,7 @@ public class RecordingActivity extends AppCompatThemeActivity {
String ext = shared.getString(AudioApplication.PREFERENCE_ENCODING, "");
if (shared.getBoolean(AudioApplication.PREFERENCE_FLY, false)) {
perSec = Factory.getEncoderRate(ext, recording.sampleRate);
perSec = Factory.getEncoderRate(Sound.getAudioFormat(this), ext, recording.sampleRate);
try {
free = Storage.getFree(this, recording.targetUri);
} catch (RuntimeException e) { // IllegalArgumentException

View file

@ -99,7 +99,7 @@ public class SettingsActivity extends AppCompatSettingsThemeActivity implements
storage.migrateLocalStorageDialog(this);
if (key.equals(AudioApplication.PREFERENCE_RATE)) {
int sampleRate = Integer.parseInt(sharedPreferences.getString(AudioApplication.PREFERENCE_RATE, ""));
if (sampleRate != Sound.getValidRecordRate(Sound.getInMode(this), sampleRate))
if (sampleRate != Sound.getValidRecordRate(Sound.getAudioFormat(this), Sound.getInMode(this), sampleRate))
Toast.Text(this, "Not supported Hz");
}
}
@ -163,6 +163,7 @@ public class SettingsActivity extends AppCompatSettingsThemeActivity implements
bindPreferenceSummaryToValue(pm.findPreference(AudioApplication.PREFERENCE_CHANNELS));
bindPreferenceSummaryToValue(pm.findPreference(AudioApplication.PREFERENCE_FORMAT));
bindPreferenceSummaryToValue(pm.findPreference(AudioApplication.PREFERENCE_VOLUME));
bindPreferenceSummaryToValue(pm.findPreference(AudioApplication.PREFERENCE_AUDIOFORMAT));
StoragePathPreferenceCompat s = (StoragePathPreferenceCompat) pm.findPreference(AudioApplication.PREFERENCE_STORAGE);
s.setStorage(new Storage(getContext()));

View file

@ -66,7 +66,7 @@ public class RecordingStorage {
public int pitchTime; // screen width
public RecordingStorage(Context context, int pitchTime, Uri targetUri) {
public RecordingStorage(Context context, int format, int pitchTime, Uri targetUri) {
this.context = context;
this.pitchTime = pitchTime;
this.targetUri = targetUri;
@ -75,7 +75,7 @@ public class RecordingStorage {
sampleRate = Sound.getSampleRate(context);
samplesUpdate = (int) (pitchTime * sampleRate / 1000f);
samplesUpdateStereo = samplesUpdate * Sound.getChannels(context);
info = new RawSamples.Info(sampleRate, Sound.getChannels(context));
info = new RawSamples.Info(format, sampleRate, Sound.getChannels(context));
}
public void startRecording(int source) {

View file

@ -27,6 +27,7 @@ import com.github.axet.androidlibrary.services.PersistentService;
import com.github.axet.androidlibrary.widgets.NotificationChannelCompat;
import com.github.axet.androidlibrary.widgets.RemoteNotificationCompat;
import com.github.axet.androidlibrary.widgets.RemoteViewsCompat;
import com.github.axet.audiolibrary.app.Sound;
import com.github.axet.audiolibrary.app.Storage;
import com.github.axet.audiorecorder.R;
import com.github.axet.audiorecorder.activities.MainActivity;
@ -128,7 +129,7 @@ public class ControlsService extends PersistentService {
title = getString(R.string.app_name);
Uri f = storage.getStoragePath();
long free = Storage.getFree(context, f);
long sec = Storage.average(context, free);
long sec = Storage.average(context, Sound.getAudioFormat(context), free);
text = AudioApplication.formatFree(context, free, sec);
builder = new RemoteNotificationCompat.Low(context, R.layout.notifictaion);
builder.setViewVisibility(R.id.notification_record, View.VISIBLE);

View file

@ -6,6 +6,8 @@ import android.content.res.TypedArray;
import android.os.Build;
import android.preference.PreferenceManager;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.ListPreferenceDialogFragmentCompat;
import android.support.v7.preference.PreferenceViewHolder;
import android.util.AttributeSet;
import com.github.axet.audiolibrary.app.Sound;

View file

@ -26,6 +26,16 @@
<item>@string/source_internal</item>
</string-array>
<string-array name="audioformat_text">
<item>16-bit PCM</item>
<item>24-bit PCM (float)</item>
</string-array>
<string-array name="audioformat_values" translatable="false">
<item>16</item>
<item>float</item>
</string-array>
<string-array name="themes_values" translatable="false">
<item>@string/Theme_Light</item>
<item>@string/Theme_Dark</item>

View file

@ -7,6 +7,16 @@
android:summary="/sdcard/some/"
android:title="@string/pref_storage_title" />
<ListPreference
android:defaultValue="16"
android:entries="@array/audioformat_text"
android:entryValues="@array/audioformat_values"
android:key="audioformat"
android:negativeButtonText="@null"
android:positiveButtonText="@null"
android:summary=""
android:title="Audio Format" />
<com.github.axet.audiorecorder.widgets.RecordingSourcePreferenceCompat
android:defaultValue="mic"
android:entries="@array/source_text"