Skip to content

Commit

Permalink
Volume boost with appropriate settings (gain in dB)
Browse files Browse the repository at this point in the history
  • Loading branch information
izderadicka committed Jan 3, 2019
1 parent 85eaaeb commit 6f12fdd
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 12 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ Available features
* Downloads part of or whole folder to cache (swipe playable item to left to see download button)
* Offline mode - plays only from cache
* Remembers up to 100 recently listened positions
* Bookmarks
* Bookmarks (on folder or file)
* Search (for folder names)
* Folder details - with picture and text (if present in the folder) and summary
* Intenet search - search author, boook ... (uses folder name and optional prefix to search on google)
* Notifications
* Notifications - Media notification with controls, plus notification for other features (sleep timer, downloads)
* Supports Android lifecycle - rotations, back, stop activity etc...
* Supports Android audio focus (pauses when call comes in etc.)
* Advanced playback features - playback speed, skip silence, boost volume


KISS Design Principles
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ android {
applicationId "eu.zderadicka.audioserve"
minSdkVersion 21
targetSdkVersion 28
versionCode 22
versionName "0.7.2"
versionCode 23
versionName "0.7.3"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand Down
26 changes: 19 additions & 7 deletions app/src/main/java/eu/zderadicka/audioserve/AudioService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,14 @@ private class ResultWrapper(val result: MediaBrowserServiceCompat.Result<List<Me
}
}

private class VolumeBooster(enabled: Boolean): AudioListener {
private class VolumeBooster(ctx: Context): AudioListener {
var gain: Int = 0
set(value) {
field = value
this.booster?.apply {
setTargetGain(value)
}
}
var enabled: Boolean = false
set(value) {
field = value
Expand All @@ -92,15 +99,18 @@ private class VolumeBooster(enabled: Boolean): AudioListener {
}
private var booster: LoudnessEnhancer? = null
init {
this.enabled = enabled
this.enabled = PreferenceManager.getDefaultSharedPreferences(ctx).getBoolean("pref_volume_boost", false)
this.gain = PreferenceManager.getDefaultSharedPreferences(ctx)
.getString("pref_volume_boost_db", "0").toInt() * 100

}
override fun onAudioSessionId(audioSessionId: Int) {
Log.d(LOG_TAG, "Audio session id is ${audioSessionId}, supported gain ${LoudnessEnhancer.PARAM_TARGET_GAIN_MB}")
Log.d(LOG_TAG, "Audio session id is ${audioSessionId}, volume boost is ${enabled}")
booster?.release()
booster = LoudnessEnhancer(audioSessionId)
booster?.apply {
enabled = enabled
setTargetGain(3000)
enabled = this@VolumeBooster.enabled
setTargetGain(this@VolumeBooster.gain)
}

}
Expand Down Expand Up @@ -536,6 +546,9 @@ class AudioService : MediaBrowserServiceCompat() {
"pref_volume_boost" -> {
volumeBooster.enabled = sharedPreferences.getBoolean("pref_volume_boost", false)
}
"pref_volume_boost_db" -> {
volumeBooster.gain = sharedPreferences.getString("pref_volume_boost_db", "0").toInt() * 100
}
}
}

Expand Down Expand Up @@ -566,8 +579,7 @@ class AudioService : MediaBrowserServiceCompat() {
session = MediaSessionCompat(this, LOG_TAG)
session.controller.registerCallback(sessionCallback)
player = ExoPlayerFactory.newSimpleInstance(this, DefaultTrackSelector())
val boostEnabled = PreferenceManager.getDefaultSharedPreferences(this).getBoolean("pref_volume_boost", false)
volumeBooster = VolumeBooster(boostEnabled)
volumeBooster = VolumeBooster(this)
player.audioComponent?.addAudioListener(volumeBooster)

setPlaybackParams()
Expand Down
25 changes: 25 additions & 0 deletions app/src/main/java/eu/zderadicka/audioserve/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ class SettingsFragment: PreferenceFragment(), SharedPreferences.OnSharedPreferen
}
}

findPreference("pref_volume_boost_db").setOnPreferenceChangeListener{_, newValue ->
try {
val n = (newValue as String).toInt();
n>=1 && n <= 30
} catch (e: Exception) {
false
}
}

findPreference("pref_clear_cache").setOnPreferenceClickListener {

Thread {
Expand Down Expand Up @@ -272,6 +281,22 @@ class SettingsFragment: PreferenceFragment(), SharedPreferences.OnSharedPreferen
"pref_playback_speed" -> {
}

"pref_volume_boost" -> {
if (pref !is CheckBoxPreference) return
val checked = sps.getBoolean( "pref_volume_boost", false)
if (checked) {
pref.summary=getString(R.string.pref_volume_boost_on_summary)

} else {
pref.summary=getString(R.string.pref_volume_boost_off_summary)
}
}

"pref_volume_boost_db" -> {
val v = sps.getString(pref.key, "1")
pref.summary = getString(R.string.pref_volume_boost_db_summary, v)
}


}
}
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
<string name="prefs_category_playback">PLAYBACK</string>
<string name="pref_autorewind_title">Auto Rewind</string>
<string name="pref_autorewind_unselected_title">No auto rewind, playback will start exactly where it was paused</string>
<string name="pref_autorewind_selected_title">Before continuing playback track\'\'ll be rewound by a small amount (2s-30s), depending how long it was paused</string>
<string name="pref_autorewind_selected_title">Before continuing playback track\'\'ll be rewound by a small amount (2s-30s), depending on how long it was paused</string>
<string name="label_rewind">Rewind</string>
<string name="label_forward">Forward</string>
<string name="pref_web_search_prefix_title">Web search prefix</string>
Expand All @@ -103,4 +103,9 @@
<string name="skip_silence">Skip Silence:</string>
<string name="speed">Speed:</string>
<string name="boost_volume">Boost Volume:</string>
<string name="pref_volume_boost_title">Volume boost</string>
<string name="pref_volume_boost_db_title">Volume boost gain</string>
<string name="pref_volume_boost_on_summary">Volume is boosted</string>
<string name="pref_volume_boost_off_summary">Normal volume limits</string>
<string name="pref_volume_boost_db_summary">If Volume boost switch is on volume will be amplified by %1$s dB (valid values are 1 - 30 dB)</string>
</resources>
13 changes: 13 additions & 0 deletions app/src/main/res/xml/settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@
android:defaultValue="false"
/>

<EditTextPreference
android:defaultValue="20"
android:key="pref_volume_boost_db"
android:selectAllOnFocus="true"
android:singleLine="true"
android:title="@string/pref_volume_boost_db_title" />

<CheckBoxPreference
android:key="pref_volume_boost"
android:title="@string/pref_volume_boost_title"
android:defaultValue="false"
/>

<eu.zderadicka.audioserve.ui.SeekBarPreference
android:key="pref_playback_speed"
android:title="@string/pref_playback_speed"
Expand Down

0 comments on commit 6f12fdd

Please sign in to comment.