Added Microphone Gain audio setting
This commit is contained in:
@ -15,6 +15,7 @@ import com.tutpro.baresip.databinding.ActivityAudioBinding
|
||||
class AudioActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var binding: ActivityAudioBinding
|
||||
private lateinit var micGain: EditText
|
||||
private lateinit var opusBitRate: EditText
|
||||
private lateinit var opusPacketLoss: EditText
|
||||
private lateinit var aec: CheckBox
|
||||
@ -24,6 +25,7 @@ class AudioActivity : AppCompatActivity() {
|
||||
private var save = false
|
||||
private var restart = false
|
||||
private var callVolume = BaresipService.callVolume
|
||||
private var oldMicGain = ""
|
||||
private var oldAudioModules = mutableMapOf<String, Boolean>()
|
||||
private var oldOpusBitrate = ""
|
||||
private var oldOpusPacketLoss = ""
|
||||
@ -74,6 +76,10 @@ class AudioActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
micGain = binding.MicGain
|
||||
oldMicGain = Config.variable("augain")
|
||||
micGain.setText(oldMicGain)
|
||||
|
||||
speakerPhone = binding.SpeakerPhone
|
||||
speakerPhone.isChecked = BaresipService.speakerPhone
|
||||
|
||||
@ -126,7 +132,7 @@ class AudioActivity : AppCompatActivity() {
|
||||
aec.isChecked = oldAec
|
||||
|
||||
audioDelay = binding.AudioDelay
|
||||
audioDelay.setText(BaresipService.audioDelay.toString())
|
||||
audioDelay.setText("${BaresipService.audioDelay}")
|
||||
|
||||
val toneCountrySpinner = binding.ToneCountrySpinner
|
||||
val toneCountryKeys = arrayListOf("bg", "br", "de", "cz", "es", "fi", "fr", "uk", "jp", "no", "nz", "se", "ru", "us")
|
||||
@ -179,6 +185,36 @@ class AudioActivity : AppCompatActivity() {
|
||||
save = true
|
||||
}
|
||||
|
||||
var gain = micGain.text.toString().trim()
|
||||
if (!gain.contains("."))
|
||||
gain = "$gain.0"
|
||||
if (gain != oldMicGain) {
|
||||
if (!checkMicGain(gain)) {
|
||||
Utils.alertView(this, getString(R.string.notice),
|
||||
"${getString(R.string.invalid_microphone_gain)}: $gain.")
|
||||
micGain.setText(oldMicGain)
|
||||
return false
|
||||
}
|
||||
if (gain == "1.0") {
|
||||
Api.module_unload("augain")
|
||||
Config.removeVariableValue("module", "augain.so")
|
||||
Config.replaceVariable("augain", "1.0")
|
||||
} else {
|
||||
if (oldMicGain == "1.0") {
|
||||
if (Api.module_load("augain") != 0) {
|
||||
Utils.alertView(this, getString(R.string.error),
|
||||
getString(R.string.failed_to_load_module))
|
||||
micGain.setText(oldMicGain)
|
||||
return false
|
||||
}
|
||||
Config.addVariable("module", "augain.so")
|
||||
}
|
||||
Config.replaceVariable("augain", gain)
|
||||
Api.cmd_exec("augain $gain")
|
||||
}
|
||||
save = true
|
||||
}
|
||||
|
||||
if (speakerPhone.isChecked != BaresipService.speakerPhone) {
|
||||
BaresipService.speakerPhone = speakerPhone.isChecked
|
||||
Config.replaceVariable("speaker_phone",
|
||||
@ -235,12 +271,16 @@ class AudioActivity : AppCompatActivity() {
|
||||
|
||||
if (aec.isChecked != oldAec) {
|
||||
if (aec.isChecked) {
|
||||
Config.replaceVariable("module", "webrtc_aecm.so")
|
||||
if (Api.module_load("webrtc_aecm.so") != 0) {
|
||||
Utils.alertView(this, getString(R.string.error),
|
||||
Config.addVariable("module", "webrtc_aecm.so")
|
||||
if (gain != "1.0") {
|
||||
restart = true
|
||||
} else {
|
||||
if (Api.module_load("webrtc_aecm.so") != 0) {
|
||||
Utils.alertView(this, getString(R.string.error),
|
||||
getString(R.string.failed_to_load_module))
|
||||
aec.isChecked = false
|
||||
return false
|
||||
aec.isChecked = false
|
||||
return false
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Api.module_unload("webrtc_aecm.so")
|
||||
@ -298,6 +338,11 @@ class AudioActivity : AppCompatActivity() {
|
||||
Utils.alertView(this, getString(R.string.default_call_volume),
|
||||
getString(R.string.default_call_volume_help))
|
||||
}
|
||||
binding.MicGainTitle.setOnClickListener {
|
||||
Utils.alertView(this, getString(R.string.microphone_gain),
|
||||
getString(R.string.microphone_gain_help)
|
||||
)
|
||||
}
|
||||
binding.SpeakerPhoneTitle.setOnClickListener {
|
||||
Utils.alertView(this, getString(R.string.speaker_phone),
|
||||
getString(R.string.speaker_phone_help))
|
||||
@ -328,6 +373,16 @@ class AudioActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkMicGain(micGain: String): Boolean {
|
||||
val number =
|
||||
try {
|
||||
micGain.toDouble()
|
||||
} catch (e: NumberFormatException) {
|
||||
return false
|
||||
}
|
||||
return number >= 1.0
|
||||
}
|
||||
|
||||
private fun checkOpusBitRate(opusBitRate: String): Boolean {
|
||||
val number = opusBitRate.toIntOrNull() ?: return false
|
||||
return (number >= 6000) && (number <= 510000)
|
||||
|
||||
@ -157,6 +157,12 @@ object Config {
|
||||
if ("webrtc_aecm.so" in previousModules)
|
||||
config = "${config}module webrtc_aecm.so\n"
|
||||
|
||||
val micGain = previousVariable("augain")
|
||||
config = if (micGain == "" || micGain == "1.0")
|
||||
"${config}augain 1.0\n"
|
||||
else
|
||||
"${config}module augain.so\naugain $micGain\n"
|
||||
|
||||
val opusBitRate = previousVariable("opus_bitrate")
|
||||
config = if (opusBitRate == "")
|
||||
"${config}opus_bitrate 28000\n"
|
||||
|
||||
@ -40,6 +40,36 @@
|
||||
</Spinner>
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:orientation="horizontal" >
|
||||
<TextView
|
||||
android:id="@+id/MicGainTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:textSize="18sp"
|
||||
android:text="@string/microphone_gain" >
|
||||
</TextView>
|
||||
<EditText
|
||||
android:id="@+id/MicGain"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_toEndOf="@+id/MicGainTitle"
|
||||
android:layout_marginStart="10dp"
|
||||
android:textSize="18sp"
|
||||
android:scrollHorizontally="true"
|
||||
android:inputType="numberDecimal"
|
||||
android:hint="@string/_1.0"
|
||||
android:textColorHint="@color/colorSecondaryDark"
|
||||
android:importantForAutofill="no" >
|
||||
</EditText>
|
||||
</RelativeLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@ -370,6 +370,12 @@
|
||||
<string name="aec_extended_filter_help">Jos merkitty, kaiun poistossa käytetään laajennettua
|
||||
suodatinta.
|
||||
</string>
|
||||
<string name="microphone_gain">Mikrofonin äänikerroin</string>
|
||||
<string name="microphone_gain_help">Kertoo mikrofonin äänen voimakkuuden tällä desimaaliluvulla.
|
||||
Minimikerroin on 1.0 (tehdasasetus), mikä ei muuta mikrofonin äänen voimakkuutta. Suuremmat
|
||||
arvot voivat vaikuttaa negatiivisesti äänen laatuun.</string>
|
||||
<string name="invalid_microphone_gain">Virheellinen mikrofonin äänikerroin</string>
|
||||
<string name="_1.0" translatable="false">1.0</string>
|
||||
<string name="opus_bit_rate">Opus-koodekin bittinopeus</string>
|
||||
<string name="opus_bit_rate_help">Opus-koodekin käyttämä
|
||||
keskimääräinen enimmäisnopeus. Mahdollisia arvoja ovat
|
||||
|
||||
@ -344,6 +344,12 @@
|
||||
<string name="aec_help">If checked, echo cancellation is attempted on call audio.</string>
|
||||
<string name="aec_extended_filter">AEC Extended Filter</string>
|
||||
<string name="aec_extended_filter_help">If checked, echo cancellation is using extended filter.</string>
|
||||
<string name="microphone_gain">Microphone Gain</string>
|
||||
<string name="microphone_gain_help">Multiply microphone volume by this decimal number. Minimum
|
||||
value is 1.0 (factory default) that disables microphone gain. Larger values may negatively
|
||||
affect audio quality.</string>
|
||||
<string name="invalid_microphone_gain">Invalid Microphone Gain value</string>
|
||||
<string name="_1.0" translatable="false">1.0</string>
|
||||
<string name="opus_bit_rate">Opus Bit Rate</string>
|
||||
<string name="opus_bit_rate_help">Average maximum bit rate used by Opus audio stream.
|
||||
Valid values are 6000-510000. Factory default is 28000.</string>
|
||||
|
||||
Reference in New Issue
Block a user