Skip to content

Commit 50df6b1

Browse files
committed
Added option to disable normalization when exporting with AudioMixer
1 parent deadebc commit 50df6b1

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/main/java/net/raphimc/noteblocktool/audio/export/impl/AudioMixerAudioExporter.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import net.raphimc.audiomixer.AudioMixer;
2121
import net.raphimc.audiomixer.pcmsource.impl.MonoIntPcmSource;
2222
import net.raphimc.audiomixer.sound.impl.pcm.OptimizedMonoSound;
23+
import net.raphimc.audiomixer.soundmodifier.impl.NormalizationModifier;
2324
import net.raphimc.audiomixer.util.AudioFormats;
2425
import net.raphimc.audiomixer.util.SoundSampleUtil;
2526
import net.raphimc.audiomixer.util.io.SoundIO;
@@ -36,18 +37,24 @@
3637

3738
public class AudioMixerAudioExporter extends AudioExporter {
3839

40+
private final boolean globalNormalization;
3941
protected final Map<String, int[]> sounds;
4042
protected final AudioMixer audioMixer;
4143

42-
public AudioMixerAudioExporter(final SongView<?> songView, final AudioFormat format, final float masterVolume, final Consumer<Float> progressConsumer) {
44+
public AudioMixerAudioExporter(final SongView<?> songView, final AudioFormat format, final float masterVolume, final boolean globalNormalization, final Consumer<Float> progressConsumer) {
4345
super(songView, format, masterVolume, progressConsumer);
46+
this.globalNormalization = globalNormalization;
47+
4448
try {
4549
this.sounds = new HashMap<>();
4650
for (Map.Entry<String, byte[]> entry : SoundMap.loadSoundData(songView).entrySet()) {
4751
this.sounds.put(entry.getKey(), SoundIO.readSamples(SoundFileUtil.readAudioFile(new ByteArrayInputStream(entry.getValue())), AudioFormats.withChannels(format, 1)));
4852
}
4953
this.audioMixer = new AudioMixer(format);
5054
this.audioMixer.getMasterMixSound().setMaxSounds(8192);
55+
if (!this.globalNormalization) {
56+
this.audioMixer.getMasterMixSound().getSoundModifiers().append(new NormalizationModifier());
57+
}
5158
} catch (Throwable e) {
5259
throw new RuntimeException("Failed to initialize AudioMixer audio exporter", e);
5360
}
@@ -67,7 +74,9 @@ protected void postTick() {
6774

6875
@Override
6976
protected void finish() {
70-
SoundSampleUtil.normalize(this.samples.getArrayDirect(), (int) Math.pow(2, this.format.getSampleSizeInBits() - 1) - 1);
77+
if (this.globalNormalization) {
78+
SoundSampleUtil.normalize(this.samples.getArrayDirect(), (int) Math.pow(2, this.format.getSampleSizeInBits() - 1) - 1);
79+
}
7180
}
7281

7382
}

src/main/java/net/raphimc/noteblocktool/frames/ExportFrame.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class ExportFrame extends JFrame {
6868
private final List<ListFrame.LoadedSong> loadedSongs;
6969
private final JComboBox<String> format = new JComboBox<>(new String[]{"NBS", "MP3 (Using LAME encoder)", "WAV", "AIF"});
7070
private final JLabel soundSystemLabel = new JLabel("Sound System:");
71-
private final JComboBox<String> soundSystem = new JComboBox<>(new String[]{"OpenAL (best sound quality, fastest)", "AudioMixer (normalized)", "Un4seen BASS"});
71+
private final JComboBox<String> soundSystem = new JComboBox<>(new String[]{"OpenAL (best sound quality, fastest)", "AudioMixer", "AudioMixer (global normalized)", "Un4seen BASS"});
7272
private final JLabel sampleRateLabel = new JLabel("Sample Rate:");
7373
private final JSpinner sampleRate = new JSpinner(new SpinnerNumberModel(48000, 8000, 192000, 8000));
7474
private final JLabel bitDepthLabel = new JLabel("PCM Bit Depth:");
@@ -267,7 +267,7 @@ private File openFileChooser() {
267267
private void doExport(final File outFile) {
268268
final boolean isAudioFile = this.format.getSelectedIndex() != 0;
269269
final boolean isMp3 = this.format.getSelectedIndex() == 1;
270-
final boolean bassSoundSystem = this.soundSystem.getSelectedIndex() == 2;
270+
final boolean bassSoundSystem = this.soundSystem.getSelectedIndex() == 3;
271271
final AudioFormat format = new AudioFormat(
272272
((Number) this.sampleRate.getValue()).floatValue(),
273273
!isMp3 ? Integer.parseInt(this.bitDepth.getSelectedItem().toString().substring(4)) : 16,
@@ -413,8 +413,10 @@ private void exportSong(final ListFrame.LoadedSong song, final AudioFormat forma
413413
if (this.soundSystem.getSelectedIndex() == 0) {
414414
exporter = new OpenALAudioExporter(songView, format, this.volume.getValue() / 100F, progressConsumer);
415415
} else if (this.soundSystem.getSelectedIndex() == 1) {
416-
exporter = new AudioMixerAudioExporter(songView, format, this.volume.getValue() / 100F, progressConsumer);
416+
exporter = new AudioMixerAudioExporter(songView, format, this.volume.getValue() / 100F, false, progressConsumer);
417417
} else if (this.soundSystem.getSelectedIndex() == 2) {
418+
exporter = new AudioMixerAudioExporter(songView, format, this.volume.getValue() / 100F, true, progressConsumer);
419+
} else if (this.soundSystem.getSelectedIndex() == 3) {
418420
exporter = new BassAudioExporter(songView, format, this.volume.getValue() / 100F, progressConsumer);
419421
} else {
420422
throw new UnsupportedOperationException("Unsupported sound system: " + this.soundSystem.getSelectedIndex());

0 commit comments

Comments
 (0)