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 bassPrunned = new FloatArray();
|
||||||
private FloatArray bassPeaks = new FloatArray();
|
private FloatArray bassPeaks = new FloatArray();
|
||||||
private float bassMaxValue;
|
private float bassMaxValue;
|
||||||
|
private float bassAvg;
|
||||||
|
|
||||||
int UMBinBegin;
|
int UMBinBegin;
|
||||||
int UMBinEnd;
|
int UMBinEnd;
|
||||||
private FloatArray UMSpectralFlux = new FloatArray();
|
private FloatArray umSpectralFlux = new FloatArray();
|
||||||
private FloatArray UMThreshold = new FloatArray();
|
private FloatArray umThreshold = new FloatArray();
|
||||||
private FloatArray UMPrunned = new FloatArray();
|
private FloatArray umPrunned = new FloatArray();
|
||||||
private FloatArray UMPeaks = new FloatArray();
|
private FloatArray umPeaks = new FloatArray();
|
||||||
private float UMMaxValue;
|
private float UMMaxValue;
|
||||||
|
private float umAvg;
|
||||||
|
|
||||||
private FloatArray overlappedPeaks = new FloatArray();
|
private FloatArray overlappedPeaks = new FloatArray();
|
||||||
|
|
||||||
float bassThresholdMultiplier;
|
float bassThresholdMultiplier;
|
||||||
float UMThresholdMultiplier;
|
float umThresholdMultiplier;
|
||||||
int UMThresholdCalcRange;
|
int UMThresholdCalcRange;
|
||||||
int bassThresholdCalcRange;
|
int bassThresholdCalcRange;
|
||||||
|
|
||||||
@ -64,7 +66,7 @@ public class AudioAnalyzer {
|
|||||||
int totalTasks = audioData.getSampleCount()/audioData.getReadWindowSize();
|
int totalTasks = audioData.getSampleCount()/audioData.getReadWindowSize();
|
||||||
|
|
||||||
bassThresholdMultiplier = 1.5f;
|
bassThresholdMultiplier = 1.5f;
|
||||||
UMThresholdMultiplier = 2f;
|
umThresholdMultiplier = 2f;
|
||||||
|
|
||||||
bassBinBegin = 1;
|
bassBinBegin = 1;
|
||||||
bassBinEnd = 15;
|
bassBinEnd = 15;
|
||||||
@ -120,7 +122,7 @@ public class AudioAnalyzer {
|
|||||||
fluxVal += ((spectrum[i] - lastSpectrum[i])) > 0
|
fluxVal += ((spectrum[i] - lastSpectrum[i])) > 0
|
||||||
? (spectrum[i] - lastSpectrum[i]) : 0;
|
? (spectrum[i] - lastSpectrum[i]) : 0;
|
||||||
}
|
}
|
||||||
UMSpectralFlux.add(fluxVal);
|
umSpectralFlux.add(fluxVal);
|
||||||
tasksDone++;
|
tasksDone++;
|
||||||
progress = (int) (100f*tasksDone/totalTasks);
|
progress = (int) (100f*tasksDone/totalTasks);
|
||||||
sender.send(MiniEvents.ANALYZER_ITERATED);
|
sender.send(MiniEvents.ANALYZER_ITERATED);
|
||||||
@ -142,12 +144,12 @@ public class AudioAnalyzer {
|
|||||||
public void run() {
|
public void run() {
|
||||||
|
|
||||||
//threshold calculation
|
//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 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 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;
|
float average = 0;
|
||||||
for (int j = bassStart; j <= bassEnd; j++) {
|
for (int j = bassStart; j <= bassEnd; j++) {
|
||||||
@ -158,10 +160,10 @@ public class AudioAnalyzer {
|
|||||||
|
|
||||||
average = 0;
|
average = 0;
|
||||||
for (int j = UMStart; j <= UMEnd; j++) {
|
for (int j = UMStart; j <= UMEnd; j++) {
|
||||||
average+= UMSpectralFlux.get(j);
|
average+= umSpectralFlux.get(j);
|
||||||
}
|
}
|
||||||
average /= (UMEnd - UMStart);
|
average /= (UMEnd - UMStart);
|
||||||
UMThreshold.add(average*UMThresholdMultiplier);
|
umThreshold.add(average*umThresholdMultiplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
Gdx.app.debug("Audio Analyzer", "Threshold calculated.");
|
Gdx.app.debug("Audio Analyzer", "Threshold calculated.");
|
||||||
@ -169,7 +171,7 @@ public class AudioAnalyzer {
|
|||||||
|
|
||||||
//pruning data
|
//pruning data
|
||||||
float prunnedCurrentVal;
|
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);
|
prunnedCurrentVal = bassSpectralFlux.get(i) - bassThreshold.get(i);
|
||||||
|
|
||||||
if (prunnedCurrentVal >= 0) {
|
if (prunnedCurrentVal >= 0) {
|
||||||
@ -178,12 +180,12 @@ public class AudioAnalyzer {
|
|||||||
bassPrunned.add(0);
|
bassPrunned.add(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
prunnedCurrentVal = UMSpectralFlux.get(i) - UMThreshold.get(i);
|
prunnedCurrentVal = umSpectralFlux.get(i) - umThreshold.get(i);
|
||||||
|
|
||||||
if (prunnedCurrentVal >= 0 ) {
|
if (prunnedCurrentVal >= 0 ) {
|
||||||
UMPrunned.add(prunnedCurrentVal);
|
umPrunned.add(prunnedCurrentVal);
|
||||||
} else {
|
} else {
|
||||||
UMPrunned.add(0);
|
umPrunned.add(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -194,41 +196,56 @@ public class AudioAnalyzer {
|
|||||||
//peak detection
|
//peak detection
|
||||||
|
|
||||||
int lastID = 0;
|
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));
|
bassPeaks.add((bassPrunned.get(i) > bassPrunned.get(i+1) ? bassPrunned.get(i) : 0));
|
||||||
if (bassPeaks.get(i) > bassMaxValue) {
|
if (bassPeaks.get(i) > bassMaxValue) {
|
||||||
bassMaxValue = bassPeaks.get(i);
|
bassMaxValue = bassPeaks.get(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
UMPeaks.add((UMPrunned.get(i) > UMPrunned.get(i+1) ? UMPrunned.get(i) : 0));
|
umPeaks.add((umPrunned.get(i) > umPrunned.get(i+1) ? umPrunned.get(i) : 0));
|
||||||
if (UMPeaks.get(i) > UMMaxValue) {
|
if (umPeaks.get(i) > UMMaxValue) {
|
||||||
UMMaxValue = UMPeaks.get(i);
|
UMMaxValue = umPeaks.get(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
//overlapping beats
|
//overlapping beats
|
||||||
if (bassPeaks.get(i) != 0 && UMPeaks.get(i) != 0) {
|
if (bassPeaks.get(i) != 0 && umPeaks.get(i) != 0) {
|
||||||
overlappedPeaks.add(bassPeaks.get(i)+UMPeaks.get(i)/2);
|
overlappedPeaks.add(bassPeaks.get(i)+umPeaks.get(i)/2);
|
||||||
} else {
|
} else {
|
||||||
overlappedPeaks.add(0);
|
overlappedPeaks.add(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
avgBPS = -1f;
|
avgBPS = -1f;
|
||||||
float beats = 0;
|
|
||||||
if (avgBPS == -1 && bassPeaks.get(i) != 0) {
|
if (avgBPS != -1) {
|
||||||
//this should actually equal to 1;
|
if (bassPeaks.get(i) == 0) {
|
||||||
|
avgBPS ++;
|
||||||
|
} else {
|
||||||
|
bassBeats ++;
|
||||||
|
lastID = i;
|
||||||
|
}
|
||||||
|
} else if (bassPeaks.get(i) != 0) {
|
||||||
avgBPS = 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;
|
if (bassPeaks.get(i) != 0) {
|
||||||
avgBPS *= secondsPerWindow;
|
bassAvg += bassPeaks.get(i);
|
||||||
avgBPS = beats/avgBPS;
|
}
|
||||||
|
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) {
|
if (work) {
|
||||||
Gdx.app.debug("Audio Analyzer", "overlapped beats checked.");
|
Gdx.app.debug("Audio Analyzer", "overlapped beats checked.");
|
||||||
@ -248,10 +265,10 @@ public class AudioAnalyzer {
|
|||||||
bassPrunned.shrink();
|
bassPrunned.shrink();
|
||||||
bassPeaks.shrink();
|
bassPeaks.shrink();
|
||||||
|
|
||||||
UMSpectralFlux.shrink();
|
umSpectralFlux.shrink();
|
||||||
UMThreshold.shrink();
|
umThreshold.shrink();
|
||||||
UMPrunned.shrink();
|
umPrunned.shrink();
|
||||||
UMPeaks.shrink();
|
umPeaks.shrink();
|
||||||
|
|
||||||
overlappedPeaks.shrink();
|
overlappedPeaks.shrink();
|
||||||
}
|
}
|
||||||
@ -267,8 +284,8 @@ public class AudioAnalyzer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void runThresholdCleaning(float rangeModifier) {
|
public void runThresholdCleaning(float rangeModifier) {
|
||||||
this.bassThresholdMultiplier += rangeModifier;
|
this.bassThresholdMultiplier /= rangeModifier;
|
||||||
this.UMThresholdMultiplier += rangeModifier;
|
this.umThresholdMultiplier /= rangeModifier;
|
||||||
work = true;
|
work = true;
|
||||||
Thread thresholdClean = new Thread(thresholdCalculator);
|
Thread thresholdClean = new Thread(thresholdCalculator);
|
||||||
thresholdClean.start();
|
thresholdClean.start();
|
||||||
@ -283,7 +300,7 @@ public class AudioAnalyzer {
|
|||||||
return bassPeaks;
|
return bassPeaks;
|
||||||
}
|
}
|
||||||
public FloatArray getUMPeaks() {
|
public FloatArray getUMPeaks() {
|
||||||
return UMPeaks;
|
return umPeaks;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int thresholdRangeCalc(float durationOfRange) {
|
private int thresholdRangeCalc(float durationOfRange) {
|
||||||
@ -300,7 +317,7 @@ public class AudioAnalyzer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getReadIndex() {
|
public int getReadIndex() {
|
||||||
if (audioData.getReadIndex() < UMPeaks.size) {
|
if (audioData.getReadIndex() < umPeaks.size) {
|
||||||
return audioData.getReadIndex();
|
return audioData.getReadIndex();
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -59,9 +59,13 @@ public class RhythmMapAlgorithm implements Runnable {
|
|||||||
((Polyjet.GAME_AREA_HEIGHT-bassPeaks.get(index)*Polyjet.GAME_AREA_HEIGHT)/avgBPS)*speedMod);
|
((Polyjet.GAME_AREA_HEIGHT-bassPeaks.get(index)*Polyjet.GAME_AREA_HEIGHT)/avgBPS)*speedMod);
|
||||||
} else {
|
} else {
|
||||||
if (UMPeaks.get(index) != 0) {
|
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 {
|
} else {
|
||||||
map.addRestToMap();
|
map.addRestToMap();
|
||||||
|
Loading…
Reference in New Issue
Block a user