visualizer now directly grabs data from openal.. slightly less synched for better efficiency?
This commit is contained in:
@@ -64,7 +64,7 @@ public class BasicVisualizer extends VisualizerCore {
|
||||
super.render(batch, parentAlpha);
|
||||
}
|
||||
|
||||
public void modify(float delta) {
|
||||
public void update(float delta) {
|
||||
//Averaging bins together
|
||||
for (int i = 0; i < barCount; i++) {
|
||||
float barHeight = 0;
|
||||
@@ -104,13 +104,13 @@ public class BasicVisualizer extends VisualizerCore {
|
||||
|
||||
@Override
|
||||
public void setMM(MusicManager mm) {
|
||||
super.setMM(mm);
|
||||
maxAvgHeight = 0;
|
||||
currentAvg = 0;
|
||||
float validBins = (5500/((mm.getSampleRate()/2)/((audioPCM.length/2)+1)));
|
||||
float validBins = (5500/((mm.getSampleRate()/2)/((mm.getReadWindowSize()/2)+1)));
|
||||
Gdx.app.debug("Visualizer", "valid frequency bins " + validBins);
|
||||
binsPerBar = MathUtils.round((validBins/barCount));
|
||||
barHeights = new float[barCount];
|
||||
super.setMM(mm);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -11,44 +11,36 @@ import zero1hd.rhythmbullet.util.MusicManager;
|
||||
public class VisualizerCore implements Disposable {
|
||||
protected MusicManager mm;
|
||||
private FloatFFT_1D fft;
|
||||
float[] audioPCM;
|
||||
protected float width, height;
|
||||
protected float xPos, yPos;
|
||||
protected int barCount;
|
||||
private boolean calc;
|
||||
private ReentrantLock lock;
|
||||
private float updateRate;
|
||||
private float updateTimer;
|
||||
protected float[] audioPCM;
|
||||
|
||||
public VisualizerCore(int width, int height, int x, int y) {
|
||||
this.height = height;
|
||||
this.width = width;
|
||||
this.xPos = x;
|
||||
this.yPos = y;
|
||||
updateRate = 1f/60f;
|
||||
lock = new ReentrantLock();
|
||||
}
|
||||
|
||||
public void calculate(float delta) {
|
||||
if (mm != null && calc && mm.isPlaying()) {
|
||||
updateTimer += delta;
|
||||
if (updateTimer >= updateRate) {
|
||||
//TODO use current buffer being played
|
||||
lock.lock();
|
||||
mm.readSamples(audioPCM);
|
||||
fft.realForward(audioPCM);
|
||||
lock.unlock();
|
||||
updateTimer = 0;
|
||||
}
|
||||
lock.lock();
|
||||
fft.realForward(audioPCM);
|
||||
lock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
public void setMM(MusicManager mm) {
|
||||
lock.lock();
|
||||
calc = false;
|
||||
if (audioPCM == null || audioPCM.length != mm.getReadWindowSize()) {
|
||||
calc = false;
|
||||
audioPCM = new float[mm.getReadWindowSize()];
|
||||
fft = new FloatFFT_1D(mm.getReadWindowSize());
|
||||
}
|
||||
audioPCM = new float[mm.getReadWindowSize()];
|
||||
this.mm = mm;
|
||||
calc = true;
|
||||
lock.unlock();
|
||||
@@ -57,7 +49,7 @@ public class VisualizerCore implements Disposable {
|
||||
public void render(Batch batch, float parentAlpha) {
|
||||
}
|
||||
|
||||
public void modify(float delta) {
|
||||
public void update(float delta) {
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -98,11 +90,7 @@ public class VisualizerCore implements Disposable {
|
||||
return mm;
|
||||
}
|
||||
|
||||
public void setUpdateRate(float updateRate) {
|
||||
this.updateRate = updateRate;
|
||||
}
|
||||
|
||||
public float getUpdateRate() {
|
||||
return updateRate;
|
||||
public float[] getAudioPCM() {
|
||||
return audioPCM;
|
||||
}
|
||||
}
|
||||
|
@@ -1,6 +1,7 @@
|
||||
|
||||
package zero1hd.rhythmbullet.util;
|
||||
|
||||
import com.badlogic.gdx.audio.Music;
|
||||
import com.badlogic.gdx.audio.Music.OnCompletionListener;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
@@ -64,6 +65,10 @@ public interface MusicManager extends Disposable {
|
||||
|
||||
public void setVolume(float percent);
|
||||
|
||||
/**
|
||||
* @return the amount of channels this audio file has.
|
||||
*/
|
||||
public int getChannelCount();
|
||||
/**
|
||||
* If the the properties of the song are done loading
|
||||
* @return whether its done loading
|
||||
@@ -86,4 +91,6 @@ public interface MusicManager extends Disposable {
|
||||
* @return the amount of windows that have been read.
|
||||
*/
|
||||
public int framesRead();
|
||||
|
||||
public Music getMusic();
|
||||
}
|
||||
|
Reference in New Issue
Block a user