finished basic seed generator

This commit is contained in:
2017-05-28 00:34:24 -05:00
parent dfd5aaaf8e
commit b4a6bbbea3
9 changed files with 59 additions and 94 deletions

View File

@@ -45,6 +45,8 @@ public class AudioAnalyzer {
public MiniSender sender;
int PUID;
boolean work;
private volatile int progress;
public AudioAnalyzer() {
@@ -78,16 +80,31 @@ public class AudioAnalyzer {
Gdx.app.debug("Threshold Calc Range UM", String.valueOf(UMThresholdCalcRange));
Gdx.app.debug("Threshold Calc Range Bass", String.valueOf(bassThresholdCalcRange));
fft = new FloatFFT_1D(audiofile.getReadWindowSize());
int seedDigit = 0;
while (audiofile.readSamples(audioPCM) > 0 && work) {
tasksDone++;
fft.realForward(audioPCM);
System.arraycopy(spectrum, 0, lastSpectrum, 0, spectrum.length);
System.arraycopy(audioPCM, 0, spectrum, 0, spectrum.length);
//Building a PUID (Pseudo unique ID)
if (tasksDone == (seedDigit*totalTasks/9)) {
float avg = 0;
for (int frame = 0; frame < spectrum.length; frame++) {
avg += spectrum[frame];
}
avg /= spectrum.length;
if (avg < 0) {
avg *= -1f;
}
PUID +=(int) Math.pow(10, 9-seedDigit) * ((int)(avg*1000f)-(int)(avg*100f)*10);
seedDigit ++;
}
float fluxVal = 0;
//bass detection
fluxVal = 0;
@@ -104,16 +121,18 @@ public class AudioAnalyzer {
? (int) (spectrum[i] - lastSpectrum[i]) : 0;
}
UMSpectralFlux.add(fluxVal);
tasksDone++;
progress = (int) (100f*tasksDone/totalTasks);
}
Gdx.app.debug("Audio Analyzer", "Done getting spectral flux.");
shrinkData();
containsData = true;
sender.send(MiniEvents.SPECTRAL_FLUX_DONE);
if (work) {
Gdx.app.debug("Audio Analyzer", "Done getting spectral flux.");
shrinkData();
containsData = true;
sender.send(MiniEvents.SPECTRAL_FLUX_DONE);
}
}
};
@@ -121,6 +140,7 @@ public class AudioAnalyzer {
@Override
public void run() {
Gdx.app.debug("Audio Analyzer", "USING SEED: " + PUID);
//threshold calculation
for (int i = 0; i < UMSpectralFlux.size && work; i++) {
@@ -193,32 +213,18 @@ public class AudioAnalyzer {
}
}
Gdx.app.debug("Audio Analyzer", "overlapped beats checked.");
finalized = true;
sender.send(MiniEvents.MUSIC_DATA_CLEANED);
if (work) {
Gdx.app.debug("Audio Analyzer", "overlapped beats checked.");
finalized = true;
sender.send(MiniEvents.MUSIC_DATA_CLEANED);
}
}
};
}
public void resetVars() {
bassSpectralFlux.clear();
bassThreshold.clear();
bassPrunned.clear();
bassPeaks.clear();
UMSpectralFlux.clear();
UMThreshold.clear();
UMPrunned.clear();
UMPeaks.clear();
overlappedBeats.clear();
containsData = false;
}
public void shrinkData() {
bassSpectralFlux.shrink();
bassThreshold.shrink();
@@ -269,7 +275,6 @@ public class AudioAnalyzer {
}
public float getBassMaxValue() {
Gdx.app.debug("Analyzer", "Max Base Value: " + bassMaxValue);
return bassMaxValue;
}

View File

@@ -1,38 +0,0 @@
package zero1hd.polyjet.audio;
import com.badlogic.gdx.Gdx;
public class RhythmMap {
private boolean done;
public Thread generator;
public GenerationAlgorithm generationAlgorithm;
int window = 0;
public AudioAnalyzer analyzer;
public RhythmMap(AudioAnalyzer analyzer) {
this.analyzer = analyzer;
generationAlgorithm = new GenerationAlgorithm();
}
public void generateMapData(int difficulty) {
generationAlgorithm.setDifficulty(difficulty);
generator = new Thread(generationAlgorithm);
generator.start();
}
public boolean isDone() {
return done;
}
private class GenerationAlgorithm implements Runnable {
private int difficulty;
@Override
public void run() {
Gdx.app.debug("Difficulty", String.valueOf(difficulty));
}
public void setDifficulty(int difficulty) {
this.difficulty = difficulty;
}
}
}

View File

@@ -0,0 +1,15 @@
package zero1hd.polyjet.audio;
public class RhythmMapAlgorithm implements Runnable {
AudioAnalyzer analyzer;
public RhythmMapAlgorithm(AudioAnalyzer analyzer) {
this.analyzer = analyzer;
}
@Override
public void run() {
// TODO Auto-generated method stub
}
}