diff --git a/app/src/androidTest/java/de/test/antennapod/ui/FeedSettingsTest.java b/app/src/androidTest/java/de/test/antennapod/ui/FeedSettingsTest.java index 861c62f1b..187c9e16d 100644 --- a/app/src/androidTest/java/de/test/antennapod/ui/FeedSettingsTest.java +++ b/app/src/androidTest/java/de/test/antennapod/ui/FeedSettingsTest.java @@ -73,7 +73,7 @@ public class FeedSettingsTest { clickPreference(R.string.auto_delete_label); onView(withText(R.string.cancel_label)).perform(click()); - clickPreference(R.string.feed_volume_reduction); + clickPreference(R.string.feed_volume_adapdation); onView(withText(R.string.cancel_label)).perform(click()); } } diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java index ae9e003d5..0e4c883cf 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/FeedSettingsFragment.java @@ -156,7 +156,7 @@ public class FeedSettingsFragment extends Fragment { setupAutoDownloadPreference(); setupKeepUpdatedPreference(); setupAutoDeletePreference(); - setupVolumeReductionPreferences(); + setupVolumeAdaptationPreferences(); setupNewEpisodesAction(); setupAuthentificationPreference(); setupEpisodeFilterPreference(); @@ -166,7 +166,7 @@ public class FeedSettingsFragment extends Fragment { setupTags(); updateAutoDeleteSummary(); - updateVolumeReductionValue(); + updateVolumeAdaptationValue(); updateAutoDownloadEnabled(); updateNewEpisodesAction(); @@ -317,9 +317,9 @@ public class FeedSettingsFragment extends Fragment { } } - private void setupVolumeReductionPreferences() { - ListPreference volumeReductionPreference = findPreference("volumeReduction"); - volumeReductionPreference.setOnPreferenceChangeListener((preference, newValue) -> { + private void setupVolumeAdaptationPreferences() { + ListPreference volumeAdaptationPreference = findPreference("volumeReduction"); + volumeAdaptationPreference.setOnPreferenceChangeListener((preference, newValue) -> { switch ((String) newValue) { case "off": feedPreferences.setVolumeAdaptionSetting(VolumeAdaptionSetting.OFF); @@ -330,28 +330,46 @@ public class FeedSettingsFragment extends Fragment { case "heavy": feedPreferences.setVolumeAdaptionSetting(VolumeAdaptionSetting.HEAVY_REDUCTION); break; + case "light_boost": + feedPreferences.setVolumeAdaptionSetting(VolumeAdaptionSetting.LIGHT_BOOST); + break; + case "medium_boost": + feedPreferences.setVolumeAdaptionSetting(VolumeAdaptionSetting.MEDIUM_BOOST); + break; + case "heavy_boost": + feedPreferences.setVolumeAdaptionSetting(VolumeAdaptionSetting.HEAVY_BOOST); + break; default: } DBWriter.setFeedPreferences(feedPreferences); - updateVolumeReductionValue(); + updateVolumeAdaptationValue(); EventBus.getDefault().post( new VolumeAdaptionChangedEvent(feedPreferences.getVolumeAdaptionSetting(), feed.getId())); return false; }); } - private void updateVolumeReductionValue() { - ListPreference volumeReductionPreference = findPreference("volumeReduction"); + private void updateVolumeAdaptationValue() { + ListPreference volumeAdaptationPreference = findPreference("volumeReduction"); switch (feedPreferences.getVolumeAdaptionSetting()) { case OFF: - volumeReductionPreference.setValue("off"); + volumeAdaptationPreference.setValue("off"); break; case LIGHT_REDUCTION: - volumeReductionPreference.setValue("light"); + volumeAdaptationPreference.setValue("light"); break; case HEAVY_REDUCTION: - volumeReductionPreference.setValue("heavy"); + volumeAdaptationPreference.setValue("heavy"); + break; + case LIGHT_BOOST: + volumeAdaptationPreference.setValue("light_boost"); + break; + case MEDIUM_BOOST: + volumeAdaptationPreference.setValue("medium_boost"); + break; + case HEAVY_BOOST: + volumeAdaptationPreference.setValue("heavy_boost"); break; } } diff --git a/app/src/main/res/xml/feed_settings.xml b/app/src/main/res/xml/feed_settings.xml index 619ab6296..fb9e2e425 100644 --- a/app/src/main/res/xml/feed_settings.xml +++ b/app/src/main/res/xml/feed_settings.xml @@ -50,12 +50,12 @@ + android:summary="@string/feed_volume_adaptation_summary" + android:title="@string/feed_volume_adapdation" /> 1) { + exoPlayer.setVolume(1f); + loudnessEnhancer.setEnabled(true); + loudnessEnhancer.setTargetGain((int) (1000 * (v - 1))); + } else { + exoPlayer.setVolume(v); + loudnessEnhancer.setEnabled(false); + } } public void start() { @@ -335,4 +352,16 @@ public class ExoPlayerWrapper { void setOnBufferingUpdateListener(Consumer bufferingUpdateListener) { this.bufferingUpdateListener = bufferingUpdateListener; } + + private void initLoudnessEnhancer(int audioStreamId) { + LoudnessEnhancer newEnhancer = new LoudnessEnhancer(audioStreamId); + LoudnessEnhancer oldEnhancer = this.loudnessEnhancer; + if (oldEnhancer != null) { + newEnhancer.setEnabled(oldEnhancer.getEnabled()); + newEnhancer.setTargetGain((int) oldEnhancer.getTargetGain()); + oldEnhancer.release(); + } + + this.loudnessEnhancer = newEnhancer; + } } diff --git a/core/src/main/res/values/arrays.xml b/core/src/main/res/values/arrays.xml index 7749c6f3c..50afe630b 100644 --- a/core/src/main/res/values/arrays.xml +++ b/core/src/main/res/values/arrays.xml @@ -13,16 +13,22 @@ never - - @string/feed_volume_reduction_off - @string/feed_volume_reduction_light + @string/feed_volume_reduction_heavy + @string/feed_volume_reduction_light + @string/feed_volume_reduction_off + @string/feed_volume_boost_light + @string/feed_volume_boost_medium + @string/feed_volume_boost_heavy - - off - light + heavy + light + off + light_boost + medium_boost + heavy_boost diff --git a/core/src/test/java/de/danoeh/antennapod/core/feed/VolumeAdaptionSettingTest.java b/core/src/test/java/de/danoeh/antennapod/core/feed/VolumeAdaptionSettingTest.java index 4241707bc..30767bdc8 100644 --- a/core/src/test/java/de/danoeh/antennapod/core/feed/VolumeAdaptionSettingTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/feed/VolumeAdaptionSettingTest.java @@ -31,11 +31,35 @@ public class VolumeAdaptionSettingTest { assertThat(setting.toInteger(), is(equalTo(2))); } + @Test + public void mapLightBoostToInteger() { + VolumeAdaptionSetting setting = VolumeAdaptionSetting.LIGHT_BOOST; + + assertThat(setting.toInteger(), is(equalTo(3))); + } + + @Test + public void mapMediumBoostToInteger() { + VolumeAdaptionSetting setting = VolumeAdaptionSetting.MEDIUM_BOOST; + + assertThat(setting.toInteger(), is(equalTo(4))); + } + + @Test + public void mapHeavyBoostToInteger() { + VolumeAdaptionSetting setting = VolumeAdaptionSetting.HEAVY_BOOST; + + assertThat(setting.toInteger(), is(equalTo(5))); + } + @Test public void mapIntegerToVolumeAdaptionSetting() { assertThat(VolumeAdaptionSetting.fromInteger(0), is(equalTo(VolumeAdaptionSetting.OFF))); assertThat(VolumeAdaptionSetting.fromInteger(1), is(equalTo(VolumeAdaptionSetting.LIGHT_REDUCTION))); assertThat(VolumeAdaptionSetting.fromInteger(2), is(equalTo(VolumeAdaptionSetting.HEAVY_REDUCTION))); + assertThat(VolumeAdaptionSetting.fromInteger(3), is(equalTo(VolumeAdaptionSetting.LIGHT_BOOST))); + assertThat(VolumeAdaptionSetting.fromInteger(4), is(equalTo(VolumeAdaptionSetting.MEDIUM_BOOST))); + assertThat(VolumeAdaptionSetting.fromInteger(5), is(equalTo(VolumeAdaptionSetting.HEAVY_BOOST))); } @Test(expected = IllegalArgumentException.class) @@ -45,7 +69,7 @@ public class VolumeAdaptionSettingTest { @Test(expected = IllegalArgumentException.class) public void cannotMapValuesOutOfRange() { - VolumeAdaptionSetting.fromInteger(3); + VolumeAdaptionSetting.fromInteger(6); } @Test @@ -62,4 +86,31 @@ public class VolumeAdaptionSettingTest { assertTrue("Light reduction must have higher factor than heavy reduction", lightReductionFactor > heavyReductionFactor); } -} \ No newline at end of file + + @Test + public void lightBoostYieldsHigherValueThanLightReduction() { + float lightReductionFactor = VolumeAdaptionSetting.LIGHT_REDUCTION.getAdaptionFactor(); + + float lightBoostFactor = VolumeAdaptionSetting.LIGHT_BOOST.getAdaptionFactor(); + + assertTrue("Light boost must have higher factor than light reduction", lightBoostFactor > lightReductionFactor); + } + + @Test + public void mediumBoostYieldsHigherValueThanLightBoost() { + float lightBoostFactor = VolumeAdaptionSetting.LIGHT_BOOST.getAdaptionFactor(); + + float mediumBoostFactor = VolumeAdaptionSetting.MEDIUM_BOOST.getAdaptionFactor(); + + assertTrue("Medium boost must have higher factor than light boost", mediumBoostFactor > lightBoostFactor); + } + + @Test + public void heavyBoostYieldsHigherValueThanMediumBoost() { + float mediumBoostFactor = VolumeAdaptionSetting.MEDIUM_BOOST.getAdaptionFactor(); + + float heavyBoostFactor = VolumeAdaptionSetting.HEAVY_BOOST.getAdaptionFactor(); + + assertTrue("Heavy boost must have higher factor than medium boost", heavyBoostFactor > mediumBoostFactor); + } +} diff --git a/model/src/main/java/de/danoeh/antennapod/model/feed/VolumeAdaptionSetting.java b/model/src/main/java/de/danoeh/antennapod/model/feed/VolumeAdaptionSetting.java index 67e30e5c8..e71c5ad36 100644 --- a/model/src/main/java/de/danoeh/antennapod/model/feed/VolumeAdaptionSetting.java +++ b/model/src/main/java/de/danoeh/antennapod/model/feed/VolumeAdaptionSetting.java @@ -3,7 +3,10 @@ package de.danoeh.antennapod.model.feed; public enum VolumeAdaptionSetting { OFF(0, 1.0f), LIGHT_REDUCTION(1, 0.5f), - HEAVY_REDUCTION(2, 0.2f); + HEAVY_REDUCTION(2, 0.2f), + LIGHT_BOOST(3, 1.5f), + MEDIUM_BOOST(4, 2f), + HEAVY_BOOST(5, 2.5f); private final int value; private float adaptionFactor; diff --git a/ui/i18n/src/main/res/values/strings.xml b/ui/i18n/src/main/res/values/strings.xml index 6bdb836dd..baed14c55 100644 --- a/ui/i18n/src/main/res/values/strings.xml +++ b/ui/i18n/src/main/res/values/strings.xml @@ -124,11 +124,14 @@ Retry Include in auto downloads Auto delete episode - Volume reduction - Turn down volume for episodes of this podcast: %1$s - Off - Light - Heavy + Volume adaptation + Turn volume for episodes of this podcast up or down: %1$s + No adaption + Light reduction + Heavy reduction + Light boost + Medium boost + Heavy boost Always Never Add to inbox