made progress on analysis screen and fixing average beats per second

This commit is contained in:
2017-07-10 00:29:50 -05:00
parent d815a3c053
commit cf0114bac3
8 changed files with 82 additions and 29 deletions

View File

@@ -43,13 +43,14 @@ public class AudioAnalyzer {
int UMThresholdCalcRange;
int bassThresholdCalcRange;
public MiniSender sender;
public volatile MiniSender sender;
private float avgBPS;
int PUID;
boolean work;
private volatile int progress;
private float secondsPerFrame;
public AudioAnalyzer() {
sender = new MiniSender();
@@ -122,6 +123,7 @@ public class AudioAnalyzer {
UMSpectralFlux.add(fluxVal);
tasksDone++;
progress = (int) (100f*tasksDone/totalTasks);
sender.send(MiniEvents.ANALYZER_ITERATED);
}
if (work) {
@@ -136,7 +138,6 @@ public class AudioAnalyzer {
};
thresholdCalculator = new Runnable() {
@Override
public void run() {
@@ -184,13 +185,15 @@ public class AudioAnalyzer {
} else {
UMPrunned.add(0);
}
}
Gdx.app.debug("Audio Analyzer", "Data prunned.");
float secondsUnit = audioData.getFormat().getSampleRate()/audioData.getReadWindowSize();
secondsPerFrame = audioData.getReadWindowSize()/audioData.getFormat().getSampleRate();
//peak detection
avgBPS = -1f;
int beats = 0;
int lastID = 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) {
@@ -209,15 +212,21 @@ public class AudioAnalyzer {
overlappedPeaks.add(0);
}
avgBPS = -1f;
int beats = 0;
if (avgBPS == -1 && bassPeaks.get(i) != 0) {
//this should actually equal to 1;
avgBPS = 0;
} else if (bassPeaks.get(i) == 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 /= beats;
avgBPS /= secondsUnit;
avgBPS *= secondsPerFrame;
}
@@ -329,4 +338,8 @@ public class AudioAnalyzer {
public float getAvgBPS() {
return avgBPS;
}
public float getsecondsPerFrame() {
return secondsPerFrame;
}
}

View File

@@ -93,7 +93,7 @@ public class AudioInfo implements Disposable {
}
public String getSongName() {
return songName;
return songName.replace('_', ' ');
}
public Texture getAlbumCover() {

View File

@@ -16,7 +16,7 @@ public class RhythmMapAlgorithm implements Runnable {
private MersenneTwister rand;
private GamePlayMap map;
private float avgBPS;
private float second;
public RhythmMapAlgorithm(AudioAnalyzer analyzer) {
bassPeaks = analyzer.getBassPeaks();
UMPeaks = analyzer.getUMPeaks();
@@ -24,6 +24,7 @@ public class RhythmMapAlgorithm implements Runnable {
map = new GamePlayMap(analyzer.getAudioData());
rand = new MersenneTwister(analyzer.getPUID());
avgBPS = analyzer.getAvgBPS();
second = analyzer.getsecondsPerFrame();
}
@Override
@@ -31,13 +32,19 @@ public class RhythmMapAlgorithm implements Runnable {
map.beginBuild();
for (int index = 0; index < bassPeaks.size; index++) {
if (bassPeaks.get(index) != 0 || UMPeaks.get(index) != 0) {
if (overlappedPeaks.get(index) != 0) {
if (overlappedPeaks.get(index+3) != 0) {
//TODO basic void circle spawning
float endRadius = rand.nextFloat()*Polyjet.GAME_AREA_WIDTH;
map.addToMap(Entities.VOID_CIRCLE,
overlappedPeaks.get(index)*Polyjet.GAME_AREA_WIDTH,
endRadius,
rand.nextFloat()*Polyjet.GAME_AREA_WIDTH,
rand.nextFloat()*Polyjet.GAME_AREA_HEIGHT);
} else if (bassPeaks.get(index) != 0) {
rand.nextFloat()*Polyjet.GAME_AREA_HEIGHT,
avgBPS,
3f*second
);
}
if (bassPeaks.get(index) != 0) {
map.addToMap(Entities.BAR,
MathUtils.round(rand.nextFloat()*Polyjet.GAME_AREA_WIDTH),
bassPeaks.get(index)*Polyjet.GAME_AREA_HEIGHT/avgBPS);