Skip to content

Commit

Permalink
update volume normalization for upcoming server API changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Chaphasilor committed Apr 29, 2024
1 parent d29bd8f commit 1aa454c
Show file tree
Hide file tree
Showing 15 changed files with 104 additions and 217 deletions.
Expand Up @@ -60,7 +60,7 @@ class AlbumScreenContentFlexibleSpaceBar extends StatelessWidget {
AppLocalizations.of(context)!.placeholderSource),
id: parentItem.id,
item: parentItem,
contextLufs: (isPlaylist || parentItem.lufs == 0.0) ? null : parentItem.lufs, // album LUFS sometimes end up being simply `0`, but that's not the actual value
contextNormalizationGain: (isPlaylist || parentItem.normalizationGain == 0.0) ? null : parentItem.normalizationGain, // album normalization gain sometimes ends up being simply `0`, but that's not the actual value
),
order: FinampPlaybackOrder.linear,
);
Expand All @@ -79,7 +79,7 @@ class AlbumScreenContentFlexibleSpaceBar extends StatelessWidget {
AppLocalizations.of(context)!.placeholderSource),
id: parentItem.id,
item: parentItem,
contextLufs: (isPlaylist || parentItem.lufs == 0.0) ? null : parentItem.lufs, // album LUFS sometimes end up being simply `0`, but that's not the actual value
contextNormalizationGain: (isPlaylist || parentItem.normalizationGain == 0.0) ? null : parentItem.normalizationGain, // album normalization gain sometimes ends up being simply `0`, but that's not the actual value
),
order: FinampPlaybackOrder.shuffled,
);
Expand All @@ -98,7 +98,7 @@ class AlbumScreenContentFlexibleSpaceBar extends StatelessWidget {
AppLocalizations.of(context)!.placeholderSource),
id: parentItem.id,
item: parentItem,
contextLufs: (isPlaylist || parentItem.lufs == 0.0) ? null : parentItem.lufs, // album LUFS sometimes end up being simply `0`, but that's not the actual value
contextNormalizationGain: (isPlaylist || parentItem.normalizationGain == 0.0) ? null : parentItem.normalizationGain, // album normalization gain sometimes ends up being simply `0`, but that's not the actual value
),
);
GlobalSnackbar.message((scaffold) => AppLocalizations.of(scaffold)!
Expand All @@ -118,7 +118,7 @@ class AlbumScreenContentFlexibleSpaceBar extends StatelessWidget {
AppLocalizations.of(context)!.placeholderSource),
id: parentItem.id,
item: parentItem,
contextLufs: (isPlaylist || parentItem.lufs == 0.0) ? null : parentItem.lufs, // album LUFS sometimes end up being simply `0`, but that's not the actual value
contextNormalizationGain: (isPlaylist || parentItem.normalizationGain == 0.0) ? null : parentItem.normalizationGain, // album normalization gain sometimes ends up being simply `0`, but that's not the actual value
));
GlobalSnackbar.message((scaffold) => AppLocalizations.of(scaffold)!
.confirmPlayNext(isPlaylist ? "playlist" : "album"), isConfirmation: true);
Expand All @@ -140,7 +140,7 @@ class AlbumScreenContentFlexibleSpaceBar extends StatelessWidget {
AppLocalizations.of(context)!.placeholderSource),
id: parentItem.id,
item: parentItem,
contextLufs: (isPlaylist || parentItem.lufs == 0.0) ? null : parentItem.lufs, // album LUFS sometimes end up being simply `0`, but that's not the actual value
contextNormalizationGain: (isPlaylist || parentItem.normalizationGain == 0.0) ? null : parentItem.normalizationGain, // album normalization gain sometimes ends up being simply `0`, but that's not the actual value
));
GlobalSnackbar.message((scaffold) => AppLocalizations.of(scaffold)!
.confirmShuffleToNextUp, isConfirmation: true);
Expand All @@ -162,7 +162,7 @@ class AlbumScreenContentFlexibleSpaceBar extends StatelessWidget {
AppLocalizations.of(context)!.placeholderSource),
id: parentItem.id,
item: parentItem,
contextLufs: (isPlaylist || parentItem.lufs == 0.0) ? null : parentItem.lufs, // album LUFS sometimes end up being simply `0`, but that's not the actual value
contextNormalizationGain: (isPlaylist || parentItem.normalizationGain == 0.0) ? null : parentItem.normalizationGain, // album normalization gain sometimes ends up being simply `0`, but that's not the actual value
));
GlobalSnackbar.message((scaffold) => AppLocalizations.of(scaffold)!
.confirmShuffleNext, isConfirmation: true);
Expand Down
10 changes: 5 additions & 5 deletions lib/components/AlbumScreen/song_list_tile.dart
Expand Up @@ -250,13 +250,13 @@ class _SongListTileState extends ConsumerState<SongListTile>
AppLocalizations.of(context)!.placeholderSource),
id: widget.parentItem?.id ?? "",
item: widget.parentItem,
// we're playing from an album, so we should use the album's LUFS.
// album LUFS sometimes end up being simply `0`, but that's not the actual value
contextLufs: (widget.isInPlaylist ||
// we're playing from an album, so we should use the album's normalization gain.
// album normalization gain sometimes ends up being simply `0`, but that's not the actual value
contextNormalizationGain: (widget.isInPlaylist ||
widget.isOnArtistScreen ||
widget.parentItem?.lufs == 0.0)
widget.parentItem?.normalizationGain == 0.0)
? null
: widget.parentItem?.lufs,
: widget.parentItem?.normalizationGain,
),
);
} else {
Expand Down
36 changes: 18 additions & 18 deletions lib/components/MusicScreen/album_item.dart
Expand Up @@ -370,11 +370,11 @@ class _AlbumItemState extends State<AlbumItem> {
mutableAlbum.name ?? local.placeholderSource),
id: mutableAlbum.id,
item: mutableAlbum,
contextLufs: (widget.isPlaylist ||
mutableAlbum.lufs == 0.0)
contextNormalizationGain: (widget.isPlaylist ||
mutableAlbum.normalizationGain == 0.0)
? null
: mutableAlbum
.lufs, // album LUFS sometimes end up being simply `0`, but that's not the actual value
.normalizationGain, // album normalization gain sometimes ends up being simply `0`, but that's not the actual value
));

