95 lines
4.3 KiB
Kotlin
95 lines
4.3 KiB
Kotlin
package ru.ua1zbe.svxremote
|
||
|
||
import android.app.Activity
|
||
import android.os.Bundle
|
||
import android.widget.ArrayAdapter
|
||
import android.widget.Button
|
||
import android.widget.CheckBox
|
||
import android.widget.SeekBar
|
||
import android.widget.Spinner
|
||
import android.widget.TextView
|
||
import android.widget.Toast
|
||
import ru.ua1zbe.svxremote.prefs.Prefs
|
||
|
||
/**
|
||
* Скрытые настройки звука (тройной тап по названию программы на главном
|
||
* экране): усиление микрофона, буфер воспроизведения (джиттер), накопление
|
||
* перед стартом. Применяются при следующем подключении/передаче.
|
||
*/
|
||
class AudioSettingsActivity : Activity() {
|
||
|
||
override fun onCreate(savedInstanceState: Bundle?) {
|
||
super.onCreate(savedInstanceState)
|
||
setContentView(R.layout.activity_audio_settings)
|
||
|
||
val seekMicGain = findViewById<SeekBar>(R.id.seek_mic_gain)
|
||
val lblMicGain = findViewById<TextView>(R.id.lbl_mic_gain_value)
|
||
val seekRxBuffer = findViewById<SeekBar>(R.id.seek_rx_buffer)
|
||
val lblRxBuffer = findViewById<TextView>(R.id.lbl_rx_buffer_value)
|
||
val seekJitter = findViewById<SeekBar>(R.id.seek_jitter)
|
||
val lblJitter = findViewById<TextView>(R.id.lbl_jitter_value)
|
||
val spinBitrate = findViewById<Spinner>(R.id.spin_tx_bitrate)
|
||
|
||
// Скорость передачи Opus: Авто + фиксированные 6..32 кбит/с.
|
||
// SvxLink: Opus 8 кГц, кадр 20 мс; декодер принимает любой битрейт,
|
||
// поэтому выбор — на стороне клиента. Авто = адаптация под интернет.
|
||
val bitrates = intArrayOf(0, 6, 8, 10, 12, 16, 20, 24, 32)
|
||
val bitrateLabels = bitrates.map {
|
||
if (it == 0) getString(R.string.audio_tx_bitrate_auto)
|
||
else getString(R.string.audio_tx_bitrate_fmt, it)
|
||
}
|
||
spinBitrate.adapter = ArrayAdapter(
|
||
this, android.R.layout.simple_spinner_item, bitrateLabels
|
||
).apply {
|
||
setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||
}
|
||
val savedBitrate = Prefs.txBitrateKbps(this)
|
||
spinBitrate.setSelection(bitrates.indexOfFirst { it == savedBitrate }.coerceAtLeast(0))
|
||
|
||
fun updateMicGainLabel() {
|
||
lblMicGain.text = "${100 + seekMicGain.progress * 10}%"
|
||
}
|
||
|
||
fun updateRxBufferLabel() {
|
||
lblRxBuffer.text = "${100 + seekRxBuffer.progress * 20} мс"
|
||
}
|
||
|
||
fun updateJitterLabel() {
|
||
lblJitter.text = "${seekJitter.progress * 20} мс"
|
||
}
|
||
|
||
seekMicGain.progress = ((Prefs.micGain(this) - 1.0f) * 10).toInt().coerceIn(0, 40)
|
||
seekRxBuffer.progress = ((Prefs.rxBufferMs(this) - 100) / 20).coerceIn(0, 25)
|
||
seekJitter.progress = (Prefs.rxJitterMs(this) / 20).coerceIn(0, 20)
|
||
updateMicGainLabel()
|
||
updateRxBufferLabel()
|
||
updateJitterLabel()
|
||
|
||
val listener = object : SeekBar.OnSeekBarChangeListener {
|
||
override fun onProgressChanged(seekBar: SeekBar, progress: Int, fromUser: Boolean) {
|
||
updateMicGainLabel()
|
||
updateRxBufferLabel()
|
||
updateJitterLabel()
|
||
}
|
||
|
||
override fun onStartTrackingTouch(seekBar: SeekBar) {}
|
||
override fun onStopTrackingTouch(seekBar: SeekBar) {}
|
||
}
|
||
seekMicGain.setOnSeekBarChangeListener(listener)
|
||
seekRxBuffer.setOnSeekBarChangeListener(listener)
|
||
seekJitter.setOnSeekBarChangeListener(listener)
|
||
|
||
val chkRxStats = findViewById<CheckBox>(R.id.chk_rx_stats)
|
||
chkRxStats.isChecked = Prefs.rxStatsEnabled(this)
|
||
|
||
findViewById<Button>(R.id.btn_audio_save).setOnClickListener {
|
||
Prefs.setMicGain(this, 1.0f + seekMicGain.progress * 0.1f)
|
||
Prefs.setRxBufferMs(this, 100 + seekRxBuffer.progress * 20)
|
||
Prefs.setRxJitterMs(this, seekJitter.progress * 20)
|
||
Prefs.setTxBitrateKbps(this, bitrates[spinBitrate.selectedItemPosition])
|
||
Prefs.setRxStatsEnabled(this, chkRxStats.isChecked)
|
||
Toast.makeText(this, getString(R.string.saved), Toast.LENGTH_SHORT).show()
|
||
finish()
|
||
}
|
||
}
|
||
} |