diff --git a/app/src/main/java/com/dimowner/audiorecorder/AppConstants.java b/app/src/main/java/com/dimowner/audiorecorder/AppConstants.java
index b26e41ff..1d65c7f5 100755
--- a/app/src/main/java/com/dimowner/audiorecorder/AppConstants.java
+++ b/app/src/main/java/com/dimowner/audiorecorder/AppConstants.java
@@ -107,7 +107,8 @@ private AppConstants() {}
public static final int RECORD_SAMPLE_RATE_32000 = 32000;
public static final int RECORD_SAMPLE_RATE_48000 = 48000;
- public static final int RECORD_ENCODING_BITRATE_12000 = 12000; //Bitrate for 3gp format
+ public static final int RECORD_ENCODING_BITRATE_8000 = 8000;
+ public static final int RECORD_ENCODING_BITRATE_16000 = 16000;
public static final int RECORD_ENCODING_BITRATE_24000 = 24000;
public static final int RECORD_ENCODING_BITRATE_48000 = 48000;
public static final int RECORD_ENCODING_BITRATE_96000 = 96000;
diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/settings/SettingsActivity.java b/app/src/main/java/com/dimowner/audiorecorder/app/settings/SettingsActivity.java
index 323810f4..8d5d2c97 100644
--- a/app/src/main/java/com/dimowner/audiorecorder/app/settings/SettingsActivity.java
+++ b/app/src/main/java/com/dimowner/audiorecorder/app/settings/SettingsActivity.java
@@ -186,9 +186,12 @@ protected void onCreate(Bundle savedInstanceState) {
sampleRateSetting.setOnInfoClickListener(v -> AndroidUtils.showInfoDialog(SettingsActivity.this, R.string.info_frequency));
bitrateSetting = findViewById(R.id.setting_bitrate);
+
+
rates = getResources().getStringArray(R.array.bit_rates2);
rateKeys = new String[] {
-// SettingsMapper.BITRATE_24000,
+ SettingsMapper.BITRATE_8000,
+ SettingsMapper.BITRATE_16000,
SettingsMapper.BITRATE_48000,
SettingsMapper.BITRATE_96000,
SettingsMapper.BITRATE_128000,
@@ -196,6 +199,7 @@ protected void onCreate(Bundle savedInstanceState) {
SettingsMapper.BITRATE_256000,
};
bitrateSetting.setData(rates, rateKeys);
+
bitrateSetting.setOnChipCheckListener((key, name, checked) -> presenter.setSettingRecordingBitrate(SettingsMapper.keyToBitrate(key)));
bitrateSetting.setTitle(R.string.bitrate);
bitrateSetting.setOnInfoClickListener(v -> AndroidUtils.showInfoDialog(SettingsActivity.this, R.string.info_bitrate));
@@ -528,8 +532,14 @@ public void updateRecordingInfo(String format) {
if (format.equals(AppConstants.FORMAT_3GP)) {
channelsSetting.removeChip(new String[] {SettingsMapper.CHANNEL_COUNT_STEREO});
channelsSetting.setSelected(SettingsMapper.CHANNEL_COUNT_MONO);
+ final String[] rates = getResources().getStringArray(R.array.bit_rates);
+ bitrateSetting.setData(rates, rateKeys);
+ bitrateSetting.setSelected(SettingsMapper.BITRATE_16000);
} else {
channelsSetting.addChip(new String[] {SettingsMapper.CHANNEL_COUNT_STEREO}, new String[] {getString(R.string.stereo)});
+ final String[] rates = getResources().getStringArray(R.array.bit_rates2);
+ bitrateSetting.setData(rates, rateKeys);
+ bitrateSetting.setSelected(SettingsMapper.BITRATE_48000);
}
}
diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/settings/SettingsMapper.java b/app/src/main/java/com/dimowner/audiorecorder/app/settings/SettingsMapper.java
index 3bc041fe..2ebdb730 100644
--- a/app/src/main/java/com/dimowner/audiorecorder/app/settings/SettingsMapper.java
+++ b/app/src/main/java/com/dimowner/audiorecorder/app/settings/SettingsMapper.java
@@ -58,8 +58,8 @@ public SettingsMapper(Context context) {
public final static String SAMPLE_RATE_44100 = "44100";
public final static String SAMPLE_RATE_48000 = "48000";
- public final static String BITRATE_12000 = "12000";
-// public final static String BITRATE_24000 = "24000";
+ public final static String BITRATE_8000 = "8000";
+ public final static String BITRATE_16000 = "16000";
public final static String BITRATE_48000 = "48000";
public final static String BITRATE_96000 = "96000";
public final static String BITRATE_128000 = "128000";
@@ -233,8 +233,10 @@ public static String sampleRateToKey(int sampleRate) {
public static int keyToBitrate(String bitrateKey) {
switch (bitrateKey) {
-// case BITRATE_24000:
-// return AppConstants.RECORD_ENCODING_BITRATE_24000;
+ case BITRATE_8000:
+ return AppConstants.RECORD_ENCODING_BITRATE_8000;
+ case BITRATE_16000:
+ return AppConstants.RECORD_ENCODING_BITRATE_16000;
case BITRATE_48000:
return AppConstants.RECORD_ENCODING_BITRATE_48000;
case BITRATE_96000:
@@ -252,10 +254,10 @@ public static int keyToBitrate(String bitrateKey) {
public static String bitrateToKey(int bitrate) {
switch (bitrate) {
- case AppConstants.RECORD_ENCODING_BITRATE_12000:
- return BITRATE_12000;
-// case AppConstants.RECORD_ENCODING_BITRATE_24000:
-// return BITRATE_24000;
+ case AppConstants.RECORD_ENCODING_BITRATE_8000:
+ return BITRATE_8000;
+ case AppConstants.RECORD_ENCODING_BITRATE_16000:
+ return BITRATE_16000;
case AppConstants.RECORD_ENCODING_BITRATE_48000:
return BITRATE_48000;
case AppConstants.RECORD_ENCODING_BITRATE_96000:
diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/settings/SettingsPresenter.java b/app/src/main/java/com/dimowner/audiorecorder/app/settings/SettingsPresenter.java
index 66cbebcd..725cf4cf 100644
--- a/app/src/main/java/com/dimowner/audiorecorder/app/settings/SettingsPresenter.java
+++ b/app/src/main/java/com/dimowner/audiorecorder/app/settings/SettingsPresenter.java
@@ -266,46 +266,32 @@ private void updateAvailableSpace() {
final long space = FileUtil.getFree(fileRepository.getRecordingDir());
String format = prefs.getSettingRecordingFormat();
int sampleRate = prefs.getSettingSampleRate();
+
+ int channelsCount = prefs.getSettingChannelCount();
if (format.equals(AppConstants.FORMAT_3GP)) {
- if (view != null) {
- view.showAvailableSpace(
- TimeUtils.formatTimeIntervalHourMinSec(
- spaceToTimeSecs(space, format, sampleRate,
- AppConstants.RECORD_ENCODING_BITRATE_12000, AppConstants.RECORD_AUDIO_MONO)
- )
- );
- view.showSizePerMin(
- decimalFormat.format(
- sizePerMin(format, sampleRate, AppConstants.RECORD_ENCODING_BITRATE_12000,
- AppConstants.RECORD_AUDIO_MONO) / 1000000f
- )
- );
- view.showInformation(settingsMapper.convertFormatsToString(format) + AppConstants.SEPARATOR
- + settingsMapper.convertSampleRateToString(sampleRate) + AppConstants.SEPARATOR
- + settingsMapper.formatBitrate(AppConstants.RECORD_ENCODING_BITRATE_12000 / 1000) + AppConstants.SEPARATOR
- + settingsMapper.convertChannelsToString(AppConstants.RECORD_AUDIO_MONO));
- }
- } else {
- int bitrate = prefs.getSettingBitrate();
- int channelsCount = prefs.getSettingChannelCount();
- final long time = spaceToTimeSecs(space, format, sampleRate, bitrate, channelsCount);
- if (view != null) {
- view.showAvailableSpace(TimeUtils.formatTimeIntervalHourMinSec(time));
- view.showSizePerMin(decimalFormat.format(sizePerMin(format, sampleRate, bitrate, channelsCount) / 1000000f));
- switch (format) {
- default:
- case AppConstants.FORMAT_M4A:
- view.showInformation(settingsMapper.convertFormatsToString(format) + AppConstants.SEPARATOR
- + settingsMapper.convertSampleRateToString(sampleRate) + AppConstants.SEPARATOR
- + settingsMapper.convertBitratesToString(bitrate) + AppConstants.SEPARATOR
- + settingsMapper.convertChannelsToString(channelsCount));
- break;
- case AppConstants.FORMAT_WAV:
- view.showInformation(settingsMapper.convertFormatsToString(format) + AppConstants.SEPARATOR
- + settingsMapper.convertSampleRateToString(sampleRate) + AppConstants.SEPARATOR
- + settingsMapper.convertChannelsToString(channelsCount));
- break;
- }
+ channelsCount = 1;
+ }
+ int bitrate = prefs.getSettingBitrate();
+ if (format.equals(AppConstants.FORMAT_WAV)) {
+ bitrate = 1411 * channelsCount;
+ }
+ final long time = spaceToTimeSecs(space, format, sampleRate, bitrate, channelsCount);
+ if (view != null) {
+ view.showAvailableSpace(TimeUtils.formatTimeIntervalHourMinSec(time));
+ view.showSizePerMin(new DecimalFormat("#.##").format(sizePerMin(format, sampleRate, bitrate, channelsCount) / 1000000f));
+ switch (format) {
+ default:
+ case AppConstants.FORMAT_M4A:
+ view.showInformation(settingsMapper.convertFormatsToString(format) + AppConstants.SEPARATOR
+ + settingsMapper.convertSampleRateToString(sampleRate) + AppConstants.SEPARATOR
+ + settingsMapper.convertBitratesToString(bitrate) + AppConstants.SEPARATOR
+ + settingsMapper.convertChannelsToString(channelsCount));
+ break;
+ case AppConstants.FORMAT_WAV:
+ view.showInformation(settingsMapper.convertFormatsToString(format) + AppConstants.SEPARATOR
+ + settingsMapper.convertSampleRateToString(sampleRate) + AppConstants.SEPARATOR
+ + settingsMapper.convertChannelsToString(channelsCount));
+ break;
}
}
}
@@ -337,9 +323,9 @@ private long sizePerMin(String recordingFormat, int sampleRate, int bitrate, int
private void updateRecordingFormat(String formatKey) {
switch (formatKey) {
case AppConstants.FORMAT_WAV:
- case AppConstants.FORMAT_3GP:
view.hideBitrateSelector();
break;
+ case AppConstants.FORMAT_3GP:
case AppConstants.FORMAT_M4A:
default:
view.showBitrateSelector();
diff --git a/app/src/main/java/com/dimowner/audiorecorder/app/setup/SetupPresenter.java b/app/src/main/java/com/dimowner/audiorecorder/app/setup/SetupPresenter.java
index 78a16a0f..389c2240 100644
--- a/app/src/main/java/com/dimowner/audiorecorder/app/setup/SetupPresenter.java
+++ b/app/src/main/java/com/dimowner/audiorecorder/app/setup/SetupPresenter.java
@@ -229,7 +229,7 @@ private void updateSizePerMin() {
if (format.equals(AppConstants.FORMAT_3GP)) {
view.showSizePerMin(
decimalFormat.format(
- sizePerMin(format, sampleRate, AppConstants.RECORD_ENCODING_BITRATE_12000,
+ sizePerMin(format, sampleRate, AppConstants.RECORD_ENCODING_BITRATE_16000,
AppConstants.RECORD_AUDIO_MONO) / 1000000f
)
);
diff --git a/app/src/main/java/com/dimowner/audiorecorder/audio/recorder/ThreeGpRecorder.java b/app/src/main/java/com/dimowner/audiorecorder/audio/recorder/ThreeGpRecorder.java
index b97ae9f8..db524693 100644
--- a/app/src/main/java/com/dimowner/audiorecorder/audio/recorder/ThreeGpRecorder.java
+++ b/app/src/main/java/com/dimowner/audiorecorder/audio/recorder/ThreeGpRecorder.java
@@ -70,11 +70,8 @@ public void startRecording(String outputFile, int channelCount, int sampleRate,
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
- if (sampleRate > 8000) {
- recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_WB); //AMR_WR records with 16000 Hz frequency, ~23 kbps bitrate
- } else {
- recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); //AMR_NB records with 8000 Hz frequency, ~12 kbps bitrate
- }
+ recorder.setAudioEncoder(sampleRate == 8000 ? MediaRecorder.AudioEncoder.AMR_NB : MediaRecorder.AudioEncoder.AMR_WB);
+ recorder.setAudioEncodingBitRate(bitrate);
recorder.setMaxDuration(-1); //Duration unlimited or use RECORD_MAX_DURATION
recorder.setOutputFile(recordFile.getAbsolutePath());
try {
diff --git a/app/src/main/java/com/dimowner/audiorecorder/data/FileRepositoryImpl.java b/app/src/main/java/com/dimowner/audiorecorder/data/FileRepositoryImpl.java
index ee0b259b..5fcd6350 100644
--- a/app/src/main/java/com/dimowner/audiorecorder/data/FileRepositoryImpl.java
+++ b/app/src/main/java/com/dimowner/audiorecorder/data/FileRepositoryImpl.java
@@ -225,21 +225,11 @@ public boolean hasAvailableSpace(Context context) throws IllegalArgumentExceptio
space = FileUtil.getAvailableInternalMemorySize(context);
}
- final long time = spaceToTimeSecs(space, prefs.getSettingRecordingFormat(),
- prefs.getSettingSampleRate(), prefs.getSettingBitrate(), prefs.getSettingChannelCount());
+ final long time = spaceToTimeSecs(space, prefs.getSettingRecordingFormat(), prefs.getSettingBitrate(), prefs.getSettingChannelCount());
return time > AppConstants.MIN_REMAIN_RECORDING_TIME;
}
- private long spaceToTimeSecs(long spaceBytes, String recordingFormat, int sampleRate, int bitrate, int channels) {
- switch (recordingFormat) {
- case AppConstants.FORMAT_3GP:
- return 1000 * (spaceBytes/(AppConstants.RECORD_ENCODING_BITRATE_12000/8));
- case AppConstants.FORMAT_M4A:
- return 1000 * (spaceBytes/(bitrate/8));
- case AppConstants.FORMAT_WAV:
- return 1000 * (spaceBytes/(sampleRate * channels * 2));
- default:
- return 0;
- }
+ private long spaceToTimeSecs(long spaceBytes, String recordingFormat, int bitrate, int channels) {
+ return 1000 * (spaceBytes/(bitrate/8));
}
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 34581900..fff58408 100755
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -261,8 +261,14 @@
- 3gp
+
+ - 8 kbps
+ - 16 kbps
+
+
-
+ - 8 kbps
+ - 16 kbps
- 48 kbps
- 96 kbps
- 128 kbps