finished basic seed generator
This commit is contained in:
parent
dfd5aaaf8e
commit
b4a6bbbea3
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
15
core/src/zero1hd/polyjet/audio/RhythmMapAlgorithm.java
Executable file
15
core/src/zero1hd/polyjet/audio/RhythmMapAlgorithm.java
Executable 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
|
||||
|
||||
}
|
||||
}
|
@ -19,7 +19,6 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||
|
||||
import zero1hd.polyjet.Polyjet;
|
||||
import zero1hd.polyjet.audio.AudioData;
|
||||
import zero1hd.polyjet.audio.RhythmMap;
|
||||
import zero1hd.polyjet.ui.stages.GamePlayArea;
|
||||
import zero1hd.polyjet.ui.windows.FPSWindow;
|
||||
|
||||
@ -110,11 +109,6 @@ public class GameScreen extends ScreenAdapter implements InputProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
public void setMap (RhythmMap map) {
|
||||
this.music = map.analyzer.audiofile;
|
||||
gameArea.setMap(map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void show() {
|
||||
Gdx.input.setInputProcessor(inputs);
|
||||
|
@ -33,7 +33,6 @@ public class AnalyzePage extends Page {
|
||||
public AnalyzePage(Skin skin, AssetManager assets) {
|
||||
super("Results", skin);
|
||||
this.skin = skin;
|
||||
audioAnalyzer = new AudioAnalyzer();
|
||||
songInfo = new Table(skin);
|
||||
|
||||
loadingCircle = new Image(assets.get("cybercircle1.png", Texture.class));
|
||||
@ -62,6 +61,8 @@ public class AnalyzePage extends Page {
|
||||
public void setSong(AudioData music, AudioInfo audioInfo) {
|
||||
songInfo.clear();
|
||||
|
||||
audioAnalyzer = new AudioAnalyzer();
|
||||
|
||||
this.music = music;
|
||||
audioAnalyzer.startAnalyticalThread(music);
|
||||
songInfo.add(new Label(audioInfo.getSongName(), skin, "large-font", skin.getColor("default")));
|
||||
|
@ -40,12 +40,8 @@ public class CreativeStage extends Stage implements MiniListener {
|
||||
|
||||
public CreativeStage(final Polyjet core, final MainMenu mainMenu) {
|
||||
this.core = core;
|
||||
analyzer = new AudioAnalyzer();
|
||||
analyzer.sender.addListener(this);
|
||||
|
||||
musicSelector = new MusicSelector("Select Audio File", core.getDefaultSkin(), core.getPrefs().getString("music dir"), "default");
|
||||
musicSelector.miniSender.addListener(this);
|
||||
musicSelector.postInit();
|
||||
musicSelector.refresh();
|
||||
|
||||
fpsViewer = new FPSWindow("FPS", core.getDefaultSkin());
|
||||
@ -192,8 +188,6 @@ public class CreativeStage extends Stage implements MiniListener {
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
analyzer.resetVars();
|
||||
analyzer.shrinkData();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@ -208,6 +202,9 @@ public class CreativeStage extends Stage implements MiniListener {
|
||||
volumeWindow.setMusic(null);
|
||||
graphViewer.setData(null, null, null);
|
||||
musicPlayBackControls.setAudiofile(null);
|
||||
analyzer = new AudioAnalyzer();
|
||||
analyzer.sender.addListener(this);
|
||||
|
||||
analyzer.startAnalyticalThread(musicSelector.getSelectedMusic());
|
||||
break;
|
||||
case SPECTRAL_FLUX_DONE:
|
||||
|
@ -11,7 +11,6 @@ import com.badlogic.gdx.utils.Pools;
|
||||
import com.badlogic.gdx.utils.viewport.FitViewport;
|
||||
|
||||
import zero1hd.polyjet.Polyjet;
|
||||
import zero1hd.polyjet.audio.RhythmMap;
|
||||
import zero1hd.polyjet.controls.KeyMap;
|
||||
import zero1hd.polyjet.entity.BarBeat;
|
||||
import zero1hd.polyjet.entity.PolyJetEntity;
|
||||
@ -20,8 +19,6 @@ import zero1hd.polyjet.entity.Projectile;
|
||||
|
||||
public class GamePlayArea extends Stage {
|
||||
public PolyJetEntity polyJet;
|
||||
RhythmMap map;
|
||||
|
||||
float timeCounter;
|
||||
|
||||
//Required to know when to spawn entities on screen.
|
||||
@ -199,11 +196,6 @@ public class GamePlayArea extends Stage {
|
||||
public float getMaxHealth() {
|
||||
return maxHealth;
|
||||
}
|
||||
|
||||
public void setMap(RhythmMap map) {
|
||||
this.map = map;
|
||||
}
|
||||
|
||||
public float getyTeleport() {
|
||||
return yTeleport;
|
||||
}
|
||||
|
@ -56,10 +56,9 @@ public class MusicSelector extends Window {
|
||||
|
||||
listScroller = new ScrollPane(musicList, skin);
|
||||
listScroller.setScrollingDisabled(true, false);
|
||||
}
|
||||
|
||||
public void postInit() {
|
||||
|
||||
add(listScroller).colspan(2).expand().fill().prefWidth(getWidth()-5);
|
||||
|
||||
}
|
||||
|
||||
public void refresh() {
|
||||
|
@ -1,5 +1,5 @@
|
||||
package zero1hd.polyjet.util;
|
||||
|
||||
public enum MiniEvents {
|
||||
SPECTRAL_FLUX_DONE, MUSIC_DATA_CLEANED, MUSIC_SELECTED, BACK;
|
||||
SPECTRAL_FLUX_DONE, MUSIC_DATA_CLEANED, MUSIC_SELECTED, BACK, MAP_GENERATED;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user