universal7885: parts: Use audio hw parameter for dolby effect

This commit is contained in:
Chatur27 2022-03-11 14:52:02 +00:00 committed by roynatech2544
commit 1bbbc011be
No known key found for this signature in database
GPG key ID: 9675C32163D88D30
4 changed files with 59 additions and 69 deletions

View file

@ -10,13 +10,8 @@
</string-array> </string-array>
<string-array name="dolby_modes"> <string-array name="dolby_modes">
<item>@string/dolby_profile_auto</item> <item>@string/dolby_profile_auto</item>
<item>@string/dolby_profile_game</item>
<item>@string/dolby_profile_game_1</item>
<item>@string/dolby_profile_game_2</item>
<item>@string/dolby_profile_movie</item> <item>@string/dolby_profile_movie</item>
<item>@string/dolby_profile_music</item> <item>@string/dolby_profile_music</item>
<item>@string/dolby_profile_off</item>
<item>@string/dolby_profile_special_audio</item>
<item>@string/dolby_profile_voice</item> <item>@string/dolby_profile_voice</item>
</string-array> </string-array>
</resources> </resources>

View file

@ -2,46 +2,51 @@ package com.eurekateam.samsungextras.dolby
import android.media.audiofx.AudioEffect import android.media.audiofx.AudioEffect
import java.util.* import java.util.*
import android.content.Context
import android.media.AudioManager
import android.os.IBinder
import android.content.Intent
import android.app.Service
class DolbyCore { class DolbyCore : Service() {
private var currentProfile : Int = -1 override fun onBind(intent: Intent?): IBinder? {
private val audioEffect = AudioEffect( return null
EFFECT_TYPE_DAP, AudioEffect.EFFECT_TYPE_NULL, 0, 0
)
fun startDolbyEffect(PROFILE: Int){
audioEffect.setParameter(EFFECT_PARAM_EFF_ENAB, 1)
audioEffect.setParameter(EFFECT_PARAM_PROFILE, PROFILE)
currentProfile = PROFILE
audioEffect.enabled = true
} }
fun stopDolbyEffect(){ override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
audioEffect.enabled = false if (intent != null){
} if (intent.getBooleanExtra(DAP_ENABLED, false)){
fun isRunning (): Boolean { val PROFILE = intent.getIntExtra(DAP_PROFILE, PROFILE_AUTO)
return audioEffect.enabled mAudioEffect.setParameter(EFFECT_PARAM_EFF_ENAB, 1)
} mAudioEffect.setParameter(EFFECT_PARAM_PROFILE, PROFILE)
fun justStartOnly(){ mCurrentProfile = PROFILE
audioEffect.enabled = true mAudioEffect.enabled = true
} (getSystemService(Context.AUDIO_SERVICE) as AudioManager).
setParameters("${HW_DOLBY_ENABLE}1;${HW_DOLBY_PROFILE}${PROFILE}")
fun currentState(): Int{ } else {
return currentProfile mAudioEffect.setParameter(EFFECT_PARAM_EFF_ENAB, 0)
mAudioEffect.enabled = false
(getSystemService(Context.AUDIO_SERVICE) as AudioManager).
setParameters("${HW_DOLBY_ENABLE}0;${HW_DOLBY_PROFILE}" +
mCurrentProfile.toString())
}
}
return START_NOT_STICKY
} }
companion object { companion object {
private val EFFECT_TYPE_DAP = UUID.fromString("46d279d9-9be7-453d-9d7c-ef937f675587") private val EFFECT_TYPE_DAP = UUID.fromString("46d279d9-9be7-453d-9d7c-ef937f675587")
private const val EFFECT_PARAM_PROFILE = 0 private const val EFFECT_PARAM_PROFILE = 0
private const val EFFECT_PARAM_EFF_ENAB = 19 private const val EFFECT_PARAM_EFF_ENAB = 19
const val DAP_ENABLED = "dap_enabled"
const val DAP_PROFILE = "dap_profile"
const val PROFILE_AUTO = 0 const val PROFILE_AUTO = 0
const val PROFILE_MOVIE = 1 const val PROFILE_MOVIE = 1
const val PROFILE_MUSIC = 2 const val PROFILE_MUSIC = 2
const val PROFILE_VOICE = 3 const val PROFILE_VOICE = 3
const val PROFILE_GAME = 4 private const val HW_DOLBY_ENABLE = "g_effect_dolby_enable="
const val PROFILE_OFF = 5 private const val HW_DOLBY_PROFILE = "g_effect_dolby_profile="
const val PROFILE_GAME_1 = 6 val mAudioEffect = AudioEffect(EFFECT_TYPE_DAP, AudioEffect.EFFECT_TYPE_NULL, 0, 0)
const val PROFILE_GAME_2 = 7 var mCurrentProfile = PROFILE_AUTO
const val PROFILE_SPACIAL_AUDIO = 8
} }
} }

View file