GlobalSnackbar.message((scaffold) =>
Expand Down Expand Up @@ -417,11 +417,11 @@ class _AlbumItemState extends State<AlbumItem> {
mutableAlbum.name ?? local.placeholderSource),
id: mutableAlbum.id,
item: mutableAlbum,
contextLufs: (widget.isPlaylist ||
mutableAlbum.lufs == 0.0)
contextNormalizationGain: (widget.isPlaylist ||
mutableAlbum.normalizationGain == 0.0)
? null
: mutableAlbum
.lufs, // album LUFS sometimes end up being simply `0`, but that's not the actual value
.normalizationGain, // album normalization gain sometimes ends up being simply `0`, but that's not the actual value
));

GlobalSnackbar.message((scaffold) =>
Expand Down Expand Up @@ -465,11 +465,11 @@ class _AlbumItemState extends State<AlbumItem> {
mutableAlbum.name ?? local.placeholderSource),
id: mutableAlbum.id,
item: mutableAlbum,
contextLufs: (widget.isPlaylist ||
mutableAlbum.lufs == 0.0)
contextNormalizationGain: (widget.isPlaylist ||
mutableAlbum.normalizationGain == 0.0)
? null
: mutableAlbum
.lufs, // album LUFS sometimes end up being simply `0`, but that's not the actual value
.normalizationGain, // album normalization gain sometimes ends up being simply `0`, but that's not the actual value
));

GlobalSnackbar.message((scaffold) =>
Expand Down Expand Up @@ -513,11 +513,11 @@ class _AlbumItemState extends State<AlbumItem> {
mutableAlbum.name ?? local.placeholderSource),
id: mutableAlbum.id,
item: mutableAlbum,
contextLufs: (widget.isPlaylist ||
mutableAlbum.lufs == 0.0)
contextNormalizationGain: (widget.isPlaylist ||
mutableAlbum.normalizationGain == 0.0)
? null
: mutableAlbum
.lufs, // album LUFS sometimes end up being simply `0`, but that's not the actual value
.normalizationGain, // album normalization gain sometimes ends up being simply `0`, but that's not the actual value
));

