diff --git a/ts3-client/swing/src/main/java/com/ts3client/ui/CapturePanel.java b/ts3-client/swing/src/main/java/com/ts3client/ui/CapturePanel.java index 4354584..a41e9bd 100644 --- a/ts3-client/swing/src/main/java/com/ts3client/ui/CapturePanel.java +++ b/ts3-client/swing/src/main/java/com/ts3client/ui/CapturePanel.java @@ -20,13 +20,14 @@ import java.util.function.Supplier; */ final class CapturePanel extends FormPanel { + private static final String[] DENOISE_STEPS = {"Off", "6 dB", "12 dB", "18 dB", "21 dB"}; + private final VoiceInput liveMic; private final VoiceActivationSection activation; private final JComboBox inputCombo; private final JSlider inputGain; - private final JCheckBox denoiseCheck; - private final JSlider denoiseLevel; + private final JSlider denoise; private final JCheckBox typingCheck; private final JCheckBox agcCheck; private final JSlider agcBoost; @@ -48,13 +49,13 @@ final class CapturePanel extends FormPanel { applyLive(m -> m.setInputGain(inputGain.getValue() / 100.0)); }); - denoiseCheck = new JCheckBox("Remove background noise", settings.denoise); - // TS3's four steps, 6/12/18/21 dB of suppression. - denoiseLevel = new JSlider(0, 3, Math.max(0, Math.min(3, settings.denoiserLevel))); - denoiseLevel.setMajorTickSpacing(1); - denoiseLevel.setPaintTicks(true); - limitWidth(denoiseLevel, SLIDER_WIDTH); - denoiseLevel.setToolTipText("6, 12, 18 or 21 dB"); + // Off, then TS3's four denoiser_level steps. + denoise = new JSlider(0, DENOISE_STEPS.length - 1, + settings.denoise ? Math.max(0, Math.min(3, settings.denoiserLevel)) + 1 : 0); + denoise.setMajorTickSpacing(1); + denoise.setPaintTicks(true); + denoise.setSnapToTicks(true); + JLabel denoiseLabel = new JLabel(DENOISE_STEPS[denoise.getValue()]); typingCheck = new JCheckBox("Typing attenuation", settings.typingAttenuation); agcCheck = new JCheckBox("Automatic gain control", settings.agc); agcBoost = new JSlider(0, Settings.MAX_AGC_BOOST_DB, settings.agcBoostDb); @@ -71,27 +72,26 @@ final class CapturePanel extends FormPanel { addSection(this, c, row++, "Activation"); row = activation.layOut(this, c, row); addSection(this, c, row++, "Digital Signal Processing"); - addWide(this, c, row++, denoiseCheck); - addRow(this, c, row++, new JLabel("Noise removal level:"), denoiseLevel); + addRow(this, c, row++, new JLabel("Remove background noise:"), sliderWithLabel(denoise, denoiseLabel)); addWide(this, c, row++, typingCheck); addWide(this, c, row++, agcCheck); addRow(this, c, row++, new JLabel("Boost quiet speech:"), agcBoost); addFiller(this, c, row); Runnable syncProcessing = () -> { - denoiseLevel.setEnabled(denoiseCheck.isSelected()); agcBoost.setEnabled(agcCheck.isSelected()); applyLive(m -> { - m.setNoiseSuppression(denoiseCheck.isSelected()); - m.setDenoiserLevel(denoiseLevel.getValue()); + applyDenoise(m); m.setTypingAttenuation(typingCheck.isSelected()); m.setAgc(agcCheck.isSelected()); }); }; - denoiseCheck.addActionListener(e -> syncProcessing.run()); typingCheck.addActionListener(e -> syncProcessing.run()); agcCheck.addActionListener(e -> syncProcessing.run()); - denoiseLevel.addChangeListener(e -> applyLive(m -> m.setDenoiserLevel(denoiseLevel.getValue()))); + denoise.addChangeListener(e -> { + denoiseLabel.setText(DENOISE_STEPS[denoise.getValue()]); + applyLive(this::applyDenoise); + }); agcBoost.addChangeListener(e -> applyLive(m -> m.setAgcBoost(agcBoost.getValue()))); syncProcessing.run(); } @@ -100,14 +100,19 @@ final class CapturePanel extends FormPanel { void writeInto(Settings target) { target.inputDevice = AudioDevices.selectedId(inputCombo); target.inputVolume = inputGain.getValue() / 100.0; - target.denoise = denoiseCheck.isSelected(); - target.denoiserLevel = denoiseLevel.getValue(); + target.denoise = denoise.getValue() > 0; + if (target.denoise) target.denoiserLevel = denoise.getValue() - 1; target.typingAttenuation = typingCheck.isSelected(); target.agc = agcCheck.isSelected(); target.agcBoostDb = agcBoost.getValue(); activation.writeInto(target); } + private void applyDenoise(VoiceInput mic) { + mic.setNoiseSuppression(denoise.getValue() > 0); + if (denoise.getValue() > 0) mic.setDenoiserLevel(denoise.getValue() - 1); + } + /** Applies a live change to the connected microphone and to the microphone test alike. */ void applyLive(Consumer change) { if (liveMic != null) change.accept(liveMic);