From 68422f04533f9d173f3ff95b63d2fe36fb860256 Mon Sep 17 00:00:00 2001 From: Recrown Date: Sun, 28 May 2017 23:09:10 -0500 Subject: [PATCH] cleaned code and tuned audio analyzer --- core/src/zero1hd/polyjet/audio/AudioAnalyzer.java | 2 +- core/src/zero1hd/polyjet/audio/AudioData.java | 3 ++- core/src/zero1hd/polyjet/audio/Mp3AudioData.java | 14 +++++++++++--- core/src/zero1hd/polyjet/audio/WavAudioData.java | 4 ++-- .../src/zero1hd/polyjet/screens/PreGameScreen.java | 2 ++ .../polyjet/ui/builders/MusicSelectable.java | 1 - .../polyjet/ui/pages/MusicSelectionPage.java | 1 - .../zero1hd/polyjet/ui/stages/CreativeStage.java | 2 ++ .../src/zero1hd/polyjet/ui/windows/BeatViewer.java | 12 ++++++++++-- core/src/zero1hd/wavedecoder/WavDecoder.java | 7 +++++++ 10 files changed, 37 insertions(+), 11 deletions(-) diff --git a/core/src/zero1hd/polyjet/audio/AudioAnalyzer.java b/core/src/zero1hd/polyjet/audio/AudioAnalyzer.java index 91aa0db..d3cb842 100755 --- a/core/src/zero1hd/polyjet/audio/AudioAnalyzer.java +++ b/core/src/zero1hd/polyjet/audio/AudioAnalyzer.java @@ -65,7 +65,7 @@ public class AudioAnalyzer { UMThresholdMultiplier = 2f; bassBinBegin = 1; - bassBinEnd = 17; + bassBinEnd = 15; UMBinBegin = 300; UMBinEnd = 450; diff --git a/core/src/zero1hd/polyjet/audio/AudioData.java b/core/src/zero1hd/polyjet/audio/AudioData.java index 6afd93e..fd8e5c0 100755 --- a/core/src/zero1hd/polyjet/audio/AudioData.java +++ b/core/src/zero1hd/polyjet/audio/AudioData.java @@ -3,8 +3,9 @@ package zero1hd.polyjet.audio; import javax.sound.sampled.AudioFormat; import com.badlogic.gdx.audio.Music; +import com.badlogic.gdx.utils.Disposable; -public interface AudioData { +public interface AudioData extends Disposable { /** * sets a integer variable to the current window of audio data the playback is at. * Useful for efficiency because we compute once for that frame then get the values everytime it is required instead of calculating every time we get the index. diff --git a/core/src/zero1hd/polyjet/audio/Mp3AudioData.java b/core/src/zero1hd/polyjet/audio/Mp3AudioData.java index 72bcc70..be71182 100755 --- a/core/src/zero1hd/polyjet/audio/Mp3AudioData.java +++ b/core/src/zero1hd/polyjet/audio/Mp3AudioData.java @@ -20,7 +20,6 @@ import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.files.FileHandle; import javazoom.jl.decoder.Decoder; -import javazoom.spi.mpeg.sampled.convert.DecodedMpegAudioInputStream; public class Mp3AudioData implements AudioData { private int readWindowSize = 1024; @@ -35,8 +34,6 @@ public class Mp3AudioData implements AudioData { private AudioInputStream in; - DecodedMpegAudioInputStream dStream; - Decoder decoder = new Decoder(); public Mp3AudioData(FileHandle audioFile) { try { @@ -149,4 +146,15 @@ public class Mp3AudioData implements AudioData { return sampleCount; } + @Override + public void dispose() { + playbackMusic.dispose(); + try { + in.close(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } diff --git a/core/src/zero1hd/polyjet/audio/WavAudioData.java b/core/src/zero1hd/polyjet/audio/WavAudioData.java index c4811b7..0a2d496 100755 --- a/core/src/zero1hd/polyjet/audio/WavAudioData.java +++ b/core/src/zero1hd/polyjet/audio/WavAudioData.java @@ -8,11 +8,10 @@ import javax.sound.sampled.AudioFormat; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.files.FileHandle; -import com.badlogic.gdx.utils.Disposable; import zero1hd.wavedecoder.WavDecoder; -public class WavAudioData implements AudioData, Disposable { +public class WavAudioData implements AudioData { private int readWindowSize = 1024; private AudioFormat format; int readIndex; @@ -78,5 +77,6 @@ public class WavAudioData implements AudioData, Disposable { @Override public void dispose() { playbackMusic.dispose(); + decoder.cleanAndClose(); } } diff --git a/core/src/zero1hd/polyjet/screens/PreGameScreen.java b/core/src/zero1hd/polyjet/screens/PreGameScreen.java index f7f190b..6125f4b 100755 --- a/core/src/zero1hd/polyjet/screens/PreGameScreen.java +++ b/core/src/zero1hd/polyjet/screens/PreGameScreen.java @@ -72,6 +72,8 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter, M core.setScreen(new MainMenu(core).postTransition()); } break; + default: + break; } } diff --git a/core/src/zero1hd/polyjet/ui/builders/MusicSelectable.java b/core/src/zero1hd/polyjet/ui/builders/MusicSelectable.java index f0d434f..7b96181 100755 --- a/core/src/zero1hd/polyjet/ui/builders/MusicSelectable.java +++ b/core/src/zero1hd/polyjet/ui/builders/MusicSelectable.java @@ -7,7 +7,6 @@ import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.scenes.scene2d.ui.Button; import com.badlogic.gdx.scenes.scene2d.ui.Image; import com.badlogic.gdx.scenes.scene2d.ui.Label; -import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane; import com.badlogic.gdx.scenes.scene2d.ui.Skin; import com.badlogic.gdx.scenes.scene2d.ui.Table; import com.badlogic.gdx.utils.Align; diff --git a/core/src/zero1hd/polyjet/ui/pages/MusicSelectionPage.java b/core/src/zero1hd/polyjet/ui/pages/MusicSelectionPage.java index 07d0622..c58566f 100755 --- a/core/src/zero1hd/polyjet/ui/pages/MusicSelectionPage.java +++ b/core/src/zero1hd/polyjet/ui/pages/MusicSelectionPage.java @@ -2,7 +2,6 @@ package zero1hd.polyjet.ui.pages; import java.io.File; import java.io.FilenameFilter; -import java.util.Arrays; import java.util.logging.Level; import java.util.logging.Logger; diff --git a/core/src/zero1hd/polyjet/ui/stages/CreativeStage.java b/core/src/zero1hd/polyjet/ui/stages/CreativeStage.java index ea2f6b6..2bf49ad 100755 --- a/core/src/zero1hd/polyjet/ui/stages/CreativeStage.java +++ b/core/src/zero1hd/polyjet/ui/stages/CreativeStage.java @@ -58,6 +58,7 @@ public class CreativeStage extends Stage implements MiniListener { @Override public void changed(ChangeEvent event, Actor actor) { dispose(); + musicSelector.getSelectedMusic().reset(); core.setScreen(mainMenu); } }); @@ -188,6 +189,7 @@ public class CreativeStage extends Stage implements MiniListener { @Override public void dispose() { + musicSelector.getSelectedMusic().dispose(); super.dispose(); } diff --git a/core/src/zero1hd/polyjet/ui/windows/BeatViewer.java b/core/src/zero1hd/polyjet/ui/windows/BeatViewer.java index 85d5128..8fcc185 100755 --- a/core/src/zero1hd/polyjet/ui/windows/BeatViewer.java +++ b/core/src/zero1hd/polyjet/ui/windows/BeatViewer.java @@ -43,7 +43,11 @@ public class BeatViewer extends Window { public void act(float delta) { if (music != null && data.getBassPeaks().get(songIndex) != 0) { clearActions(); - addAction(Actions.sequence(Actions.sizeTo(getWidth(), (data.getBassPeaks().get(songIndex)/data.getBassMaxValue())*bgBassBar.getHeight()), Actions.sizeTo(getWidth(), 0, 0.3f))); + try { + addAction(Actions.sequence(Actions.sizeTo(getWidth(), (data.getBassPeaks().get(songIndex)/data.getBassMaxValue())*bgBassBar.getHeight()), Actions.sizeTo(getWidth(), 0, 0.3f))); + } catch (IndexOutOfBoundsException e) { + + } } super.act(delta); } @@ -62,7 +66,11 @@ public class BeatViewer extends Window { public void act(float delta) { if (music != null && data.getUMPeaks().get(songIndex) != 0) { clearActions(); - addAction(Actions.sequence(Actions.sizeTo(getWidth(), (data.getUMPeaks().get(songIndex)/data.getUMMaxValue())*bgUMBar.getHeight()), Actions.sizeTo(getWidth(), 0f, 0.3f))); + try { + addAction(Actions.sequence(Actions.sizeTo(getWidth(), (data.getUMPeaks().get(songIndex)/data.getUMMaxValue())*bgUMBar.getHeight()), Actions.sizeTo(getWidth(), 0f, 0.3f))); + } catch (IndexOutOfBoundsException e) { + + } } super.act(delta); } diff --git a/core/src/zero1hd/wavedecoder/WavDecoder.java b/core/src/zero1hd/wavedecoder/WavDecoder.java index 935de05..6f1d89b 100755 --- a/core/src/zero1hd/wavedecoder/WavDecoder.java +++ b/core/src/zero1hd/wavedecoder/WavDecoder.java @@ -148,4 +148,11 @@ public class WavDecoder { return samplesRead; } + public void cleanAndClose() { + try { + readStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } }