fix: Remove ForceExactMaxDuration

This commit is contained in:
Myzel394 2023-11-19 17:51:04 +01:00
parent 0364a79dcb
commit 703e783193
No known key found for this signature in database
GPG Key ID: 79CC92F37B3E1A2B
7 changed files with 4 additions and 76 deletions

View File

@ -76,7 +76,6 @@ data class RecordingInformation(
val maxDuration: Long,
val intervalDuration: Long,
val fileExtension: String,
val forceExactMaxDuration: Boolean,
) {
val hasRecordingsAvailable
get() = File(folderPath).listFiles()?.isNotEmpty() ?: false
@ -88,7 +87,6 @@ data class AudioRecorderSettings(
val maxDuration: Long = 30 * 60 * 1000L,
// 60 seconds
val intervalDuration: Long = 60 * 1000L,
val forceExactMaxDuration: Boolean = true,
// 320 Kbps
val bitRate: Int = 320000,
val samplingRate: Int? = null,
@ -238,10 +236,6 @@ data class AudioRecorderSettings(
return copy(maxDuration = duration)
}
fun setForceExactMaxDuration(forceExactMaxDuration: Boolean): AudioRecorderSettings {
return copy(forceExactMaxDuration = forceExactMaxDuration)
}
fun setShowAllMicrophones(showAllMicrophones: Boolean): AudioRecorderSettings {
return copy(showAllMicrophones = showAllMicrophones)
}

View File

@ -17,12 +17,11 @@ data class AudioRecorderExporter(
val recording: RecordingInformation,
) {
suspend fun concatenateFiles(
context: Context,
batchesFolder: BatchesFolder,
outputFilePath: String,
forceConcatenation: Boolean = false,
) {
val filePaths = batchesFolder.getBatchesForFFmpeg().joinToString("|")
val filePaths = batchesFolder.getBatchesForFFmpeg()
if (batchesFolder.checkIfOutputAlreadyExists(
recording.recordingStart,
@ -32,12 +31,13 @@ data class AudioRecorderExporter(
return
}
val filePathsConcatenated = filePaths.joinToString("|")
val command =
"-protocol_whitelist saf,concat,content,file,subfile" +
" -i 'concat:${filePaths}' -y" +
" -i 'concat:$filePathsConcatenated' -y" +
" -acodec copy" +
" -metadata date='${recording.recordingStart.format(DateTimeFormatter.ISO_DATE_TIME)}'" +
" -metadata batch_count='${filePaths.length}'" +
" -metadata batch_count='${filePaths.size}'" +
" -metadata batch_duration='${recording.intervalDuration}'" +
" -metadata max_duration='${recording.maxDuration}'" +
" $outputFilePath"
@ -57,9 +57,6 @@ data class AudioRecorderExporter(
throw Exception("Failed to concatenate audios")
}
val minRequiredForPossibleInExactMaxDuration =
recording.maxDuration / recording.intervalDuration
}
companion object {

View File

@ -40,7 +40,6 @@ abstract class IntervalRecorderService : ExtraRecorderInformationService() {
maxDuration = settings.maxDuration,
fileExtension = settings.fileExtension,
intervalDuration = settings.intervalDuration,
forceExactMaxDuration = settings.forceExactMaxDuration,
)
// Make overrideable
@ -106,7 +105,6 @@ abstract class IntervalRecorderService : ExtraRecorderInformationService() {
data class Settings(
val maxDuration: Long,
val intervalDuration: Long,
val forceExactMaxDuration: Boolean,
val bitRate: Int,
val samplingRate: Int,
val outputFormat: Int,
@ -135,7 +133,6 @@ abstract class IntervalRecorderService : ExtraRecorderInformationService() {
outputFormat = audioRecorderSettings.getOutputFormat(),
encoder = audioRecorderSettings.getEncoder(),
maxDuration = audioRecorderSettings.maxDuration,
forceExactMaxDuration = audioRecorderSettings.forceExactMaxDuration,
)
}
}

View File

@ -1,54 +0,0 @@
package app.myzel394.alibi.ui.components.SettingsScreen.atoms
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.GraphicEq
import androidx.compose.material3.Icon
import androidx.compose.material3.Switch
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import app.myzel394.alibi.R
import app.myzel394.alibi.dataStore
import app.myzel394.alibi.db.AppSettings
import app.myzel394.alibi.ui.components.atoms.SettingsTile
import com.maxkeppeker.sheets.core.models.base.rememberUseCaseState
import kotlinx.coroutines.launch
@Composable
fun ForceExactMaxDurationTile(
settings: AppSettings,
) {
val scope = rememberCoroutineScope()
val dataStore = LocalContext.current.dataStore
fun updateValue(forceExactMaxDuration: Boolean) {
scope.launch {
dataStore.updateData {
it.setAudioRecorderSettings(
it.audioRecorderSettings.setForceExactMaxDuration(forceExactMaxDuration)
)
}
}
}
SettingsTile(
title = stringResource(R.string.ui_settings_option_forceExactDuration_title),
description = stringResource(R.string.ui_settings_option_forceExactDuration_description),
leading = {
Icon(
Icons.Default.GraphicEq,
contentDescription = null,
)
},
trailing = {
Switch(
checked = settings.audioRecorderSettings.forceExactMaxDuration,
onCheckedChange = ::updateValue,
)
},
)
}

View File

@ -136,7 +136,6 @@ fun AudioRecorderScreen(
)
AudioRecorderExporter(recording).concatenateFiles(
context,
audioRecorder.recorderService!!.batchesFolder,
outputFile,
)

View File

@ -37,14 +37,12 @@ import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import app.myzel394.alibi.R
import app.myzel394.alibi.dataStore
import app.myzel394.alibi.db.AppSettings
import app.myzel394.alibi.ui.SUPPORTS_DARK_MODE_NATIVELY
import app.myzel394.alibi.ui.components.SettingsScreen.atoms.AboutTile
import app.myzel394.alibi.ui.components.SettingsScreen.atoms.BitrateTile
import app.myzel394.alibi.ui.components.SettingsScreen.atoms.CustomNotificationTile
import app.myzel394.alibi.ui.components.SettingsScreen.atoms.DeleteRecordingsImmediatelyTile
import app.myzel394.alibi.ui.components.SettingsScreen.atoms.EncoderTile
import app.myzel394.alibi.ui.components.SettingsScreen.atoms.ForceExactMaxDurationTile
import app.myzel394.alibi.ui.components.SettingsScreen.atoms.ImportExport
import app.myzel394.alibi.ui.components.SettingsScreen.atoms.InAppLanguagePicker
import app.myzel394.alibi.ui.components.SettingsScreen.atoms.IntervalDurationTile
@ -146,7 +144,6 @@ fun SettingsScreen(
)
MaxDurationTile(settings = settings)
IntervalDurationTile(settings = settings)
ForceExactMaxDurationTile(settings = settings)
InAppLanguagePicker()
DeleteRecordingsImmediatelyTile(settings = settings)
CustomNotificationTile(navController = navController, settings = settings)

View File

@ -39,8 +39,6 @@
<string name="ui_settings_option_maxDuration_description">Set the maximum duration of the recording</string>
<string name="ui_settings_option_intervalDuration_title">Batch duration</string>
<string name="ui_settings_option_intervalDuration_description">Record a single batch for this duration. Alibi records multiple batches and deletes the oldest one. When exporting the audio, all batches will be merged together</string>
<string name="ui_settings_option_forceExactDuration_title">Force exact duration</string>
<string name="ui_settings_option_forceExactDuration_description">Force to strip the output file to be the exactly specified duration. If this is disabled, the output file may be a bit longer due to batches of audio samples being encoded together.</string>
<string name="ui_settings_option_bitrate_title">Bitrate</string>
<string name="ui_settings_option_bitrate_description">A higher bitrate means better quality but also larger file size</string>
<string name="ui_settings_option_bitrate_explanation">Set the bitrate for the audio recording</string>