GlobalSnackbar.message((scaffold) =>
Expand Down Expand Up @@ -560,11 +560,11 @@ class _AlbumItemState extends State<AlbumItem> {
mutableAlbum.name ?? local.placeholderSource),
id: mutableAlbum.id,
item: mutableAlbum,
contextLufs: (widget.isPlaylist ||
mutableAlbum.lufs == 0.0)
contextNormalizationGain: (widget.isPlaylist ||
mutableAlbum.normalizationGain == 0.0)
? null
: mutableAlbum
.lufs, // album LUFS sometimes end up being simply `0`, but that's not the actual value
.normalizationGain, // album normalization gain sometimes ends up being simply `0`, but that's not the actual value
));

GlobalSnackbar.message((scaffold) =>
Expand Down Expand Up @@ -608,11 +608,11 @@ class _AlbumItemState extends State<AlbumItem> {
mutableAlbum.name ?? local.placeholderSource),
id: mutableAlbum.id,
item: mutableAlbum,
contextLufs: (widget.isPlaylist ||
mutableAlbum.lufs == 0.0)
contextNormalizationGain: (widget.isPlaylist ||
mutableAlbum.normalizationGain == 0.0)
? null
: mutableAlbum
.lufs, // album LUFS sometimes end up being simply `0`, but that's not the actual value
.normalizationGain, // album normalization gain sometimes ends up being simply `0`, but that's not the actual value
));

GlobalSnackbar.message((scaffold) =>
Expand Down
12 changes: 12 additions & 0 deletions lib/components/PlayerScreen/feature_chips.dart
@@ -1,4 +1,5 @@
import 'package:finamp/models/finamp_models.dart';
import 'package:finamp/services/music_player_background_task.dart';
import 'package:finamp/services/queue_service.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
Expand Down Expand Up @@ -74,6 +75,17 @@ class FeatureState {

//TODO get codec information (from just_audio or Jellyfin)

if (FinampSettingsHelper.finampSettings.replayGainActive) {
double? effectiveGainChange = getEffectiveGainChange(currentTrack!.item, currentTrack!.baseItem);
if (effectiveGainChange != null) {
features.add(
FeatureProperties(
text: AppLocalizations.of(context)!.numberAsDecibel(effectiveGainChange),
),
);
}
}

return features;
}
}
Expand Down

This file was deleted.

This file was deleted.

