starting work on visualizer
This commit is contained in:
parent
3fca2c57bf
commit
c45551f1d2
@ -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;
|
||||
|
@ -46,8 +46,6 @@ public class AudioInfo implements Disposable {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
// invalidMusic = true;
|
||||
|
||||
} else {
|
||||
|
||||
try {
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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];
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
33
core/src/zero1hd/rhythmbullet/ui/builders/Visualizer.java
Executable file
33
core/src/zero1hd/rhythmbullet/ui/builders/Visualizer.java
Executable file
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user