mirror of
https://github.com/zarzet/SpotiFLAC-Mobile.git
synced 2026-07-29 15:28:48 +02:00
feat(convert): support same-format lossless re-encoding
This commit is contained in:
@@ -220,26 +220,14 @@ extension _TrackMetadataConvertAndCueSplit on _TrackMetadataScreenState {
|
||||
final currentFormat = _currentFileFormat;
|
||||
final isLosslessSource = isLosslessConversionSource(currentFormat);
|
||||
|
||||
final formats = <String>[];
|
||||
if (currentFormat == 'FLAC') {
|
||||
formats.addAll(['ALAC', 'WAV', 'AIFF', 'AAC', 'MP3', 'Opus']);
|
||||
} else if (currentFormat == 'ALAC') {
|
||||
formats.addAll(['FLAC', 'WAV', 'AIFF', 'AAC', 'MP3', 'Opus']);
|
||||
} else if (currentFormat == 'M4A') {
|
||||
formats.addAll(['ALAC', 'FLAC', 'WAV', 'AIFF', 'AAC', 'MP3', 'Opus']);
|
||||
} else if (currentFormat == 'WAV') {
|
||||
formats.addAll(['FLAC', 'ALAC', 'AIFF', 'AAC', 'MP3', 'Opus']);
|
||||
} else if (currentFormat == 'AIFF') {
|
||||
formats.addAll(['FLAC', 'ALAC', 'WAV', 'AAC', 'MP3', 'Opus']);
|
||||
} else if (currentFormat == 'AAC') {
|
||||
formats.addAll(['MP3', 'Opus']);
|
||||
} else if (currentFormat == 'MP3') {
|
||||
formats.addAll(['AAC', 'Opus']);
|
||||
} else if (currentFormat == 'Opus') {
|
||||
formats.addAll(['AAC', 'MP3']);
|
||||
} else {
|
||||
formats.addAll(['AAC', 'MP3', 'Opus']);
|
||||
}
|
||||
final formats = audioConversionTargetFormats
|
||||
.where(
|
||||
(target) => canConvertAudioFormat(
|
||||
sourceFormat: currentFormat,
|
||||
targetFormat: target,
|
||||
),
|
||||
)
|
||||
.toList(growable: false);
|
||||
|
||||
final labels = context.l10n.losslessConversionLabels;
|
||||
|
||||
@@ -922,9 +910,7 @@ extension _TrackMetadataConvertAndCueSplit on _TrackMetadataScreenState {
|
||||
newPath,
|
||||
);
|
||||
if (convertedMetadata['error'] == null) {
|
||||
convertedBitDepth = readPositiveInt(
|
||||
convertedMetadata['bit_depth'],
|
||||
);
|
||||
convertedBitDepth = readPositiveInt(convertedMetadata['bit_depth']);
|
||||
convertedSampleRate = readPositiveInt(
|
||||
convertedMetadata['sample_rate'],
|
||||
);
|
||||
@@ -1134,5 +1120,4 @@ extension _TrackMetadataConvertAndCueSplit on _TrackMetadataScreenState {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -128,8 +128,13 @@ bool canConvertAudioFormat({
|
||||
required String sourceFormat,
|
||||
required String targetFormat,
|
||||
}) {
|
||||
if (sourceFormat.trim().toUpperCase() == targetFormat.trim().toUpperCase()) {
|
||||
return false;
|
||||
final normalizedSource = sourceFormat.trim().toUpperCase();
|
||||
final normalizedTarget = targetFormat.trim().toUpperCase();
|
||||
if (normalizedSource == normalizedTarget) {
|
||||
// Same-format lossless re-encoding is useful for reducing bit depth or
|
||||
// sample rate while selecting the dither and resampler implementation.
|
||||
return isLosslessConversionSource(normalizedSource) &&
|
||||
isLosslessConversionTarget(normalizedTarget);
|
||||
}
|
||||
if (isLosslessConversionTarget(targetFormat) &&
|
||||
!isLosslessConversionSource(sourceFormat)) {
|
||||
|
||||
Reference in New Issue
Block a user