28 changes: 11 additions & 17 deletions lib/l10n/app_en.arb
Expand Up @@ -951,26 +951,10 @@
"@replayGainSwitchTitle": {
"description": "Title for the switch that toggles replay gain"
},
"replayGainSwitchSubtitle": "Use LUFS information to normalize the loudness of songs",
"replayGainSwitchSubtitle": "Use normalization gain information to normalize the loudness of songs",
"@replayGainSwitchSubtitle": {
"description": "Subtitle for the switch that toggles replay gain"
},
"replayGainTargetLufsEditorTitle": "Replay Gain Target LUFS",
"@replayGainTargetLufsEditorTitle": {
"description": "Title for the input that sets the replay gain target LUFS"
},
"replayGainTargetLufsEditorSubtitle": "The target loudness (LUFS value) in decibels (dB) for replay gain to normalize to",
"@replayGainTargetLufsEditorSubtitle": {
"description": "Subtitle for the input that sets the replay gain target LUFS"
},
"replayGainNormalizationFactorEditorTitle": "Replay Gain Normalization Factor",
"@replayGainNormalizationFactorEditorTitle": {
"description": "Title for the input that sets the replay gain normalization factor"
},
"replayGainNormalizationFactorEditorSubtitle": "How much to normalize the volume by. Controls the 'aggressiveness' of the normalization.",
"@replayGainNormalizationFactorEditorSubtitle": {
"description": "Subtitle for the input that sets the replay gain normalization factor"
},
"replayGainModeSelectorTitle": "Replay Gain Mode",
"@replayGainModeSelectorTitle": {
"description": "Title for the dropdown that selects the replay gain mode"
Expand Down Expand Up @@ -1003,6 +987,16 @@
"@replayGainIOSBaseGainEditorSubtitle": {
"description": "Subtitle for the input that sets the replay gain base gain on iOS and other non-Android platforms"
},
"numberAsDecibel": "{value} dB",
"@numberAsDecibel": {
"description": "Label for a number that represents a decibel value. The value will be the decibel value.",
"placeholders": {
"value": {
"type": "double",
"example": "-9.6"
}
}
},
"swipeInsertQueueNext": "Play Swiped Song Next",
"@swipeInsertQueueNext": {},
"swipeInsertQueueNextSubtitle": "Enable to insert a song as next item in queue when swiped in song list instead of appending it to the end.",
Expand Down
20 changes: 5 additions & 15 deletions lib/models/finamp_models.dart
Expand Up @@ -65,12 +65,10 @@ const _isFavouriteDefault = false;
const _songShuffleItemCountDefault = 250;
const _replayGainActiveDefault = true;
// 3/4 volume in dB. In my testing, most tracks were louder than the default target
// of -14.0 LUFS, so the gain rarely needed to be increased. -5.0 gives us a bit of
// of -14.0 normalization gain, so the gain rarely needed to be increased. -5.0 gives us a bit of
// headroom in case we need to boost a track (since volume can't go above 1.0),
// without reducing the volume too much.
const _replayGainIOSBaseGainDefault = -5.0;
const _replayGainTargetLufsDefault = -14.0;
const _replayGainNormalizationFactorDefault = 1.0;
const _replayGainModeDefault = ReplayGainMode.hybrid;
const _contentViewType = ContentViewType.list;
const _contentGridViewCrossAxisCountPortrait = 2;
Expand Down Expand Up @@ -117,8 +115,6 @@ class FinampSettings {
this.songShuffleItemCount = _songShuffleItemCountDefault,
this.replayGainActive = _replayGainActiveDefault,
this.replayGainIOSBaseGain = _replayGainIOSBaseGainDefault,
this.replayGainTargetLufs = _replayGainTargetLufsDefault,
this.replayGainNormalizationFactor = _replayGainNormalizationFactorDefault,
this.replayGainMode = _replayGainModeDefault,
this.contentViewType = _contentViewType,
this.contentGridViewCrossAxisCountPortrait =
Expand Down Expand Up @@ -273,12 +269,6 @@ class FinampSettings {
@HiveField(30, defaultValue: _replayGainIOSBaseGainDefault)
double replayGainIOSBaseGain;

@HiveField(31, defaultValue: _replayGainTargetLufsDefault)
double replayGainTargetLufs;

@HiveField(32, defaultValue: _replayGainNormalizationFactorDefault)
double replayGainNormalizationFactor;

@HiveField(33, defaultValue: _replayGainModeDefault)
ReplayGainMode replayGainMode;

Expand Down Expand Up @@ -1304,7 +1294,7 @@ class QueueItemSource {
required this.name,
required this.id,
this.item,
this.contextLufs,
this.contextNormalizationGain,
});

@HiveField(0)
Expand All @@ -1320,7 +1310,7 @@ class QueueItemSource {
BaseItemDto? item;

@HiveField(4)
double? contextLufs;
double? contextNormalizationGain;
}

@HiveType(typeId: 55)
Expand Down Expand Up @@ -1578,11 +1568,11 @@ enum SavedQueueState {

/// Describes which mode will be used for loudness normalization.
enum ReplayGainMode {
/// Use track LUFS if playing unrelated tracks, use album LUFS if playing albums
/// Use track normalization gain if playing unrelated tracks, use album normalization gain if playing albums
@HiveField(0)
hybrid,

/// Use track LUFS regardless of context
/// Use track normalization gain regardless of context
@HiveField(1)
trackOnly,

Expand Down

0 comments on commit 1aa454c

Please sign in to comment.