@ -21,48 +21,44 @@ import androidx.preference.Preference
import androidx.preference.PreferenceFragmentCompat import androidx.preference.PreferenceFragmentCompat
import androidx.preference.SwitchPreference import androidx.preference.SwitchPreference
import com.eurekateam.samsungextras.R import com.eurekateam.samsungextras.R
import android.content.Intent
class DolbyFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener { class DolbyFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeListener {
private var DolbyModesPreference: ListPreference? = null private var DolbyModesPreference: ListPreference? = null
private var DolbyEnablePreference: SwitchPreference? = null private var DolbyEnablePreference: SwitchPreference? = null
private var dolbyCore = DolbyCore() private lateinit var mIntent : Intent
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
addPreferencesFromResource(R.xml.dolby_settings) addPreferencesFromResource(R.xml.dolby_settings)
DolbyModesPreference = findPreference(DOLBY_MODES) DolbyModesPreference = findPreference(DOLBY_MODES)
DolbyEnablePreference = findPreference(PREF_DOLBY) DolbyEnablePreference = findPreference(PREF_DOLBY)
DolbyEnablePreference!!.isChecked = dolbyCore.isRunning() DolbyEnablePreference!!.isChecked = DolbyCore.mAudioEffect.enabled
DolbyEnablePreference!!.onPreferenceChangeListener = this DolbyEnablePreference!!.onPreferenceChangeListener = this
val items = arrayOf<CharSequence>( val items = arrayOf<CharSequence>(
"1", "2", "3", "4", "5", "6", "7", "8", "9" "0", "1", "2", "3"
) )
mIntent = Intent(requireContext(), DolbyCore::class.java)
DolbyModesPreference!!.entryValues = items DolbyModesPreference!!.entryValues = items
DolbyModesPreference!!.onPreferenceChangeListener = DolbyModesPreference!!.onPreferenceChangeListener =
Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any -> Preference.OnPreferenceChangeListener { _: Preference?, newValue: Any ->
when ((newValue as String).toInt()) { when ((newValue as String).toInt()) {
1 -> dolbyCore.startDolbyEffect(DolbyCore.PROFILE_AUTO) 0 -> mIntent.putExtra(DolbyCore.DAP_PROFILE, DolbyCore.PROFILE_AUTO)
2 -> dolbyCore.startDolbyEffect(DolbyCore.PROFILE_GAME) 1 -> mIntent.putExtra(DolbyCore.DAP_PROFILE, DolbyCore.PROFILE_MOVIE)
3 -> dolbyCore.startDolbyEffect(DolbyCore.PROFILE_GAME_1) 2 -> mIntent.putExtra(DolbyCore.DAP_PROFILE, DolbyCore.PROFILE_MUSIC)
4 -> dolbyCore.startDolbyEffect(DolbyCore.PROFILE_GAME_2) 3 -> mIntent.putExtra(DolbyCore.DAP_PROFILE, DolbyCore.PROFILE_VOICE)
5 -> dolbyCore.startDolbyEffect(DolbyCore.PROFILE_MOVIE)
6 -> dolbyCore.startDolbyEffect(DolbyCore.PROFILE_MUSIC)
7 -> dolbyCore.startDolbyEffect(DolbyCore.PROFILE_OFF)
8 -> dolbyCore.startDolbyEffect(DolbyCore.PROFILE_VOICE)
9 -> dolbyCore.startDolbyEffect(DolbyCore.PROFILE_SPACIAL_AUDIO)
else -> { else -> {
} }
} }
mIntent.putExtra(DolbyCore.DAP_ENABLED, true)
requireContext().startService(mIntent)
true true
} }
} }
override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean { override fun onPreferenceChange(preference: Preference, newValue: Any): Boolean {
if (preference === DolbyEnablePreference) { if (preference == DolbyEnablePreference) {
val value = newValue as Boolean val value = newValue as Boolean
if (value) { mIntent.putExtra(DolbyCore.DAP_ENABLED, value)
dolbyCore.justStartOnly() requireContext().startService(mIntent)
} else {
dolbyCore.stopDolbyEffect()
}
return true return true
} }
return false return false
@ -72,4 +68,4 @@ class DolbyFragment : PreferenceFragmentCompat(), Preference.OnPreferenceChangeL
private const val PREF_DOLBY = "dolby_pref" private const val PREF_DOLBY = "dolby_pref"
private const val DOLBY_MODES = "dolby_modes" private const val DOLBY_MODES = "dolby_modes"
} }
} }

View file

@ -2,30 +2,24 @@ package com.eurekateam.samsungextras.dolby
import android.service.quicksettings.Tile import android.service.quicksettings.Tile
import android.service.quicksettings.TileService import android.service.quicksettings.TileService
import android.content.Intent
class DolbyTile : TileService() { class DolbyTile : TileService() {
private var isRunning = false
private var dolbyCore = DolbyCore()
override fun onStartListening() {
super.onStartListening()
isRunning = dolbyCore.isRunning()
updateTile()
}
override fun onClick() { override fun onClick() {
if (isRunning) { val mIntent = Intent(this, DolbyCore::class.java)
dolbyCore.stopDolbyEffect() if (DolbyCore.mAudioEffect.enabled) {
mIntent.putExtra(DolbyCore.DAP_ENABLED, false)
} else { } else {
dolbyCore.justStartOnly() mIntent.putExtra(DolbyCore.DAP_ENABLED, true)
mIntent.putExtra(DolbyCore.DAP_PROFILE, DolbyCore.mCurrentProfile)
} }
isRunning = !isRunning
updateTile() updateTile()
} }
private fun updateTile() { private fun updateTile() {
val tile = qsTile val tile = qsTile
tile.state = tile.state =
if (isRunning) Tile.STATE_ACTIVE else Tile.STATE_INACTIVE if (DolbyCore.mAudioEffect.enabled) Tile.STATE_ACTIVE else Tile.STATE_INACTIVE
tile.updateTile() tile.updateTile()
} }
} }