diff --git a/core/src/zero1hd/rhythmbullet/audio/AudioAnalyzer.java b/core/src/zero1hd/rhythmbullet/audio/AudioAnalyzer.java index c17d95c..93d4b06 100755 --- a/core/src/zero1hd/rhythmbullet/audio/AudioAnalyzer.java +++ b/core/src/zero1hd/rhythmbullet/audio/AudioAnalyzer.java @@ -12,7 +12,6 @@ import zero1hd.rhythmbullet.util.MiniSender; public class AudioAnalyzer { private boolean containsData; - FloatFFT_1D fft; private CoreMusicInfo musicInfo; float[] audioPCM; @@ -91,7 +90,7 @@ public class AudioAnalyzer { Gdx.app.debug("Threshold Calc Range M", String.valueOf(umThresholdCalcRange)); Gdx.app.debug("Threshold Calc Range Bass", String.valueOf(bassThresholdCalcRange)); - fft = new FloatFFT_1D(musicInfo.getReadWindowSize()); + FloatFFT_1D fft = new FloatFFT_1D(musicInfo.getReadWindowSize()); int seedDigit = 0; while (musicInfo.readSamples(audioPCM) > 0 && work) { @@ -311,12 +310,6 @@ public class AudioAnalyzer { exec.submit(analysisAlgorithm); } - public void shrinkData() { - bassSpectralFlux = null; - mSpectralFlux = null; - umSpectralFlux = null; - } - public void runThresholdCleaning(float rangeModifier) { this.bassThresholdMultiplier -= rangeModifier; this.umThresholdMultiplier -= rangeModifier; diff --git a/core/src/zero1hd/rhythmbullet/audio/AudioInfo.java b/core/src/zero1hd/rhythmbullet/audio/AudioInfo.java index b8f941f..4ca9ee9 100755 --- a/core/src/zero1hd/rhythmbullet/audio/AudioInfo.java +++ b/core/src/zero1hd/rhythmbullet/audio/AudioInfo.java @@ -46,8 +46,6 @@ public class AudioInfo implements Disposable { e.printStackTrace(); } -// invalidMusic = true; - } else { try { diff --git a/core/src/zero1hd/rhythmbullet/audio/CoreMusicInfo.java b/core/src/zero1hd/rhythmbullet/audio/CoreMusicInfo.java index 36ce13e..48095b3 100755 --- a/core/src/zero1hd/rhythmbullet/audio/CoreMusicInfo.java +++ b/core/src/zero1hd/rhythmbullet/audio/CoreMusicInfo.java @@ -9,13 +9,13 @@ public interface CoreMusicInfo 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. */ - public void readIndexUpdate(); + public void playbackIndexUpdate(); /** * Gets the current position in seconds s * @return the current frame of audio. */ - public int getReadIndex(); + public int getPlaybackIndexPosition(); /** * Completely resets the current audio data. Think of pooling, except, only one instance which is reused instead of multiple. @@ -59,4 +59,10 @@ public interface CoreMusicInfo extends Disposable { * @return sample rate as float */ public float getSampleRate(); + + /** + * The current numerical value of the last window read + * @return + */ + public int getCurrentReadWindowIndex(); } diff --git a/core/src/zero1hd/rhythmbullet/audio/Mp3AudioData.java b/core/src/zero1hd/rhythmbullet/audio/Mp3AudioData.java index 6a9a04d..f929d9e 100755 --- a/core/src/zero1hd/rhythmbullet/audio/Mp3AudioData.java +++ b/core/src/zero1hd/rhythmbullet/audio/Mp3AudioData.java @@ -22,7 +22,8 @@ import javazoom.jl.decoder.OutputBuffer; public class Mp3AudioData implements CoreMusicInfo { private int readWindowSize = 1024; - + + private int currentReadWindowIndex; private Music playbackMusic; private int readIndex; @@ -67,12 +68,12 @@ public class Mp3AudioData implements CoreMusicInfo { } @Override - public void readIndexUpdate() { + public void playbackIndexUpdate() { readIndex = (int) (playbackMusic.getPosition() * sampleRate / readWindowSize); } @Override - public int getReadIndex() { + public int getPlaybackIndexPosition() { return readIndex; } @@ -130,6 +131,9 @@ public class Mp3AudioData implements CoreMusicInfo { samples[sid] /= Short.MAX_VALUE+1; } } + if (framesRead != 0) { + currentReadWindowIndex++; + } return framesRead; } @@ -175,4 +179,9 @@ public class Mp3AudioData implements CoreMusicInfo { public float getSampleRate() { return sampleRate; } + + @Override + public int getCurrentReadWindowIndex() { + return currentReadWindowIndex; + } } diff --git a/core/src/zero1hd/rhythmbullet/audio/WavAudioData.java b/core/src/zero1hd/rhythmbullet/audio/WavAudioData.java index cb3a423..b71ec12 100755 --- a/core/src/zero1hd/rhythmbullet/audio/WavAudioData.java +++ b/core/src/zero1hd/rhythmbullet/audio/WavAudioData.java @@ -14,7 +14,8 @@ import zero1hd.wavedecoder.WavDecoder; public class WavAudioData implements CoreMusicInfo { private int readWindowSize = 1024; private AudioFormat format; - int readIndex; + private int readIndex; + private int currentReadWindowIndex; Music playbackMusic; WavDecoder decoder; @@ -31,12 +32,12 @@ public class WavAudioData implements CoreMusicInfo { } @Override - public void readIndexUpdate() { + public void playbackIndexUpdate() { readIndex = (int) (playbackMusic.getPosition() * decoder.getSampleRate() / readWindowSize); } @Override - public int getReadIndex() { + public int getPlaybackIndexPosition() { return readIndex; } @@ -65,6 +66,10 @@ public class WavAudioData implements CoreMusicInfo { } catch (IOException e) { e.printStackTrace(); } + + if (samplesRead != 0) { + currentReadWindowIndex++; + } return samplesRead; } @@ -89,4 +94,9 @@ public class WavAudioData implements CoreMusicInfo { public float getSampleRate() { return format.getSampleRate(); } + + @Override + public int getCurrentReadWindowIndex() { + return currentReadWindowIndex; + } } diff --git a/core/src/zero1hd/rhythmbullet/audio/map/GamePlayMap.java b/core/src/zero1hd/rhythmbullet/audio/map/GamePlayMap.java index 400796b..c125cba 100755 --- a/core/src/zero1hd/rhythmbullet/audio/map/GamePlayMap.java +++ b/core/src/zero1hd/rhythmbullet/audio/map/GamePlayMap.java @@ -91,8 +91,8 @@ public class GamePlayMap { } public MapWindowData getCurrentWindowBasedOnIndex() { - if (index != musicData.getReadIndex()) { - index = musicData.getReadIndex(); + if (index != musicData.getPlaybackIndexPosition()) { + index = musicData.getPlaybackIndexPosition(); if (index < spawnList.length) { return spawnList[index]; } diff --git a/core/src/zero1hd/rhythmbullet/stages/GamePlayArea.java b/core/src/zero1hd/rhythmbullet/stages/GamePlayArea.java index 0715e8a..eb88446 100755 --- a/core/src/zero1hd/rhythmbullet/stages/GamePlayArea.java +++ b/core/src/zero1hd/rhythmbullet/stages/GamePlayArea.java @@ -60,7 +60,7 @@ public class GamePlayArea extends Stage { public void act(float delta) { MapWindowData mwd; if (audioMap != null && audioMap.getMusicData().getPlaybackMusic().isPlaying()) { - audioMap.getMusicData().readIndexUpdate(); + audioMap.getMusicData().playbackIndexUpdate(); if ((mwd = audioMap.getCurrentWindowBasedOnIndex()) != null) { EntitySpawnInfo[] currentSpawnInfo = mwd.getArray(); if (currentSpawnInfo != null) { diff --git a/core/src/zero1hd/rhythmbullet/ui/builders/AudioGraph.java b/core/src/zero1hd/rhythmbullet/ui/builders/AudioGraph.java index cde02a6..d1ca4d5 100755 --- a/core/src/zero1hd/rhythmbullet/ui/builders/AudioGraph.java +++ b/core/src/zero1hd/rhythmbullet/ui/builders/AudioGraph.java @@ -123,7 +123,7 @@ public class AudioGraph extends Actor { @Override public void act(float delta) { if (audioData != null) { - setAudioDataIndex(audioData.getReadIndex()); + setAudioDataIndex(audioData.getPlaybackIndexPosition()); } super.act(delta); } diff --git a/core/src/zero1hd/rhythmbullet/ui/builders/AudioGraphRelation.java b/core/src/zero1hd/rhythmbullet/ui/builders/AudioGraphRelation.java index 2215779..b999629 100755 --- a/core/src/zero1hd/rhythmbullet/ui/builders/AudioGraphRelation.java +++ b/core/src/zero1hd/rhythmbullet/ui/builders/AudioGraphRelation.java @@ -123,7 +123,7 @@ public class AudioGraphRelation extends Actor { @Override public void act(float delta) { if (audioData != null) { - setAudioDataIndex(audioData.getReadIndex()); + setAudioDataIndex(audioData.getPlaybackIndexPosition()); } super.act(delta); } diff --git a/core/src/zero1hd/rhythmbullet/ui/builders/Visualizer.java b/core/src/zero1hd/rhythmbullet/ui/builders/Visualizer.java new file mode 100755 index 0000000..f04bd49 --- /dev/null +++ b/core/src/zero1hd/rhythmbullet/ui/builders/Visualizer.java @@ -0,0 +1,33 @@ +package zero1hd.rhythmbullet.ui.builders; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.scenes.scene2d.Actor; + +import edu.emory.mathcs.jtransforms.fft.FloatFFT_1D; +import zero1hd.rhythmbullet.audio.CoreMusicInfo; + +public class Visualizer extends Actor { + private CoreMusicInfo cmi; + private FloatFFT_1D fft; + float[] audioPCM; + + public Visualizer() { + fft = new FloatFFT_1D(cmi.getReadWindowSize()); + audioPCM = new float[cmi.getReadWindowSize()]; + + setSize(Gdx.graphics.getHeight()*0.6f, Gdx.graphics.getHeight()*0.6f); + } + + @Override + public void act(float delta) { + if (cmi.getPlaybackIndexPosition() > cmi.getCurrentReadWindowIndex()) { + cmi.readSamples(audioPCM); + Gdx.app.debug("Visualizer", "Skipping a frame to catch up to music."); + } else { + Gdx.app.debug("Visualizer", "Not reading so music can catch up."); + } + + fft.realForward(audioPCM); + super.act(delta); + } +} diff --git a/core/src/zero1hd/rhythmbullet/ui/windows/BeatViewer.java b/core/src/zero1hd/rhythmbullet/ui/windows/BeatViewer.java index df6f448..f7df927 100755 --- a/core/src/zero1hd/rhythmbullet/ui/windows/BeatViewer.java +++ b/core/src/zero1hd/rhythmbullet/ui/windows/BeatViewer.java @@ -120,7 +120,7 @@ public class BeatViewer extends Window { @Override public void act(float delta) { if (music != null) { - songIndex = music.getReadIndex(); + songIndex = music.getPlaybackIndexPosition(); } super.act(delta); }