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:
@@ -63,6 +63,8 @@ public final class CaptureVoiceInput implements VoiceInput {
|
||||
private volatile boolean vadOverPtt;
|
||||
private volatile double inputGain;
|
||||
private volatile CodecType codec = CodecType.OPUS_VOICE;
|
||||
private volatile int redundancyDelay;
|
||||
private volatile int redundancyCopies;
|
||||
|
||||
private final SpeechProbabilityDetector speechDetector =
|
||||
new RnnSpeechDetector(VoiceFormat.SAMPLE_RATE);
|
||||
@@ -109,6 +111,7 @@ public final class CaptureVoiceInput implements VoiceInput {
|
||||
this.inputGain = settings.inputVolume;
|
||||
this.params = OpusParameters.from(settings);
|
||||
this.codec = codecFor(params);
|
||||
setRedundancy(settings.redundancyDelay, settings.redundancyCopies);
|
||||
processor.setNoiseSuppression(settings.denoise);
|
||||
processor.setSuppressionLevel(SuppressionLevel.fromDenoiserLevel(settings.denoiserLevel));
|
||||
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) {
|
||||
return p.music ? OpusCodec.Application.AUDIO : OpusCodec.Application.VOIP;
|
||||
}
|
||||
@@ -551,6 +560,16 @@ public final class CaptureVoiceInput implements VoiceInput {
|
||||
return codec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRedundancyDelay() {
|
||||
return redundancyDelay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRedundancyCopies() {
|
||||
return redundancyCopies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] provide() {
|
||||
byte[] p = queue.poll();
|
||||
|
||||
@@ -66,6 +66,9 @@ public interface VoiceInput extends Microphone {
|
||||
/** Applies Opus encoder parameters, taking effect immediately if capturing. */
|
||||
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);
|
||||
|
||||
/** 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);
|
||||
setAgcBoost(settings.agcBoostDb);
|
||||
setOpusParameters(OpusParameters.from(settings));
|
||||
setRedundancy(settings.redundancyDelay, settings.redundancyCopies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,6 +122,17 @@ public final class Settings {
|
||||
public int packetLoss = 5;
|
||||
/** Encode as music (OPUS_MUSIC) rather than voice (OPUS_VOICE). */
|
||||
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). */
|
||||
public double outputVolume = 1.0;
|
||||
/**
|
||||
@@ -278,6 +289,8 @@ public final class Settings {
|
||||
fec = parseB(props.getProperty("fec"), fec);
|
||||
packetLoss = parseI(props.getProperty("packetLoss"), packetLoss);
|
||||
music = parseB(props.getProperty("music"), music);
|
||||
redundancyDelay = parseI(props.getProperty("redundancyDelay"), redundancyDelay);
|
||||
redundancyCopies = parseI(props.getProperty("redundancyCopies"), redundancyCopies);
|
||||
outputVolume = parseD(props.getProperty("outputVolume"), outputVolume);
|
||||
masterVolume = parseD(props.getProperty("masterVolume"), masterVolume);
|
||||
inputVolume = parseD(props.getProperty("inputVolume"), inputVolume);
|
||||
@@ -336,6 +349,8 @@ public final class Settings {
|
||||
props.setProperty("fec", Boolean.toString(fec));
|
||||
props.setProperty("packetLoss", Integer.toString(packetLoss));
|
||||
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("masterVolume", Double.toString(masterVolume));
|
||||
props.setProperty("inputVolume", Double.toString(inputVolume));
|
||||
|
||||
@@ -5,6 +5,7 @@ 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;
|
||||
@@ -24,6 +25,8 @@ final class EncoderSection {
|
||||
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;
|
||||
|
||||
@@ -53,6 +56,43 @@ final class EncoderSection {
|
||||
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()];
|
||||
}
|
||||
|
||||
/** 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++, 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;
|
||||
}
|
||||
|
||||
@@ -72,6 +114,8 @@ final class EncoderSection {
|
||||
target.vbr = vbrCheck.isSelected();
|
||||
target.fec = fecCheck.isSelected();
|
||||
target.music = musicCheck.isSelected();
|
||||
target.redundancyDelay = selectedDelay();
|
||||
target.redundancyCopies = selectedCopies();
|
||||
}
|
||||
|
||||
private void pushLive() {
|
||||
|
||||
Reference in New Issue
Block a user