Add voice redundancy and the encoder settings on Android
Redundancy sends every voice packet again, one to four times, 20 to 200 ms apart. Listeners' jitter buffers grow to wait for the copies, native clients' included, so a lost packet costs nothing while a copy arrives. With a native client listening over a bursty lossy uplink, the frames lost to concealment fell from 10% to under 1%. Android gets the desktop's encoder settings: bitrate, complexity, VBR, FEC, music codec, and the new redundancy delay and copies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -39,6 +39,8 @@ import com.ts3client.config.Settings
|
|||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
private val DENOISE_LEVELS = listOf("Off", "6 dB", "12 dB", "18 dB", "21 dB")
|
private val DENOISE_LEVELS = listOf("Off", "6 dB", "12 dB", "18 dB", "21 dB")
|
||||||
|
private const val MIN_BITRATE_KBITS = 8f
|
||||||
|
private const val MAX_BITRATE_KBITS = 160f
|
||||||
|
|
||||||
/** Audio devices, transmission, voice activation, processing and playback. */
|
/** Audio devices, transmission, voice activation, processing and playback. */
|
||||||
@Composable
|
@Composable
|
||||||
@@ -51,6 +53,11 @@ fun SoundSettingsScreen(vm: SessionController, onBack: () -> Unit) {
|
|||||||
var inputMode by remember { mutableStateOf(settings.inputMode) }
|
var inputMode by remember { mutableStateOf(settings.inputMode) }
|
||||||
var vadMode by remember { mutableStateOf(settings.vadMode) }
|
var vadMode by remember { mutableStateOf(settings.vadMode) }
|
||||||
var agc by remember { mutableStateOf(settings.agc) }
|
var agc by remember { mutableStateOf(settings.agc) }
|
||||||
|
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 mutedTalkWarning by remember { mutableStateOf(settings.mutedTalkWarning) }
|
var mutedTalkWarning by remember { mutableStateOf(settings.mutedTalkWarning) }
|
||||||
var threshold by remember { mutableFloatStateOf(settings.vadThresholdDb.toFloat()) }
|
var threshold by remember { mutableFloatStateOf(settings.vadThresholdDb.toFloat()) }
|
||||||
var inputDevice by remember { mutableStateOf(settings.inputDevice) }
|
var inputDevice by remember { mutableStateOf(settings.inputDevice) }
|
||||||
@@ -147,6 +154,36 @@ fun SoundSettingsScreen(vm: SessionController, onBack: () -> Unit) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Section("Encoder")
|
||||||
|
Level("Bitrate", settings.bitrate / 1000f, MIN_BITRATE_KBITS..MAX_BITRATE_KBITS, { "${it.roundToInt()} kbit/s" }) {
|
||||||
|
change { bitrate = it.roundToInt() * 1000 }
|
||||||
|
}
|
||||||
|
Level("Complexity", settings.complexity.toFloat(), 0f..10f, { "${it.roundToInt()}" }, steps = 9) {
|
||||||
|
change { complexity = it.roundToInt() }
|
||||||
|
}
|
||||||
|
Toggle("Variable bitrate (VBR)", vbr) {
|
||||||
|
vbr = it
|
||||||
|
change { this.vbr = it }
|
||||||
|
}
|
||||||
|
Toggle("Forward error correction (FEC)", fec) {
|
||||||
|
fec = it
|
||||||
|
change { this.fec = it }
|
||||||
|
}
|
||||||
|
Toggle("Music codec (stereo, higher fidelity)", music) {
|
||||||
|
music = it
|
||||||
|
change { this.music = it }
|
||||||
|
}
|
||||||
|
Picker("Redundancy", Settings.REDUNDANCY_DELAYS.map { it to if (it == 0) "Off" else "$it ms" }, 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 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Section("Playback")
|
Section("Playback")
|
||||||
Level("Volume", settings.outputVolume.toFloat(), 0f..2f, { "${(it * 100).roundToInt()} %" }) {
|
Level("Volume", settings.outputVolume.toFloat(), 0f..2f, { "${(it * 100).roundToInt()} %" }) {
|
||||||
change { outputVolume = it.toDouble() }
|
change { outputVolume = it.toDouble() }
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ public final class CaptureVoiceInput implements VoiceInput {
|
|||||||
private volatile boolean vadOverPtt;
|
private volatile boolean vadOverPtt;
|
||||||
private volatile double inputGain;
|
private volatile double inputGain;
|
||||||
private volatile CodecType codec = CodecType.OPUS_VOICE;
|
private volatile CodecType codec = CodecType.OPUS_VOICE;
|
||||||
|
private volatile int redundancyDelay;
|
||||||
|
private volatile int redundancyCopies;
|
||||||
|
|
||||||
private final SpeechProbabilityDetector speechDetector =
|
private final SpeechProbabilityDetector speechDetector =
|
||||||
new RnnSpeechDetector(VoiceFormat.SAMPLE_RATE);
|
new RnnSpeechDetector(VoiceFormat.SAMPLE_RATE);
|
||||||
@@ -109,6 +111,7 @@ public final class CaptureVoiceInput implements VoiceInput {
|
|||||||
this.inputGain = settings.inputVolume;
|
this.inputGain = settings.inputVolume;
|
||||||
this.params = OpusParameters.from(settings);
|
this.params = OpusParameters.from(settings);
|
||||||
this.codec = codecFor(params);
|
this.codec = codecFor(params);
|
||||||
|
setRedundancy(settings.redundancyDelay, settings.redundancyCopies);
|
||||||
processor.setNoiseSuppression(settings.denoise);
|
processor.setNoiseSuppression(settings.denoise);
|
||||||
processor.setSuppressionLevel(SuppressionLevel.fromDenoiserLevel(settings.denoiserLevel));
|
processor.setSuppressionLevel(SuppressionLevel.fromDenoiserLevel(settings.denoiserLevel));
|
||||||
processor.setTransientSuppression(settings.typingAttenuation);
|
processor.setTransientSuppression(settings.typingAttenuation);
|
||||||
@@ -192,6 +195,12 @@ public final class CaptureVoiceInput implements VoiceInput {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setRedundancy(int delayMillis, int copies) {
|
||||||
|
this.redundancyDelay = Math.max(0, delayMillis);
|
||||||
|
this.redundancyCopies = Math.max(1, Math.min(Settings.MAX_REDUNDANCY_COPIES, copies));
|
||||||
|
}
|
||||||
|
|
||||||
private static OpusCodec.Application applicationFor(OpusParameters p) {
|
private static OpusCodec.Application applicationFor(OpusParameters p) {
|
||||||
return p.music ? OpusCodec.Application.AUDIO : OpusCodec.Application.VOIP;
|
return p.music ? OpusCodec.Application.AUDIO : OpusCodec.Application.VOIP;
|
||||||
}
|
}
|
||||||
@@ -551,6 +560,16 @@ public final class CaptureVoiceInput implements VoiceInput {
|
|||||||
return codec;
|
return codec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRedundancyDelay() {
|
||||||
|
return redundancyDelay;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getRedundancyCopies() {
|
||||||
|
return redundancyCopies;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public byte[] provide() {
|
public byte[] provide() {
|
||||||
byte[] p = queue.poll();
|
byte[] p = queue.poll();
|
||||||
|
|||||||
@@ -66,6 +66,9 @@ public interface VoiceInput extends Microphone {
|
|||||||
/** Applies Opus encoder parameters, taking effect immediately if capturing. */
|
/** Applies Opus encoder parameters, taking effect immediately if capturing. */
|
||||||
void setOpusParameters(OpusParameters parameters);
|
void setOpusParameters(OpusParameters parameters);
|
||||||
|
|
||||||
|
/** Sends every voice packet {@code copies} more times, {@code delayMillis} apart; a delay of 0 sends it once. */
|
||||||
|
void setRedundancy(int delayMillis, int copies);
|
||||||
|
|
||||||
void setPushToTalk(boolean pressed);
|
void setPushToTalk(boolean pressed);
|
||||||
|
|
||||||
/** Receives the live input level on {@link InputLevel}'s scale, once per captured frame. */
|
/** Receives the live input level on {@link InputLevel}'s scale, once per captured frame. */
|
||||||
@@ -99,5 +102,6 @@ public interface VoiceInput extends Microphone {
|
|||||||
setAgc(settings.agc);
|
setAgc(settings.agc);
|
||||||
setAgcBoost(settings.agcBoostDb);
|
setAgcBoost(settings.agcBoostDb);
|
||||||
setOpusParameters(OpusParameters.from(settings));
|
setOpusParameters(OpusParameters.from(settings));
|
||||||
|
setRedundancy(settings.redundancyDelay, settings.redundancyCopies);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,6 +122,17 @@ public final class Settings {
|
|||||||
public int packetLoss = 5;
|
public int packetLoss = 5;
|
||||||
/** Encode as music (OPUS_MUSIC) rather than voice (OPUS_VOICE). */
|
/** Encode as music (OPUS_MUSIC) rather than voice (OPUS_VOICE). */
|
||||||
public boolean music = false;
|
public boolean music = false;
|
||||||
|
/**
|
||||||
|
* Milliseconds between a voice packet and each of its {@link #redundancyCopies}, 0 for off.
|
||||||
|
* Listeners' jitter buffers grow to wait for the last copy, so it buys loss resilience with
|
||||||
|
* about {@code redundancyDelay * redundancyCopies} of latency.
|
||||||
|
*/
|
||||||
|
public int redundancyDelay = 0;
|
||||||
|
/** The {@link #redundancyDelay} choices the settings offer; whole 20 ms voice frames. */
|
||||||
|
public static final int[] REDUNDANCY_DELAYS = {0, 20, 40, 60, 80, 120, 200};
|
||||||
|
/** How many times every voice packet is sent again. */
|
||||||
|
public int redundancyCopies = 1;
|
||||||
|
public static final int MAX_REDUNDANCY_COPIES = 4;
|
||||||
/** Master playback gain, 0..1 (may exceed 1 for boost up to 2). */
|
/** Master playback gain, 0..1 (may exceed 1 for boost up to 2). */
|
||||||
public double outputVolume = 1.0;
|
public double outputVolume = 1.0;
|
||||||
/**
|
/**
|
||||||
@@ -278,6 +289,8 @@ public final class Settings {
|
|||||||
fec = parseB(props.getProperty("fec"), fec);
|
fec = parseB(props.getProperty("fec"), fec);
|
||||||
packetLoss = parseI(props.getProperty("packetLoss"), packetLoss);
|
packetLoss = parseI(props.getProperty("packetLoss"), packetLoss);
|
||||||
music = parseB(props.getProperty("music"), music);
|
music = parseB(props.getProperty("music"), music);
|
||||||
|
redundancyDelay = parseI(props.getProperty("redundancyDelay"), redundancyDelay);
|
||||||
|
redundancyCopies = parseI(props.getProperty("redundancyCopies"), redundancyCopies);
|
||||||
outputVolume = parseD(props.getProperty("outputVolume"), outputVolume);
|
outputVolume = parseD(props.getProperty("outputVolume"), outputVolume);
|
||||||
masterVolume = parseD(props.getProperty("masterVolume"), masterVolume);
|
masterVolume = parseD(props.getProperty("masterVolume"), masterVolume);
|
||||||
inputVolume = parseD(props.getProperty("inputVolume"), inputVolume);
|
inputVolume = parseD(props.getProperty("inputVolume"), inputVolume);
|
||||||
@@ -336,6 +349,8 @@ public final class Settings {
|
|||||||
props.setProperty("fec", Boolean.toString(fec));
|
props.setProperty("fec", Boolean.toString(fec));
|
||||||
props.setProperty("packetLoss", Integer.toString(packetLoss));
|
props.setProperty("packetLoss", Integer.toString(packetLoss));
|
||||||
props.setProperty("music", Boolean.toString(music));
|
props.setProperty("music", Boolean.toString(music));
|
||||||
|
props.setProperty("redundancyDelay", Integer.toString(redundancyDelay));
|
||||||
|
props.setProperty("redundancyCopies", Integer.toString(redundancyCopies));
|
||||||
props.setProperty("outputVolume", Double.toString(outputVolume));
|
props.setProperty("outputVolume", Double.toString(outputVolume));
|
||||||
props.setProperty("masterVolume", Double.toString(masterVolume));
|
props.setProperty("masterVolume", Double.toString(masterVolume));
|
||||||
props.setProperty("inputVolume", Double.toString(inputVolume));
|
props.setProperty("inputVolume", Double.toString(inputVolume));
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import com.ts3client.audio.VoiceInput;
|
|||||||
import com.ts3client.config.Settings;
|
import com.ts3client.config.Settings;
|
||||||
|
|
||||||
import javax.swing.JCheckBox;
|
import javax.swing.JCheckBox;
|
||||||
|
import javax.swing.JComboBox;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JSlider;
|
import javax.swing.JSlider;
|
||||||
@@ -24,6 +25,8 @@ final class EncoderSection {
|
|||||||
private final JCheckBox vbrCheck;
|
private final JCheckBox vbrCheck;
|
||||||
private final JCheckBox fecCheck;
|
private final JCheckBox fecCheck;
|
||||||
private final JCheckBox musicCheck;
|
private final JCheckBox musicCheck;
|
||||||
|
private final JComboBox<String> redundancyCombo;
|
||||||
|
private final JComboBox<Integer> copiesCombo;
|
||||||
|
|
||||||
private final JLabel bitrateLabel;
|
private final JLabel bitrateLabel;
|
||||||
|
|
||||||
@@ -53,6 +56,43 @@ final class EncoderSection {
|
|||||||
fecCheck.addActionListener(e -> pushLive());
|
fecCheck.addActionListener(e -> pushLive());
|
||||||
musicCheck.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()];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Adds the section's rows to {@code form} from {@code row} on; returns the next free row. */
|
/** Adds the section's rows to {@code form} from {@code row} on; returns the next free row. */
|
||||||
@@ -62,6 +102,8 @@ final class EncoderSection {
|
|||||||
FormPanel.addWide(form, c, row++, vbrCheck);
|
FormPanel.addWide(form, c, row++, vbrCheck);
|
||||||
FormPanel.addWide(form, c, row++, fecCheck);
|
FormPanel.addWide(form, c, row++, fecCheck);
|
||||||
FormPanel.addWide(form, c, row++, musicCheck);
|
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;
|
return row;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,6 +114,8 @@ final class EncoderSection {
|
|||||||
target.vbr = vbrCheck.isSelected();
|
target.vbr = vbrCheck.isSelected();
|
||||||
target.fec = fecCheck.isSelected();
|
target.fec = fecCheck.isSelected();
|
||||||
target.music = musicCheck.isSelected();
|
target.music = musicCheck.isSelected();
|
||||||
|
target.redundancyDelay = selectedDelay();
|
||||||
|
target.redundancyCopies = selectedCopies();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pushLive() {
|
private void pushLive() {
|
||||||
|
|||||||
+1
-1
Submodule ts3j updated: 4cc27db0e8...90bf6e030c
Reference in New Issue
Block a user