Move bitrate, FEC and redundancy to a Network settings page

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-06 20:29:16 +00:00
co-authored by Claude Opus 5.5
parent 9458ff3400
commit 5ec4204d1d
7 changed files with 193 additions and 125 deletions
@@ -16,7 +16,7 @@ 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. Changes preview live on the connected microphone and
* pre-processing, and the encoder (bar what the Network page holds). Changes preview live on the connected microphone and
* the test alike.
*/
final class CapturePanel extends FormPanel {
@@ -34,10 +34,10 @@ final class CapturePanel extends FormPanel {
private final JSlider agcBoost;
CapturePanel(Settings settings, AudioBackend audio, VoiceInput liveMic, HotkeyService hotkeys,
HotkeysPanel hotkeysPanel, Supplier<Settings> audioSnapshot) {
HotkeysPanel hotkeysPanel, Supplier<Settings> audioSnapshot, Runnable pushEncoder) {
this.liveMic = liveMic;
this.activation = new VoiceActivationSection(settings, audio, liveMic, hotkeys, hotkeysPanel, audioSnapshot);
this.encoder = new EncoderSection(settings, liveMic);
this.encoder = new EncoderSection(settings, pushEncoder);
GridBagConstraints c = gbc();
inputCombo = AudioDevices.combo(audio.io().inputDevices(), settings.inputDevice);
@@ -1,131 +1,46 @@
package com.ts3client.ui;
import com.ts3client.audio.OpusParameters;
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.JPanel;
import javax.swing.JSlider;
import java.awt.GridBagConstraints;
/** The Capture page's Opus encoder controls, applied to the running encoder as they change. */
/**
* 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 static final int MIN_BITRATE_KBITS = 8;
private static final int MAX_BITRATE_KBITS = 160;
private final Settings settings;
private final VoiceInput liveMic;
private final JSlider bitrateSlider;
private final JSlider complexitySlider;
private final JCheckBox vbrCheck;
private final JCheckBox fecCheck;
private final JCheckBox musicCheck;
private final JComboBox<String> redundancyCombo;
private final JComboBox<Integer> copiesCombo;
private final JLabel bitrateLabel;
EncoderSection(Settings settings, VoiceInput liveMic) {
this.settings = settings;
this.liveMic = liveMic;
int kbits = Math.max(MIN_BITRATE_KBITS, Math.min(MAX_BITRATE_KBITS, settings.bitrate / 1000));
bitrateSlider = new JSlider(MIN_BITRATE_KBITS, MAX_BITRATE_KBITS, kbits);
bitrateLabel = new JLabel(kbits + " kbit/s");
bitrateSlider.addChangeListener(e -> {
bitrateLabel.setText(bitrateSlider.getValue() + " kbit/s");
pushLive();
});
/** @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 -> pushLive());
complexitySlider.addChangeListener(e -> pushEncoder.run());
vbrCheck = new JCheckBox("Variable bitrate (VBR)", settings.vbr);
fecCheck = new JCheckBox("Forward error correction (FEC)", settings.fec);
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>");
vbrCheck.addActionListener(e -> pushLive());
fecCheck.addActionListener(e -> pushLive());
musicCheck.addActionListener(e -> pushLive());
String[] delays = new String[Settings.REDUNDANCY_DELAYS.length];
for (int i = 0; i < delays.length; i++) {
int ms = Settings.REDUNDANCY_DELAYS[i];
delays[i] = ms == 0 ? "Off" : ms + " ms";
}
redundancyCombo = new JComboBox<>(delays);
redundancyCombo.setSelectedIndex(nearestDelay(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);
pushRedundancy();
});
copiesCombo.addActionListener(e -> pushRedundancy());
}
private void pushRedundancy() {
if (liveMic != null) liveMic.setRedundancy(selectedDelay(), selectedCopies());
}
private int selectedCopies() {
return (Integer) copiesCombo.getSelectedItem();
}
private static int nearestDelay(int ms) {
int best = 0;
for (int i = 1; i < Settings.REDUNDANCY_DELAYS.length; i++) {
if (Math.abs(Settings.REDUNDANCY_DELAYS[i] - ms) < Math.abs(Settings.REDUNDANCY_DELAYS[best] - ms)) best = i;
}
return best;
}
private int selectedDelay() {
return Settings.REDUNDANCY_DELAYS[redundancyCombo.getSelectedIndex()];
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("Bitrate:"), FormPanel.sliderWithLabel(bitrateSlider, bitrateLabel, 70));
FormPanel.addRow(form, c, row++, new JLabel("Complexity:"), complexitySlider);
FormPanel.addWide(form, c, row++, vbrCheck);
FormPanel.addWide(form, c, row++, fecCheck);
FormPanel.addWide(form, c, row++, musicCheck);
FormPanel.addRow(form, c, row++, new JLabel("Redundancy:"), redundancyCombo);
FormPanel.addRow(form, c, row++, new JLabel("Copies:"), copiesCombo);
return row;
}
/** Copies the form into {@code target}, without touching anything else. */
void writeInto(Settings target) {
target.bitrate = bitrateSlider.getValue() * 1000;
target.complexity = complexitySlider.getValue();
target.vbr = vbrCheck.isSelected();
target.fec = fecCheck.isSelected();
target.music = musicCheck.isSelected();
target.redundancyDelay = selectedDelay();
target.redundancyCopies = selectedCopies();
}
private void pushLive() {
if (liveMic == null) return;
liveMic.setOpusParameters(new OpusParameters(
bitrateSlider.getValue() * 1000,
complexitySlider.getValue(),
vbrCheck.isSelected(),
fecCheck.isSelected(),
settings.packetLoss,
musicCheck.isSelected()));
}
}
@@ -0,0 +1,105 @@
package com.ts3client.ui;
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, and duplicate voice packets. Changes preview live on the connected
* microphone.
*/
final class NetworkPanel extends FormPanel {
private static final int MIN_BITRATE_KBITS = 8;
private static final int MAX_BITRATE_KBITS = 160;
private final VoiceInput liveMic;
private final JSlider bitrateSlider;
private final JCheckBox vbrCheck;
private final JCheckBox fecCheck;
private final JComboBox<String> redundancyCombo;
private final JComboBox<Integer> copiesCombo;
/** @param pushEncoder puts the encoder settings on screen, across pages, into effect */
NetworkPanel(Settings settings, VoiceInput liveMic, Runnable pushEncoder) {
this.liveMic = liveMic;
GridBagConstraints c = gbc();
int kbits = Math.max(MIN_BITRATE_KBITS, Math.min(MAX_BITRATE_KBITS, settings.bitrate / 1000));
bitrateSlider = new JSlider(MIN_BITRATE_KBITS, MAX_BITRATE_KBITS, kbits);
JLabel bitrateLabel = new JLabel(kbits + " kbit/s");
bitrateSlider.addChangeListener(e -> {
bitrateLabel.setText(bitrateSlider.getValue() + " kbit/s");
pushEncoder.run();
});
vbrCheck = new JCheckBox("Variable bitrate (VBR)", settings.vbr);
fecCheck = new JCheckBox("Forward error correction (FEC)", settings.fec);
vbrCheck.addActionListener(e -> pushEncoder.run());
fecCheck.addActionListener(e -> pushEncoder.run());
String[] delays = new String[Settings.REDUNDANCY_DELAYS.length];
for (int i = 0; i < delays.length; i++) {
int ms = Settings.REDUNDANCY_DELAYS[i];
delays[i] = ms == 0 ? "Off" : ms + " ms";
}
redundancyCombo = new JComboBox<>(delays);
redundancyCombo.setSelectedIndex(nearestDelay(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);
pushRedundancy();
});
copiesCombo.addActionListener(e -> pushRedundancy());
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);
addSection(this, c, row++, "Redundancy");
addRow(this, c, row++, new JLabel("Delay:"), redundancyCombo);
addRow(this, c, row++, new JLabel("Copies:"), copiesCombo);
addFiller(this, c, row);
}
private void pushRedundancy() {
if (liveMic != null) liveMic.setRedundancy(selectedDelay(), selectedCopies());
}
private int selectedCopies() {
return (Integer) copiesCombo.getSelectedItem();
}
private static int nearestDelay(int ms) {
int best = 0;
for (int i = 1; i < Settings.REDUNDANCY_DELAYS.length; i++) {
if (Math.abs(Settings.REDUNDANCY_DELAYS[i] - ms) < Math.abs(Settings.REDUNDANCY_DELAYS[best] - ms)) best = i;
}
return best;
}
private int selectedDelay() {
return Settings.REDUNDANCY_DELAYS[redundancyCombo.getSelectedIndex()];
}
/** Copies the page into {@code target}, without touching anything else. */
void writeInto(Settings target) {
target.bitrate = bitrateSlider.getValue() * 1000;
target.vbr = vbrCheck.isSelected();
target.fec = fecCheck.isSelected();
target.redundancyDelay = selectedDelay();
target.redundancyCopies = selectedCopies();
}
}
@@ -3,6 +3,7 @@ package com.ts3client.ui;
import com.formdev.flatlaf.util.ScaledEmptyBorder;
import com.formdev.flatlaf.util.UIScale;
import com.ts3client.audio.AudioBackend;
import com.ts3client.audio.OpusParameters;
import com.ts3client.audio.VoiceInput;
import com.ts3client.audio.VoiceOutput;
import com.ts3client.config.Settings;
@@ -42,6 +43,7 @@ public final class SettingsDialog extends JDialog {
private final ApplicationPanel applicationPanel;
private final PlaybackPanel playbackPanel;
private final CapturePanel capturePanel;
private final NetworkPanel networkPanel;
private final NotificationsPanel notificationsPanel;
private final DesignPanel designPanel;
private final HotkeysPanel hotkeysPanel;
@@ -59,7 +61,11 @@ public final class SettingsDialog extends JDialog {
applicationPanel = new ApplicationPanel(settings);
hotkeysPanel = new HotkeysPanel(hotkeys);
capturePanel = new CapturePanel(settings, audio, liveMic, hotkeys, hotkeysPanel, this::audioSnapshot);
Runnable pushEncoder = () -> {
if (liveMic != null) liveMic.setOpusParameters(OpusParameters.from(audioSnapshot()));
};
capturePanel = new CapturePanel(settings, audio, liveMic, hotkeys, hotkeysPanel, this::audioSnapshot, pushEncoder);
networkPanel = new NetworkPanel(settings, liveMic, pushEncoder);
playbackPanel = new PlaybackPanel(settings, audio.io(), livePlayback, sounds,
capturePanel::setTestOutputDevice);
notificationsPanel = new NotificationsPanel(settings, sounds);
@@ -72,6 +78,7 @@ public final class SettingsDialog extends JDialog {
new OptionsPage("myTeamSpeak", myTeamSpeak, "MYTS_ACCOUNT"),
new OptionsPage("Playback", scrollable(playbackPanel), "PLAYBACK"),
new OptionsPage("Capture", scrollable(capturePanel), "CAPTURE"),
new OptionsPage("Network", scrollable(networkPanel), "PING_4"),
new OptionsPage("Design", designPanel, "GUISETUP", "CHANNEL_EDIT"),
new OptionsPage("Hotkeys", hotkeysPanel, "HOTKEYS"),
new OptionsPage("Contacts", scrollable(contactsPanel), "CONTACT", "EDIT_FRIEND_FOE_STATUS"),
@@ -165,6 +172,7 @@ public final class SettingsDialog extends JDialog {
private void writeAudioSettings(Settings target) {
playbackPanel.writeInto(target);
capturePanel.writeInto(target);
networkPanel.writeInto(target);
}
/**
@@ -176,6 +184,7 @@ public final class SettingsDialog extends JDialog {
*/
private Settings audioSnapshot() {
Settings snapshot = new Settings();
snapshot.packetLoss = settings.packetLoss;
writeAudioSettings(snapshot);
if (snapshot.inputMode == Settings.InputMode.PUSH_TO_TALK) {
snapshot.inputMode = Settings.InputMode.VOICE_ACTIVATION;