From a15e1c61b2d984ae5cdca402f95d9f7e25c41eda Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Thu, 9 May 2024 20:20:47 +0200 Subject: [PATCH] Cleaned up code --- .../raphimc/noteblocktool/audio/soundsystem/SoundSystem.java | 5 +---- .../audio/soundsystem/impl/JavaxSoundSystem.java | 5 +++-- .../java/net/raphimc/noteblocktool/frames/ExportFrame.java | 2 +- .../net/raphimc/noteblocktool/frames/SongPlayerFrame.java | 2 +- .../java/net/raphimc/noteblocktool/util/SoundSampleUtil.java | 4 ++-- 5 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main/java/net/raphimc/noteblocktool/audio/soundsystem/SoundSystem.java b/src/main/java/net/raphimc/noteblocktool/audio/soundsystem/SoundSystem.java index 261a15c..b32a49d 100644 --- a/src/main/java/net/raphimc/noteblocktool/audio/soundsystem/SoundSystem.java +++ b/src/main/java/net/raphimc/noteblocktool/audio/soundsystem/SoundSystem.java @@ -22,7 +22,6 @@ public abstract class SoundSystem implements AutoCloseable { protected final int maxSounds; - protected float masterVolume = 1F; public SoundSystem(final int maxSounds) { this.maxSounds = maxSounds; @@ -44,8 +43,6 @@ public int getMaxSounds() { public abstract int getSoundCount(); - public void setMasterVolume(final float volume) { - this.masterVolume = volume; - } + public abstract void setMasterVolume(final float volume); } diff --git a/src/main/java/net/raphimc/noteblocktool/audio/soundsystem/impl/JavaxSoundSystem.java b/src/main/java/net/raphimc/noteblocktool/audio/soundsystem/impl/JavaxSoundSystem.java index b773429..ed1a806 100644 --- a/src/main/java/net/raphimc/noteblocktool/audio/soundsystem/impl/JavaxSoundSystem.java +++ b/src/main/java/net/raphimc/noteblocktool/audio/soundsystem/impl/JavaxSoundSystem.java @@ -37,6 +37,7 @@ public class JavaxSoundSystem extends SoundSystem { private final int samplesPerTick; private final SourceDataLine dataLine; private final Map mutationCache; + private float masterVolume = 1F; private long[] buffer = new long[0]; public JavaxSoundSystem(final float playbackSpeed) { @@ -50,7 +51,7 @@ public JavaxSoundSystem(final float playbackSpeed) { this.dataLine.start(); this.mutationCache = new ConcurrentHashMap<>(); } catch (Throwable e) { - throw new RuntimeException("Could not initialize javax audio system", e); + throw new RuntimeException("Could not initialize javax sound system", e); } } @@ -87,7 +88,7 @@ public int getSoundCount() { @Override public void setMasterVolume(final float volume) { - super.setMasterVolume(volume); + this.masterVolume = volume; this.mutationCache.clear(); } diff --git a/src/main/java/net/raphimc/noteblocktool/frames/ExportFrame.java b/src/main/java/net/raphimc/noteblocktool/frames/ExportFrame.java index 33b519a..a704ddc 100644 --- a/src/main/java/net/raphimc/noteblocktool/frames/ExportFrame.java +++ b/src/main/java/net/raphimc/noteblocktool/frames/ExportFrame.java @@ -59,7 +59,7 @@ public class ExportFrame extends JFrame { private final List loadedSongs; private final JComboBox format = new JComboBox<>(new String[]{"NBS", "WAV", "AIF"}); private final JLabel soundSystemLabel = new JLabel("Sound System:"); - private final JComboBox soundSystem = new JComboBox<>(new String[]{"OpenAL (better sound quality)", "Javax (faster, normalized, mono only)"}); + private final JComboBox soundSystem = new JComboBox<>(new String[]{"OpenAL (better sound quality)", "Javax (faster, normalized)"}); private final JLabel sampleRateLabel = new JLabel("Sample Rate:"); private final JSpinner sampleRate = new JSpinner(new SpinnerNumberModel(44_100, 8_000, 192_000, 1_000)); private final JLabel bitDepthLabel = new JLabel("PCM Bit Depth:"); diff --git a/src/main/java/net/raphimc/noteblocktool/frames/SongPlayerFrame.java b/src/main/java/net/raphimc/noteblocktool/frames/SongPlayerFrame.java index e37dff6..c7d644c 100644 --- a/src/main/java/net/raphimc/noteblocktool/frames/SongPlayerFrame.java +++ b/src/main/java/net/raphimc/noteblocktool/frames/SongPlayerFrame.java @@ -76,7 +76,7 @@ public static void close() { private final ListFrame.LoadedSong song; private final SongPlayer songPlayer; private final Timer updateTimer; - private final JComboBox soundSystemComboBox = new JComboBox<>(new String[]{"OpenAL (better sound quality)", "Javax (better system compatibility, mono only)"}); + private final JComboBox soundSystemComboBox = new JComboBox<>(new String[]{"OpenAL (better sound quality)", "Javax (better system compatibility)"}); private final JSpinner maxSoundsSpinner = new JSpinner(new SpinnerNumberModel(256, 64, 8192, 64)); private final JSlider volumeSlider = new JSlider(0, 100, 50); private final JButton playStopButton = new JButton("Play"); diff --git a/src/main/java/net/raphimc/noteblocktool/util/SoundSampleUtil.java b/src/main/java/net/raphimc/noteblocktool/util/SoundSampleUtil.java index 6fa9cb7..3c081f7 100644 --- a/src/main/java/net/raphimc/noteblocktool/util/SoundSampleUtil.java +++ b/src/main/java/net/raphimc/noteblocktool/util/SoundSampleUtil.java @@ -101,10 +101,10 @@ public static int[] mutate(final AudioFormat format, final int[] samples, final } for (int i = 0; i < newLength / format.getChannels(); i++) { - int oldIndex = (int) (i * pitch) * format.getChannels() + channel; + final int oldIndex = (int) (i * pitch) * format.getChannels() + channel; if (pitch < 1 && oldIndex < samples.length - format.getChannels()) { // Interpolate between the current sample and the next one - float ratio = (i * pitch) % 1; + final float ratio = (i * pitch) % 1; newSamples[i * format.getChannels() + channel] = (int) ((samples[oldIndex] * (1 - ratio) + samples[oldIndex + format.getChannels()] * ratio) * channelVolume); } else if (oldIndex < samples.length) { newSamples[i * format.getChannels() + channel] = (int) (samples[oldIndex] * channelVolume);