Move the remaining encoder settings to Network; use sliders for redundancy and buffering

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-06 21:03:00 +00:00
co-authored by Claude Opus 5.5
parent 33317df2eb
commit a2bfcf9f28
6 changed files with 99 additions and 105 deletions
@@ -13,12 +13,13 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import com.ts3client.android.SessionController
import com.ts3client.config.Settings
import kotlin.math.abs
import kotlin.math.roundToInt
private const val MIN_BITRATE_KBITS = 8f
private const val MAX_BITRATE_KBITS = 160f
/** What voice costs and survives on the wire: bitrate, error correction, duplicate packets and receive buffering. */
/** What voice costs and survives on the wire: the encoder, duplicate packets and receive buffering. */
@Composable
fun NetworkSettingsScreen(vm: SessionController, onBack: () -> Unit) {
val settings = vm.settings
@@ -28,6 +29,7 @@ fun NetworkSettingsScreen(vm: SessionController, onBack: () -> Unit) {
}
var vbr by remember { mutableStateOf(settings.vbr) }
var fec by remember { mutableStateOf(settings.fec) }
var music by remember { mutableStateOf(settings.music) }
var redundancy by remember { mutableStateOf(settings.redundancyDelay) }
var copies by remember { mutableStateOf(settings.redundancyCopies) }
var receiveBuffer by remember { mutableStateOf(settings.receiveBuffer) }
@@ -46,24 +48,41 @@ fun NetworkSettingsScreen(vm: SessionController, onBack: () -> Unit) {
fec = it
change { this.fec = it }
}
Level("Complexity", settings.complexity.toFloat(), 0f..10f, { "${it.roundToInt()}" }, steps = 9) {
change { complexity = it.roundToInt() }
}
Toggle("Music codec (stereo, higher fidelity)", music) {
music = it
change { this.music = it }
}
Section("Redundancy")
Picker("Delay", Settings.REDUNDANCY_DELAYS.map { it to if (it == 0) "Off" else "$it ms" }, redundancy) {
ChoiceLevel("Delay", Settings.REDUNDANCY_DELAYS, redundancy) {
redundancy = it
change { redundancyDelay = it }
}
if (redundancy > 0) {
Picker("Copies", (1..Settings.MAX_REDUNDANCY_COPIES).map { it to "$it" }, copies) {
copies = it
change { redundancyCopies = it }
Level("Copies", copies.toFloat(), 1f..Settings.MAX_REDUNDANCY_COPIES.toFloat(), { "${it.roundToInt()}" },
steps = Settings.MAX_REDUNDANCY_COPIES - 2) {
copies = it.roundToInt()
change { redundancyCopies = copies }
}
}
Section("Receive")
Picker("Extra buffering", Settings.RECEIVE_BUFFERS.map { it to if (it == 0) "Off" else "$it ms" }, receiveBuffer) {
ChoiceLevel("Extra buffering", Settings.RECEIVE_BUFFERS, receiveBuffer) {
receiveBuffer = it
change { this.receiveBuffer = it }
}
}
}
}
/** A slider stepping through the millisecond [choices], starting at the one nearest [ms]. */
@Composable
private fun ChoiceLevel(label: String, choices: IntArray, ms: Int, onDone: (Int) -> Unit) {
val index = choices.indices.minBy { abs(choices[it] - ms) }
fun at(position: Float) = choices[position.roundToInt()]
Level(label, index.toFloat(), 0f..(choices.size - 1).toFloat(), { at(it).let { v -> if (v == 0) "Off" else "$v ms" } },
steps = choices.size - 2) { onDone(at(it)) }
}
@@ -51,7 +51,6 @@ fun SoundSettingsScreen(vm: SessionController, onBack: () -> Unit) {
var inputMode by remember { mutableStateOf(settings.inputMode) }
var vadMode by remember { mutableStateOf(settings.vadMode) }
var agc by remember { mutableStateOf(settings.agc) }
var music by remember { mutableStateOf(settings.music) }
var mutedTalkWarning by remember { mutableStateOf(settings.mutedTalkWarning) }
var threshold by remember { mutableFloatStateOf(settings.vadThresholdDb.toFloat()) }
var inputDevice by remember { mutableStateOf(settings.inputDevice) }
@@ -148,15 +147,6 @@ fun SoundSettingsScreen(vm: SessionController, onBack: () -> Unit) {
}
}
Section("Encoder")
Level("Complexity", settings.complexity.toFloat(), 0f..10f, { "${it.roundToInt()}" }, steps = 9) {
change { complexity = it.roundToInt() }
}
Toggle("Music codec (stereo, higher fidelity)", music) {
music = it
change { this.music = it }
}
Section("Playback")
Level("Volume", settings.outputVolume.toFloat(), 0f..2f, { "${(it * 100).roundToInt()} %" }) {
change { outputVolume = it.toDouble() }
@@ -16,14 +16,12 @@ import java.util.function.Supplier;
/**
* Options page for everything on the way from the microphone to the server: the capture
* device and gain, how transmission is activated (with the microphone test), the
* pre-processing, and the encoder (bar what the Network page holds). Changes preview live on the connected microphone and
* the test alike.
* pre-processing. Changes preview live on the connected microphone and the test alike.
*/
final class CapturePanel extends FormPanel {
private final VoiceInput liveMic;
private final VoiceActivationSection activation;
private final EncoderSection encoder;
private final JComboBox<AudioDevice> inputCombo;
private final JSlider inputGain;
@@ -34,10 +32,9 @@ final class CapturePanel extends FormPanel {
private final JSlider agcBoost;
CapturePanel(Settings settings, AudioBackend audio, VoiceInput liveMic, HotkeyService hotkeys,
HotkeysPanel hotkeysPanel, Supplier<Settings> audioSnapshot, Runnable pushEncoder) {
HotkeysPanel hotkeysPanel, Supplier<Settings> audioSnapshot) {
this.liveMic = liveMic;
this.activation = new VoiceActivationSection(settings, audio, liveMic, hotkeys, hotkeysPanel, audioSnapshot);
this.encoder = new EncoderSection(settings, pushEncoder);
GridBagConstraints c = gbc();
inputCombo = AudioDevices.combo(audio.io().inputDevices(), settings.inputDevice);
@@ -79,8 +76,6 @@ final class CapturePanel extends FormPanel {
addWide(this, c, row++, typingCheck);
addWide(this, c, row++, agcCheck);
addRow(this, c, row++, new JLabel("Boost quiet speech:"), agcBoost);
addSection(this, c, row++, "Encoder");
row = encoder.layOut(this, c, row);
addFiller(this, c, row);
Runnable syncProcessing = () -> {
@@ -111,7 +106,6 @@ final class CapturePanel extends FormPanel {
target.agc = agcCheck.isSelected();
target.agcBoostDb = agcBoost.getValue();
activation.writeInto(target);
encoder.writeInto(target);
}
/** Applies a live change to the connected microphone and to the microphone test alike. */
@@ -1,46 +0,0 @@
package com.ts3client.ui;
import com.ts3client.config.Settings;
import javax.swing.JCheckBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSlider;
import java.awt.GridBagConstraints;
/**
* The Capture page's Opus encoder controls, applied to the running encoder as they change.
* Bitrate and error correction live on the Network page.
*/
final class EncoderSection {
private final JSlider complexitySlider;
private final JCheckBox musicCheck;
/** @param pushEncoder puts the encoder settings on screen, across pages, into effect */
EncoderSection(Settings settings, Runnable pushEncoder) {
complexitySlider = new JSlider(0, 10, settings.complexity);
FormPanel.limitWidth(complexitySlider, FormPanel.SLIDER_WIDTH);
complexitySlider.addChangeListener(e -> pushEncoder.run());
musicCheck = new JCheckBox("Music codec (stereo, higher fidelity)", settings.music);
musicCheck.setToolTipText("<html>Transmits <b>OPUS_MUSIC</b>: stereo when the capture "
+ "device has two channels, and without the voice pre-processing "
+ "(noise removal, typing attenuation, AGC).<br>"
+ "Voice mode (<b>OPUS_VOICE</b>) is mono, as in the official client.</html>");
musicCheck.addActionListener(e -> pushEncoder.run());
}
/** Adds the section's rows to {@code form} from {@code row} on; returns the next free row. */
int layOut(JPanel form, GridBagConstraints c, int row) {
FormPanel.addRow(form, c, row++, new JLabel("Complexity:"), complexitySlider);
FormPanel.addWide(form, c, row++, musicCheck);
return row;
}
/** Copies the form into {@code target}, without touching anything else. */
void writeInto(Settings target) {
target.complexity = complexitySlider.getValue();
target.music = musicCheck.isSelected();
}
}
@@ -4,15 +4,14 @@ import com.ts3client.audio.VoiceInput;
import com.ts3client.config.Settings;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JSlider;
import java.awt.GridBagConstraints;
/**
* Options page for what voice costs and survives on the wire: the encoder's bitrate and
* error correction, duplicate voice packets, and how long incoming voice is buffered.
* Transmit changes preview live on the connected microphone.
* Options page for what voice costs and survives on the wire: the encoder, duplicate voice
* packets, and how long incoming voice is buffered. Transmit changes preview live on the
* connected microphone.
*/
final class NetworkPanel extends FormPanel {
@@ -24,9 +23,11 @@ final class NetworkPanel extends FormPanel {
private final JSlider bitrateSlider;
private final JCheckBox vbrCheck;
private final JCheckBox fecCheck;
private final JComboBox<String> redundancyCombo;
private final JComboBox<Integer> copiesCombo;
private final JComboBox<String> receiveBufferCombo;
private final JSlider complexitySlider;
private final JCheckBox musicCheck;
private final JSlider delaySlider;
private final JSlider copiesSlider;
private final JSlider receiveBufferSlider;
/** @param pushEncoder puts the encoder settings on screen, across pages, into effect */
NetworkPanel(Settings settings, VoiceInput liveMic, Runnable pushEncoder) {
@@ -46,47 +47,77 @@ final class NetworkPanel extends FormPanel {
vbrCheck.addActionListener(e -> pushEncoder.run());
fecCheck.addActionListener(e -> pushEncoder.run());
redundancyCombo = new JComboBox<>(delayLabels(Settings.REDUNDANCY_DELAYS));
redundancyCombo.setSelectedIndex(nearest(Settings.REDUNDANCY_DELAYS, settings.redundancyDelay));
Integer[] copies = new Integer[Settings.MAX_REDUNDANCY_COPIES];
for (int i = 0; i < copies.length; i++) copies[i] = i + 1;
copiesCombo = new JComboBox<>(copies);
copiesCombo.setSelectedItem(Math.max(1, Math.min(Settings.MAX_REDUNDANCY_COPIES, settings.redundancyCopies)));
copiesCombo.setEnabled(selectedDelay() > 0);
redundancyCombo.addActionListener(e -> {
copiesCombo.setEnabled(selectedDelay() > 0);
complexitySlider = new JSlider(0, 10, settings.complexity);
JLabel complexityLabel = new JLabel(String.valueOf(settings.complexity));
complexitySlider.addChangeListener(e -> {
complexityLabel.setText(String.valueOf(complexitySlider.getValue()));
pushEncoder.run();
});
musicCheck = new JCheckBox("Music codec (stereo, higher fidelity)", settings.music);
musicCheck.setToolTipText("<html>Transmits <b>OPUS_MUSIC</b>: stereo when the capture "
+ "device has two channels, and without the voice pre-processing "
+ "(noise removal, typing attenuation, AGC).<br>"
+ "Voice mode (<b>OPUS_VOICE</b>) is mono, as in the official client.</html>");
musicCheck.addActionListener(e -> pushEncoder.run());
delaySlider = choiceSlider(Settings.REDUNDANCY_DELAYS, settings.redundancyDelay);
JLabel delayLabel = new JLabel(delayLabel(selectedDelay()));
int copies = Math.max(1, Math.min(Settings.MAX_REDUNDANCY_COPIES, settings.redundancyCopies));
copiesSlider = new JSlider(1, Settings.MAX_REDUNDANCY_COPIES, copies);
copiesSlider.setMajorTickSpacing(1);
copiesSlider.setPaintTicks(true);
copiesSlider.setSnapToTicks(true);
JLabel copiesLabel = new JLabel(String.valueOf(copies));
Runnable syncCopies = () -> {
copiesSlider.setEnabled(selectedDelay() > 0);
copiesLabel.setEnabled(selectedDelay() > 0);
};
syncCopies.run();
delaySlider.addChangeListener(e -> {
delayLabel.setText(delayLabel(selectedDelay()));
syncCopies.run();
pushRedundancy();
});
copiesSlider.addChangeListener(e -> {
copiesLabel.setText(String.valueOf(copiesSlider.getValue()));
pushRedundancy();
});
copiesCombo.addActionListener(e -> pushRedundancy());
receiveBufferCombo = new JComboBox<>(delayLabels(Settings.RECEIVE_BUFFERS));
receiveBufferCombo.setSelectedIndex(nearest(Settings.RECEIVE_BUFFERS, settings.receiveBuffer));
receiveBufferSlider = choiceSlider(Settings.RECEIVE_BUFFERS, settings.receiveBuffer);
JLabel receiveBufferLabel = new JLabel(delayLabel(selectedReceiveBuffer()));
receiveBufferSlider.addChangeListener(e -> receiveBufferLabel.setText(delayLabel(selectedReceiveBuffer())));
int row = 0;
addSection(this, c, row++, "Encoder");
addRow(this, c, row++, new JLabel("Bitrate:"), sliderWithLabel(bitrateSlider, bitrateLabel, 70));
addWide(this, c, row++, vbrCheck);
addWide(this, c, row++, fecCheck);
addRow(this, c, row++, new JLabel("Complexity:"), sliderWithLabel(complexitySlider, complexityLabel, 70));
addWide(this, c, row++, musicCheck);
addSection(this, c, row++, "Redundancy");
addRow(this, c, row++, new JLabel("Delay:"), redundancyCombo);
addRow(this, c, row++, new JLabel("Copies:"), copiesCombo);
addRow(this, c, row++, new JLabel("Delay:"), sliderWithLabel(delaySlider, delayLabel, 70));
addRow(this, c, row++, new JLabel("Copies:"), sliderWithLabel(copiesSlider, copiesLabel, 70));
addSection(this, c, row++, "Receive");
addRow(this, c, row++, new JLabel("Extra buffering:"), receiveBufferCombo);
addRow(this, c, row++, new JLabel("Extra buffering:"), sliderWithLabel(receiveBufferSlider, receiveBufferLabel, 70));
addFiller(this, c, row);
}
/** A slider over the indices of {@code choices}, starting at the one nearest {@code ms}. */
private static JSlider choiceSlider(int[] choices, int ms) {
JSlider slider = new JSlider(0, choices.length - 1, nearest(choices, ms));
slider.setMajorTickSpacing(1);
slider.setPaintTicks(true);
slider.setSnapToTicks(true);
return slider;
}
private void pushRedundancy() {
if (liveMic != null) liveMic.setRedundancy(selectedDelay(), selectedCopies());
if (liveMic != null) liveMic.setRedundancy(selectedDelay(), copiesSlider.getValue());
}
private int selectedCopies() {
return (Integer) copiesCombo.getSelectedItem();
}
private static String[] delayLabels(int[] choices) {
String[] labels = new String[choices.length];
for (int i = 0; i < labels.length; i++) labels[i] = choices[i] == 0 ? "Off" : choices[i] + " ms";
return labels;
private static String delayLabel(int ms) {
return ms == 0 ? "Off" : ms + " ms";
}
private static int nearest(int[] choices, int ms) {
@@ -98,7 +129,11 @@ final class NetworkPanel extends FormPanel {
}
private int selectedDelay() {
return Settings.REDUNDANCY_DELAYS[redundancyCombo.getSelectedIndex()];
return Settings.REDUNDANCY_DELAYS[delaySlider.getValue()];
}
private int selectedReceiveBuffer() {
return Settings.RECEIVE_BUFFERS[receiveBufferSlider.getValue()];
}
/** Copies the page into {@code target}, without touching anything else. */
@@ -106,8 +141,10 @@ final class NetworkPanel extends FormPanel {
target.bitrate = bitrateSlider.getValue() * 1000;
target.vbr = vbrCheck.isSelected();
target.fec = fecCheck.isSelected();
target.complexity = complexitySlider.getValue();
target.music = musicCheck.isSelected();
target.redundancyDelay = selectedDelay();
target.redundancyCopies = selectedCopies();
target.receiveBuffer = Settings.RECEIVE_BUFFERS[receiveBufferCombo.getSelectedIndex()];
target.redundancyCopies = copiesSlider.getValue();
target.receiveBuffer = selectedReceiveBuffer();
}
}
@@ -64,7 +64,7 @@ public final class SettingsDialog extends JDialog {
Runnable pushEncoder = () -> {
if (liveMic != null) liveMic.setOpusParameters(OpusParameters.from(audioSnapshot()));
};
capturePanel = new CapturePanel(settings, audio, liveMic, hotkeys, hotkeysPanel, this::audioSnapshot, pushEncoder);
capturePanel = new CapturePanel(settings, audio, liveMic, hotkeys, hotkeysPanel, this::audioSnapshot);
networkPanel = new NetworkPanel(settings, liveMic, pushEncoder);
playbackPanel = new PlaybackPanel(settings, audio.io(), livePlayback, sounds,
capturePanel::setTestOutputDevice);