added pellet gen
This commit is contained in:
parent
0cf0609442
commit
897f802885
@ -27,19 +27,21 @@ public class AudioAnalyzer {
|
||||
private FloatArray bassPrunned = new FloatArray();
|
||||
private FloatArray bassPeaks = new FloatArray();
|
||||
private float bassMaxValue;
|
||||
private float bassAvg;
|
||||
|
||||
int UMBinBegin;
|
||||
int UMBinEnd;
|
||||
private FloatArray UMSpectralFlux = new FloatArray();
|
||||
private FloatArray UMThreshold = new FloatArray();
|
||||
private FloatArray UMPrunned = new FloatArray();
|
||||
private FloatArray UMPeaks = new FloatArray();
|
||||
private FloatArray umSpectralFlux = new FloatArray();
|
||||
private FloatArray umThreshold = new FloatArray();
|
||||
private FloatArray umPrunned = new FloatArray();
|
||||
private FloatArray umPeaks = new FloatArray();
|
||||
private float UMMaxValue;
|
||||
private float umAvg;
|
||||
|
||||
private FloatArray overlappedPeaks = new FloatArray();
|
||||
|
||||
float bassThresholdMultiplier;
|
||||
float UMThresholdMultiplier;
|
||||
float umThresholdMultiplier;
|
||||
int UMThresholdCalcRange;
|
||||
int bassThresholdCalcRange;
|
||||
|
||||
@ -64,7 +66,7 @@ public class AudioAnalyzer {
|
||||
int totalTasks = audioData.getSampleCount()/audioData.getReadWindowSize();
|
||||
|
||||
bassThresholdMultiplier = 1.5f;
|
||||
UMThresholdMultiplier = 2f;
|
||||
umThresholdMultiplier = 2f;
|
||||
|
||||
bassBinBegin = 1;
|
||||
bassBinEnd = 15;
|
||||
@ -120,7 +122,7 @@ public class AudioAnalyzer {
|
||||
fluxVal += ((spectrum[i] - lastSpectrum[i])) > 0
|
||||
? (spectrum[i] - lastSpectrum[i]) : 0;
|
||||
}
|
||||
UMSpectralFlux.add(fluxVal);
|
||||
umSpectralFlux.add(fluxVal);
|
||||
tasksDone++;
|
||||
progress = (int) (100f*tasksDone/totalTasks);
|
||||
sender.send(MiniEvents.ANALYZER_ITERATED);
|
||||
@ -142,12 +144,12 @@ public class AudioAnalyzer {
|
||||
public void run() {
|
||||
|
||||
//threshold calculation
|
||||
for (int i = 0; i < UMSpectralFlux.size && work; i++) {
|
||||
for (int i = 0; i < umSpectralFlux.size && work; i++) {
|
||||
int UMStart = Math.max(0, i - UMThresholdCalcRange/2);
|
||||
int UMEnd = Math.min(UMSpectralFlux.size - 1, i + UMThresholdCalcRange/2);
|
||||
int UMEnd = Math.min(umSpectralFlux.size - 1, i + UMThresholdCalcRange/2);
|
||||
|
||||
int bassStart = Math.max(0, i - bassThresholdCalcRange/2);
|
||||
int bassEnd = Math.min(UMSpectralFlux.size - 1, i + bassThresholdCalcRange/2);
|
||||
int bassEnd = Math.min(umSpectralFlux.size - 1, i + bassThresholdCalcRange/2);
|
||||
|
||||
float average = 0;
|
||||
for (int j = bassStart; j <= bassEnd; j++) {
|
||||
@ -158,10 +160,10 @@ public class AudioAnalyzer {
|
||||
|
||||
average = 0;
|
||||
for (int j = UMStart; j <= UMEnd; j++) {
|
||||
average+= UMSpectralFlux.get(j);
|
||||
average+= umSpectralFlux.get(j);
|
||||
}
|
||||
average /= (UMEnd - UMStart);
|
||||
UMThreshold.add(average*UMThresholdMultiplier);
|
||||
umThreshold.add(average*umThresholdMultiplier);
|
||||
}
|
||||
|
||||
Gdx.app.debug("Audio Analyzer", "Threshold calculated.");
|
||||
@ -169,7 +171,7 @@ public class AudioAnalyzer {
|
||||
|
||||
//pruning data
|
||||
float prunnedCurrentVal;
|
||||
for (int i = 0; i < UMSpectralFlux.size && work; i++) {
|
||||
for (int i = 0; i < umSpectralFlux.size && work; i++) {
|
||||
prunnedCurrentVal = bassSpectralFlux.get(i) - bassThreshold.get(i);
|
||||
|
||||
if (prunnedCurrentVal >= 0) {
|
||||
@ -178,12 +180,12 @@ public class AudioAnalyzer {
|
||||
bassPrunned.add(0);
|
||||
}
|
||||
|
||||
prunnedCurrentVal = UMSpectralFlux.get(i) - UMThreshold.get(i);
|
||||
prunnedCurrentVal = umSpectralFlux.get(i) - umThreshold.get(i);
|
||||
|
||||
if (prunnedCurrentVal >= 0 ) {
|
||||
UMPrunned.add(prunnedCurrentVal);
|
||||
umPrunned.add(prunnedCurrentVal);
|
||||
} else {
|
||||
UMPrunned.add(0);
|
||||
umPrunned.add(0);
|
||||
}
|
||||
|
||||
|
||||
@ -194,41 +196,56 @@ public class AudioAnalyzer {
|
||||
//peak detection
|
||||
|
||||
int lastID = 0;
|
||||
for (int i = 0; i < UMPrunned.size-1 && work; i++) {
|
||||
float bassBeats = 0;
|
||||
float umBeats = 0;
|
||||
for (int i = 0; i < umPrunned.size-1 && work; i++) {
|
||||
bassPeaks.add((bassPrunned.get(i) > bassPrunned.get(i+1) ? bassPrunned.get(i) : 0));
|
||||
if (bassPeaks.get(i) > bassMaxValue) {
|
||||
bassMaxValue = bassPeaks.get(i);
|
||||
}
|
||||
|
||||
UMPeaks.add((UMPrunned.get(i) > UMPrunned.get(i+1) ? UMPrunned.get(i) : 0));
|
||||
if (UMPeaks.get(i) > UMMaxValue) {
|
||||
UMMaxValue = UMPeaks.get(i);
|
||||
umPeaks.add((umPrunned.get(i) > umPrunned.get(i+1) ? umPrunned.get(i) : 0));
|
||||
if (umPeaks.get(i) > UMMaxValue) {
|
||||
UMMaxValue = umPeaks.get(i);
|
||||
}
|
||||
|
||||
//overlapping beats
|
||||
if (bassPeaks.get(i) != 0 && UMPeaks.get(i) != 0) {
|
||||
overlappedPeaks.add(bassPeaks.get(i)+UMPeaks.get(i)/2);
|
||||
if (bassPeaks.get(i) != 0 && umPeaks.get(i) != 0) {
|
||||
overlappedPeaks.add(bassPeaks.get(i)+umPeaks.get(i)/2);
|
||||
} else {
|
||||
overlappedPeaks.add(0);
|
||||
}
|
||||
|
||||
avgBPS = -1f;
|
||||
float beats = 0;
|
||||
if (avgBPS == -1 && bassPeaks.get(i) != 0) {
|
||||
//this should actually equal to 1;
|
||||
|
||||
if (avgBPS != -1) {
|
||||
if (bassPeaks.get(i) == 0) {
|
||||
avgBPS ++;
|
||||
} else {
|
||||
bassBeats ++;
|
||||
lastID = i;
|
||||
}
|
||||
} else if (bassPeaks.get(i) != 0) {
|
||||
avgBPS = 0;
|
||||
} else if (avgBPS == 0 && bassPeaks.get(i) == 0) {
|
||||
avgBPS ++;
|
||||
} else {
|
||||
beats ++;
|
||||
lastID = i;
|
||||
}
|
||||
//then we minus one from the beats so it actually works out
|
||||
avgBPS -= UMPrunned.size-lastID;
|
||||
avgBPS *= secondsPerWindow;
|
||||
avgBPS = beats/avgBPS;
|
||||
|
||||
if (bassPeaks.get(i) != 0) {
|
||||
bassAvg += bassPeaks.get(i);
|
||||
}
|
||||
if (umPeaks.get(i) != 0) {
|
||||
umAvg += umPeaks.get(i);
|
||||
umBeats++;
|
||||
}
|
||||
}
|
||||
|
||||
//then we minus one from the beats so it actually works out
|
||||
avgBPS -= umPrunned.size-lastID;
|
||||
avgBPS *= secondsPerWindow;
|
||||
avgBPS /= bassBeats;
|
||||
|
||||
bassAvg /= bassBeats;
|
||||
umBeats /= umBeats;
|
||||
|
||||
|
||||
if (work) {
|
||||
Gdx.app.debug("Audio Analyzer", "overlapped beats checked.");
|
||||
@ -248,10 +265,10 @@ public class AudioAnalyzer {
|
||||
bassPrunned.shrink();
|
||||
bassPeaks.shrink();
|
||||
|
||||
UMSpectralFlux.shrink();
|
||||
UMThreshold.shrink();
|
||||
UMPrunned.shrink();
|
||||
UMPeaks.shrink();
|
||||
umSpectralFlux.shrink();
|
||||
umThreshold.shrink();
|
||||
umPrunned.shrink();
|
||||
umPeaks.shrink();
|
||||
|
||||
overlappedPeaks.shrink();
|
||||
}
|
||||
@ -267,8 +284,8 @@ public class AudioAnalyzer {
|
||||
}
|
||||
|
||||
public void runThresholdCleaning(float rangeModifier) {
|
||||
this.bassThresholdMultiplier += rangeModifier;
|
||||
this.UMThresholdMultiplier += rangeModifier;
|
||||
this.bassThresholdMultiplier /= rangeModifier;
|
||||
this.umThresholdMultiplier /= rangeModifier;
|
||||
work = true;
|
||||
Thread thresholdClean = new Thread(thresholdCalculator);
|
||||
thresholdClean.start();
|
||||
@ -283,7 +300,7 @@ public class AudioAnalyzer {
|
||||
return bassPeaks;
|
||||
}
|
||||
public FloatArray getUMPeaks() {
|
||||
return UMPeaks;
|
||||
return umPeaks;
|
||||
}
|
||||
|
||||
private int thresholdRangeCalc(float durationOfRange) {
|
||||
@ -300,7 +317,7 @@ public class AudioAnalyzer {
|
||||
}
|
||||
|
||||
public int getReadIndex() {
|
||||
if (audioData.getReadIndex() < UMPeaks.size) {
|
||||
if (audioData.getReadIndex() < umPeaks.size) {
|
||||
return audioData.getReadIndex();
|
||||
} else {
|
||||
return 0;
|
||||
|
@ -59,9 +59,13 @@ public class RhythmMapAlgorithm implements Runnable {
|
||||
((Polyjet.GAME_AREA_HEIGHT-bassPeaks.get(index)*Polyjet.GAME_AREA_HEIGHT)/avgBPS)*speedMod);
|
||||
} else {
|
||||
if (UMPeaks.get(index) != 0) {
|
||||
//TODO basic pellet scatter spawn
|
||||
float xSpawnLocation = (rand.nextFloat()*(Polyjet.GAME_AREA_WIDTH-2))+1;
|
||||
map.addToMap(Entities.PELLET,
|
||||
xSpawnLocation,
|
||||
Polyjet.GAME_AREA_HEIGHT-0.25f,
|
||||
180+180*rand.nextFloat(),
|
||||
speedMod*(Polyjet.GAME_AREA_HEIGHT/3)/avgBPS);
|
||||
}
|
||||
//TODO rest of the basic generation
|
||||
}
|
||||
} else {
|
||||
map.addRestToMap();
|
||||
|
Loading…
Reference in New Issue
Block a user