main menu particles fine tuning with visual debug
This commit is contained in:
parent
7130d9872c
commit
d3c166c6d5
@ -22,16 +22,18 @@ public class DoubleHorizontalVisualizer implements Disposable {
|
||||
private float offset;
|
||||
private int boundaryThickness;
|
||||
private boolean significantBeat;
|
||||
private float maxAverageAmplitude;
|
||||
private float dynamicAverageAmplitude;
|
||||
private byte significantFrames;
|
||||
private float targetDelta;
|
||||
private float significantThreshold = 0.5f;
|
||||
private float spacePercentage = 0.7f;
|
||||
private float baseSensitivity = 0.009f;
|
||||
private int barCount = 120;
|
||||
private float barChangeRate = 6.5f;
|
||||
private int smoothRange = 2;
|
||||
private int binsToInclude = 120;
|
||||
private Color colorBegin = new Color(0.5f, 0.6f, 0.8f, 0.46f);
|
||||
private Color color = new Color(0.5f, 0.6f, 0.8f, 0.46f);
|
||||
private int averageAmplitude;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -58,11 +60,11 @@ public class DoubleHorizontalVisualizer implements Disposable {
|
||||
|
||||
public void act(float delta) {
|
||||
if (pcm.hasAudioChanged()) {
|
||||
maxAverageAmplitude = 0;
|
||||
dynamicAverageAmplitude = 0;
|
||||
significantBeat = false;
|
||||
}
|
||||
float[] freqBins = pcm.getFrequencyBins();
|
||||
float averageAmplitude = 0;
|
||||
averageAmplitude = 0;
|
||||
for (int bar = 0; bar < amplitudes.length; bar++) {
|
||||
amplitudes[bar] = 0;
|
||||
for (int freq = bar*binsPerBar; freq < (bar*binsPerBar) + binsPerBar; freq++) {
|
||||
@ -74,21 +76,24 @@ public class DoubleHorizontalVisualizer implements Disposable {
|
||||
}
|
||||
|
||||
averageAmplitude /= amplitudes.length;
|
||||
if (averageAmplitude > maxAverageAmplitude*0.5f && !significantBeat) {
|
||||
if (maxAverageAmplitude != 0) {
|
||||
if (averageAmplitude < dynamicAverageAmplitude) {
|
||||
dynamicAverageAmplitude -= 0.01f;
|
||||
} else {
|
||||
dynamicAverageAmplitude = averageAmplitude;
|
||||
}
|
||||
if (averageAmplitude > dynamicAverageAmplitude*significantThreshold && !significantBeat) {
|
||||
if (dynamicAverageAmplitude > 0) {
|
||||
significantFrames++;
|
||||
if (significantFrames >= 16) {
|
||||
significantFrames = 0;
|
||||
significantBeat = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (averageAmplitude > maxAverageAmplitude) {
|
||||
maxAverageAmplitude = averageAmplitude;
|
||||
}
|
||||
} else {
|
||||
significantBeat = false;
|
||||
significantFrames = 0;
|
||||
}
|
||||
|
||||
for (int bar = 0; bar < barHeights.length; bar++) {
|
||||
int smoothCount = 1;
|
||||
for (int range = 0; range < smoothRange; range++) {
|
||||
@ -136,10 +141,20 @@ public class DoubleHorizontalVisualizer implements Disposable {
|
||||
}
|
||||
|
||||
for (int bar = 0; bar < barCount; bar++) {
|
||||
shapeRenderer.setColor(colorBegin);
|
||||
shapeRenderer.setColor(color);
|
||||
shapeRenderer.rect(offset + (spaceBetweenBars+barWidth)*bar, y+height, barWidth, barHeights[bar]);
|
||||
shapeRenderer.rect(offset + (spaceBetweenBars+barWidth)*bar, y, barWidth, -barHeights[barHeights.length - 1 - bar]);
|
||||
}
|
||||
shapeRenderer.setColor(Color.RED);
|
||||
shapeRenderer.rect(0, dynamicAverageAmplitude+y, width, 1);
|
||||
if (significantBeat) {
|
||||
shapeRenderer.setColor(Color.GREEN);
|
||||
} else {
|
||||
shapeRenderer.setColor(Color.WHITE);
|
||||
}
|
||||
shapeRenderer.rect(0, averageAmplitude+y, width, 1);
|
||||
shapeRenderer.setColor(Color.YELLOW);
|
||||
shapeRenderer.rect(0, dynamicAverageAmplitude*significantThreshold + y, width, 1);
|
||||
shapeRenderer.end();
|
||||
Gdx.gl.glDisable(GL20.GL_BLEND);
|
||||
batch.begin();
|
||||
|
@ -63,24 +63,26 @@ public class PCMObtainer implements Observer, PCMSystem {
|
||||
df.setRoundingMode(RoundingMode.HALF_EVEN);
|
||||
}
|
||||
|
||||
private synchronized boolean calcPCMData() {
|
||||
boolean empty = true;
|
||||
short chanVal;
|
||||
for (int sid = 0; sid < PCM.length && sid < playingBuffer.remaining(); sid++) {
|
||||
PCM[sid] = 0;
|
||||
for (int channel = 0; channel < channelCount; channel++) {
|
||||
if (PCM[sid] < (chanVal = playingBuffer.get())) {
|
||||
PCM[sid] = chanVal;
|
||||
private boolean calcPCMData() {
|
||||
synchronized (PCM) {
|
||||
boolean empty = true;
|
||||
short chanVal;
|
||||
for (int sid = 0; sid < PCM.length && sid < playingBuffer.remaining(); sid++) {
|
||||
PCM[sid] = 0;
|
||||
for (int channel = 0; channel < channelCount; channel++) {
|
||||
if (PCM[sid] < (chanVal = playingBuffer.get())) {
|
||||
PCM[sid] = chanVal;
|
||||
}
|
||||
}
|
||||
PCM[sid] /= Short.MAX_VALUE + 1f;
|
||||
|
||||
if (PCM[sid] != 0) {
|
||||
empty = false;
|
||||
}
|
||||
|
||||
}
|
||||
PCM[sid] /= Short.MAX_VALUE + 1f;
|
||||
|
||||
if (PCM[sid] != 0) {
|
||||
empty = false;
|
||||
}
|
||||
|
||||
return empty;
|
||||
}
|
||||
return empty;
|
||||
}
|
||||
|
||||
private void checkValidityOfPlaybackBuffer() {
|
||||
@ -138,7 +140,8 @@ public class PCMObtainer implements Observer, PCMSystem {
|
||||
public float[] getFrequencyBins() {
|
||||
if (mc.isPlaying()) {
|
||||
if (updated) {
|
||||
synchronized (this) {
|
||||
synchronized (PCM) {
|
||||
fft.realForward(PCM);
|
||||
System.arraycopy(PCM, 1, frequencyBins, 0, frequencyBins.length);
|
||||
}
|
||||
updated = false;
|
||||
@ -174,9 +177,6 @@ public class PCMObtainer implements Observer, PCMSystem {
|
||||
//calculate current pcm data and notify that there is new data
|
||||
checkValidityOfPlaybackBuffer();
|
||||
updated = !calcPCMData();
|
||||
if (updated) {
|
||||
fft.realForward(PCM);
|
||||
}
|
||||
windowsRead++;
|
||||
|
||||
//contemplate synchronization
|
||||
|
@ -286,7 +286,7 @@ public class MusicSelectionPage extends Page implements Observer {
|
||||
if (!selectable.isOffScreen()) {
|
||||
selectable.getMetadata().loadAlbumCover();
|
||||
selectable.loadAttempted();
|
||||
simpleDebug("Loaded " + selectable.getMetadata().getTitle());
|
||||
simpleDebug("Loaded album cover of " + selectable.getMetadata().getTitle());
|
||||
} else {
|
||||
simpleDebug("Skipping " + selectable.getMetadata().getTitle());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user