furthered usage of new mini context object
This commit is contained in:
parent
d00f434275
commit
ba8a2182fb
@ -113,7 +113,7 @@ public class RhythmBullet extends Game {
|
|||||||
public void dispose() {
|
public void dispose() {
|
||||||
Gdx.app.debug("Core", "disposing...");
|
Gdx.app.debug("Core", "disposing...");
|
||||||
if (initComplete) {
|
if (initComplete) {
|
||||||
skinAtlas.dispose();
|
// skinAtlas.dispose();
|
||||||
getDefaultSkin().dispose();
|
getDefaultSkin().dispose();
|
||||||
default_fontGenerator.dispose();
|
default_fontGenerator.dispose();
|
||||||
darktech_ldr_fontGenerator.dispose();
|
darktech_ldr_fontGenerator.dispose();
|
||||||
|
@ -12,7 +12,6 @@ import zero1hd.rhythmbullet.util.MiniSender;
|
|||||||
|
|
||||||
public class AudioAnalyzer {
|
public class AudioAnalyzer {
|
||||||
private boolean containsData;
|
private boolean containsData;
|
||||||
private boolean finalized;
|
|
||||||
FloatFFT_1D fft;
|
FloatFFT_1D fft;
|
||||||
private CoreMusicInfo musicInfo;
|
private CoreMusicInfo musicInfo;
|
||||||
|
|
||||||
@ -20,8 +19,9 @@ public class AudioAnalyzer {
|
|||||||
float[] spectrum;
|
float[] spectrum;
|
||||||
float[] lastSpectrum;
|
float[] lastSpectrum;
|
||||||
|
|
||||||
Runnable analysisAlgorithm;
|
private ExecutorService exec = Executors.newSingleThreadExecutor();
|
||||||
Runnable thresholdCalculator;
|
private Runnable analysisAlgorithm;
|
||||||
|
private Runnable thresholdCalculator;
|
||||||
|
|
||||||
int bassBinBegin;
|
int bassBinBegin;
|
||||||
int bassBinEnd;
|
int bassBinEnd;
|
||||||
@ -57,7 +57,7 @@ public class AudioAnalyzer {
|
|||||||
private float secondsPerWindow;
|
private float secondsPerWindow;
|
||||||
|
|
||||||
private AudioDataPackage pack;
|
private AudioDataPackage pack;
|
||||||
public AudioAnalyzer() {
|
public AudioAnalyzer(CoreMusicInfo audiofile) {
|
||||||
sender = new MiniSender();
|
sender = new MiniSender();
|
||||||
|
|
||||||
analysisAlgorithm = () -> {
|
analysisAlgorithm = () -> {
|
||||||
@ -297,11 +297,18 @@ public class AudioAnalyzer {
|
|||||||
pack.setMusicInfo(musicInfo);
|
pack.setMusicInfo(musicInfo);
|
||||||
|
|
||||||
if (work) {
|
if (work) {
|
||||||
finalized = true;
|
|
||||||
Gdx.app.debug("Audio Analyzer", "data cleaned and ready for map gen.");
|
Gdx.app.debug("Audio Analyzer", "data cleaned and ready for map gen.");
|
||||||
sender.send(MiniEvents.MUSIC_DATA_CLEANED);
|
sender.send(MiniEvents.MUSIC_DATA_CLEANED);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
audioPCM = new float[audiofile.getReadWindowSize()];
|
||||||
|
spectrum = new float[(audiofile.getReadWindowSize()/2)+1];
|
||||||
|
lastSpectrum = new float[(audiofile.getReadWindowSize()/2)+1];
|
||||||
|
this.musicInfo = audiofile;
|
||||||
|
work = true;
|
||||||
|
|
||||||
|
exec.submit(analysisAlgorithm);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shrinkData() {
|
public void shrinkData() {
|
||||||
@ -310,24 +317,12 @@ public class AudioAnalyzer {
|
|||||||
umSpectralFlux = null;
|
umSpectralFlux = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startAnalyticalThread(CoreMusicInfo audiofile) {
|
|
||||||
audioPCM = new float[audiofile.getReadWindowSize()];
|
|
||||||
spectrum = new float[(audiofile.getReadWindowSize()/2)+1];
|
|
||||||
lastSpectrum = new float[(audiofile.getReadWindowSize()/2)+1];
|
|
||||||
this.musicInfo = audiofile;
|
|
||||||
work = true;
|
|
||||||
|
|
||||||
ExecutorService exec = Executors.newSingleThreadExecutor();
|
|
||||||
exec.submit(analysisAlgorithm);
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
if (containsData) {
|
if (containsData) {
|
||||||
ExecutorService exec = Executors.newSingleThreadExecutor();
|
|
||||||
exec.submit(thresholdCalculator);
|
exec.submit(thresholdCalculator);
|
||||||
} else {
|
} else {
|
||||||
throw new NullPointerException("Either you didn't start the spectral flux gen, or you didn't let it finish.");
|
throw new NullPointerException("Either you didn't start the spectral flux gen, or you didn't let it finish.");
|
||||||
@ -337,7 +332,6 @@ public class AudioAnalyzer {
|
|||||||
public void runThresholdCleaning() {
|
public void runThresholdCleaning() {
|
||||||
work = true;
|
work = true;
|
||||||
if (containsData) {
|
if (containsData) {
|
||||||
ExecutorService exec = Executors.newSingleThreadExecutor();
|
|
||||||
exec.submit(thresholdCalculator);
|
exec.submit(thresholdCalculator);
|
||||||
} else {
|
} else {
|
||||||
throw new NullPointerException("Either you didn't start the spectral flux gen, or you didn't let it finish.");
|
throw new NullPointerException("Either you didn't start the spectral flux gen, or you didn't let it finish.");
|
||||||
@ -348,18 +342,6 @@ public class AudioAnalyzer {
|
|||||||
return (int) (durationOfRange/(musicInfo.getReadWindowSize()/musicInfo.getSampleRate()));
|
return (int) (durationOfRange/(musicInfo.getReadWindowSize()/musicInfo.getSampleRate()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getBassMaxValue() {
|
|
||||||
return bassMaxValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getmMaxValue() {
|
|
||||||
return mMaxValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getUMMaxValue() {
|
|
||||||
return umMaxValue;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean containsData() {
|
public boolean containsData() {
|
||||||
return containsData;
|
return containsData;
|
||||||
}
|
}
|
||||||
@ -368,44 +350,13 @@ public class AudioAnalyzer {
|
|||||||
return progress;
|
return progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFinalized() {
|
|
||||||
return finalized;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
work = false;
|
work = false;
|
||||||
|
exec.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getPUID() {
|
|
||||||
return PUID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CoreMusicInfo getAudioData() {
|
|
||||||
return musicInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getAvgSPB() {
|
|
||||||
return avgSPB;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getsecondsPerWindow() {
|
|
||||||
return secondsPerWindow;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getBassAvg() {
|
|
||||||
return bassAvg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getUmAvg() {
|
|
||||||
return umAvg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getmAvg() {
|
|
||||||
return mAvg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public synchronized AudioDataPackage getAudioDataPackage() {
|
public synchronized AudioDataPackage getAudioDataPackage() {
|
||||||
if (pack != null) {
|
if (pack != null) {
|
||||||
|
exec.shutdown();
|
||||||
return pack;
|
return pack;
|
||||||
} else {
|
} else {
|
||||||
throw new NullPointerException("Pack isn't filled yet... You made a mistake somewhere!");
|
throw new NullPointerException("Pack isn't filled yet... You made a mistake somewhere!");
|
||||||
|
@ -41,8 +41,13 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter {
|
|||||||
@Override
|
@Override
|
||||||
public void preTransition() {
|
public void preTransition() {
|
||||||
stage.clear();
|
stage.clear();
|
||||||
|
mainPage.dispose();
|
||||||
|
optionsPage.dispose();
|
||||||
|
creditsPage.dispose();
|
||||||
|
moreOptionsPage.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void postTransition() {
|
public void postTransition() {
|
||||||
mainPage = new MainPage(core, targetPosition);
|
mainPage = new MainPage(core, targetPosition);
|
||||||
mainPage.setPosition(0, 0);
|
mainPage.setPosition(0, 0);
|
||||||
|
@ -52,7 +52,8 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter, M
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void resize(int width, int height) {
|
public void resize(int width, int height) {
|
||||||
stage.getViewport().update(width, height);
|
stage.getViewport().update(width, height, true);
|
||||||
|
cameraPos.set(stage.getCamera().position);
|
||||||
super.resize(width, height);
|
super.resize(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,6 +79,8 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter, M
|
|||||||
@Override
|
@Override
|
||||||
public void preTransition() {
|
public void preTransition() {
|
||||||
stage.clear();
|
stage.clear();
|
||||||
|
ap.dispose();
|
||||||
|
ms.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -89,14 +92,10 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter, M
|
|||||||
|
|
||||||
ap = new AnalyzePage(core);
|
ap = new AnalyzePage(core);
|
||||||
ap.miniSender.addListener(this);
|
ap.miniSender.addListener(this);
|
||||||
ap.setPosition(Gdx.graphics.getWidth(), ap.getY());
|
ap.setPosition(Gdx.graphics.getWidth(), 0);
|
||||||
stage.addActor(ap);
|
stage.addActor(ap);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPhase(int phase) {
|
|
||||||
cameraPos.x = Gdx.graphics.getWidth()*(phase + 0.5f);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void show() {
|
public void show() {
|
||||||
Gdx.input.setInputProcessor(stage);
|
Gdx.input.setInputProcessor(stage);
|
||||||
|
@ -15,6 +15,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
|||||||
|
|
||||||
import zero1hd.rhythmbullet.RhythmBullet;
|
import zero1hd.rhythmbullet.RhythmBullet;
|
||||||
import zero1hd.rhythmbullet.audio.AudioAnalyzer;
|
import zero1hd.rhythmbullet.audio.AudioAnalyzer;
|
||||||
|
import zero1hd.rhythmbullet.audio.AudioDataPackage;
|
||||||
import zero1hd.rhythmbullet.audio.map.RhythmMapAlgorithm;
|
import zero1hd.rhythmbullet.audio.map.RhythmMapAlgorithm;
|
||||||
import zero1hd.rhythmbullet.screens.MainMenu;
|
import zero1hd.rhythmbullet.screens.MainMenu;
|
||||||
import zero1hd.rhythmbullet.stages.GamePlayArea;
|
import zero1hd.rhythmbullet.stages.GamePlayArea;
|
||||||
@ -246,40 +247,37 @@ public class CreativeHUD extends Stage implements MiniListener {
|
|||||||
musicPlayBackControls.getAudiofile().dispose();
|
musicPlayBackControls.getAudiofile().dispose();
|
||||||
}
|
}
|
||||||
musicPlayBackControls.setAudiofile(null);
|
musicPlayBackControls.setAudiofile(null);
|
||||||
analyzer = new AudioAnalyzer();
|
analyzer = new AudioAnalyzer(musicSelector.getSelectedMusic());
|
||||||
analyzer.sender.addListener(this);
|
analyzer.sender.addListener(this);
|
||||||
|
|
||||||
analyzer.startAnalyticalThread(musicSelector.getSelectedMusic());
|
|
||||||
break;
|
break;
|
||||||
case SPECTRAL_FLUX_DONE:
|
case SPECTRAL_FLUX_DONE:
|
||||||
analyzer.runThresholdCleaning();
|
analyzer.runThresholdCleaning();
|
||||||
break;
|
break;
|
||||||
case MUSIC_DATA_CLEANED:
|
case MUSIC_DATA_CLEANED:
|
||||||
if (analyzer != null && analyzer.isFinalized()) {
|
mapGen = new RhythmMapAlgorithm(gpa.em, gpa.cm, analyzer.getAudioDataPackage(), diffWindow.getSpeedModifier(), diffWindow.getHealthModifier(), diffWindow.getOverallDiffMod());
|
||||||
mapGen = new RhythmMapAlgorithm(gpa.em, gpa.cm, analyzer.getAudioDataPackage(), diffWindow.getSpeedModifier(), diffWindow.getHealthModifier(), diffWindow.getOverallDiffMod());
|
mapGen.getSender().addListener(this);
|
||||||
mapGen.getSender().addListener(this);
|
Thread mapGenThread = new Thread(mapGen);
|
||||||
Thread mapGenThread = new Thread(mapGen);
|
mapGenThread.start();
|
||||||
mapGenThread.start();
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case MAP_GENERATED:
|
case MAP_GENERATED:
|
||||||
Gdx.app.debug("creative", "successfully generated map.");
|
Gdx.app.debug("creative", "successfully generated map.");
|
||||||
musicPlayBackControls.setAudiofile(analyzer.getAudioData());
|
AudioDataPackage adp = analyzer.getAudioDataPackage();
|
||||||
volumeWindow.setMusic(analyzer.getAudioData());
|
musicPlayBackControls.setAudiofile(adp.getMusicInfo());
|
||||||
beatViewer.setMusic(analyzer.getAudioData(), analyzer.getAudioDataPackage());
|
volumeWindow.setMusic(adp.getMusicInfo());
|
||||||
|
beatViewer.setMusic(adp.getMusicInfo(), analyzer.getAudioDataPackage());
|
||||||
ghud.setMusic(null);
|
ghud.setMusic(null);
|
||||||
|
|
||||||
bassUMgraphWindow.setData(analyzer.getAudioDataPackage().getBassPeaks(), analyzer.getAudioDataPackage().getuMPeaks(), analyzer.getAudioData());
|
bassUMgraphWindow.setData(analyzer.getAudioDataPackage().getBassPeaks(), analyzer.getAudioDataPackage().getuMPeaks(), adp.getMusicInfo());
|
||||||
bassUMgraphWindow.getGraph().avgG1 = analyzer.getBassAvg();
|
bassUMgraphWindow.getGraph().avgG1 = adp.getBassAvg();
|
||||||
bassUMgraphWindow.getGraph().normalDataG1 = analyzer.getBassMaxValue();
|
bassUMgraphWindow.getGraph().normalDataG1 = adp.getBassMaxVal();
|
||||||
bassUMgraphWindow.getGraph().avgG2 = analyzer.getUmAvg();
|
bassUMgraphWindow.getGraph().avgG2 = adp.getuMAvg();
|
||||||
bassUMgraphWindow.getGraph().normalDataG2 = analyzer.getUMMaxValue();
|
bassUMgraphWindow.getGraph().normalDataG2 = adp.getuMMaxval();
|
||||||
|
|
||||||
mGraphWindow.setData(analyzer.getAudioDataPackage().getmPeaks(), null, analyzer.getAudioData());
|
mGraphWindow.setData(analyzer.getAudioDataPackage().getmPeaks(), null, adp.getMusicInfo());
|
||||||
mGraphWindow.getGraph().normalDataG1 = analyzer.getmMaxValue();
|
mGraphWindow.getGraph().normalDataG1 = adp.getmMaxVal();
|
||||||
mGraphWindow.getGraph().avgG1 = analyzer.getmAvg();
|
mGraphWindow.getGraph().avgG1 = adp.getmAvg();
|
||||||
gpa.setAudioMap(mapGen.getMap());
|
gpa.setAudioMap(mapGen.getMap());
|
||||||
ghud.setMusic(analyzer.getAudioData().getPlaybackMusic());
|
ghud.setMusic(adp.getMusicInfo().getPlaybackMusic());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -15,6 +15,7 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
|||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||||
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
|
||||||
import com.badlogic.gdx.utils.Align;
|
import com.badlogic.gdx.utils.Align;
|
||||||
|
import com.badlogic.gdx.utils.Disposable;
|
||||||
|
|
||||||
import zero1hd.rhythmbullet.RhythmBullet;
|
import zero1hd.rhythmbullet.RhythmBullet;
|
||||||
import zero1hd.rhythmbullet.audio.AudioAnalyzer;
|
import zero1hd.rhythmbullet.audio.AudioAnalyzer;
|
||||||
@ -27,7 +28,7 @@ import zero1hd.rhythmbullet.ui.builders.ScrollText;
|
|||||||
import zero1hd.rhythmbullet.util.MiniEvents;
|
import zero1hd.rhythmbullet.util.MiniEvents;
|
||||||
import zero1hd.rhythmbullet.util.MiniListener;
|
import zero1hd.rhythmbullet.util.MiniListener;
|
||||||
|
|
||||||
public class AnalyzePage extends Page implements MiniListener {
|
public class AnalyzePage extends Page implements MiniListener, Disposable {
|
||||||
private AnalyzePage ap = this;
|
private AnalyzePage ap = this;
|
||||||
|
|
||||||
AudioAnalyzer audioAnalyzer;
|
AudioAnalyzer audioAnalyzer;
|
||||||
@ -194,12 +195,12 @@ public class AnalyzePage extends Page implements MiniListener {
|
|||||||
|
|
||||||
songInfo.clear();
|
songInfo.clear();
|
||||||
songInfo.defaults().align(Align.left | Align.top);
|
songInfo.defaults().align(Align.left | Align.top);
|
||||||
audioAnalyzer = new AudioAnalyzer();
|
|
||||||
audioAnalyzer.sender.addListener(this);
|
|
||||||
|
|
||||||
this.music = music;
|
this.music = music;
|
||||||
|
|
||||||
audioAnalyzer.startAnalyticalThread(music);
|
audioAnalyzer = new AudioAnalyzer(music);
|
||||||
|
audioAnalyzer.sender.addListener(this);
|
||||||
|
|
||||||
|
|
||||||
songInfo.add(new ScrollText(audioInfo.getSongName(), skin, true)).expandX().fillX().spaceBottom(20f);
|
songInfo.add(new ScrollText(audioInfo.getSongName(), skin, true)).expandX().fillX().spaceBottom(20f);
|
||||||
|
|
||||||
for (int i = 0; i < info.length; i++) {
|
for (int i = 0; i < info.length; i++) {
|
||||||
@ -311,4 +312,12 @@ public class AnalyzePage extends Page implements MiniListener {
|
|||||||
public GamePlayMap getMap() {
|
public GamePlayMap getMap() {
|
||||||
return mapGenAlgorithm.getMap();
|
return mapGenAlgorithm.getMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
if (audioAnalyzer != null) {
|
||||||
|
audioAnalyzer.stop();
|
||||||
|
audioAnalyzer = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,10 +5,11 @@ import com.badlogic.gdx.scenes.scene2d.Group;
|
|||||||
import com.badlogic.gdx.scenes.scene2d.Touchable;
|
import com.badlogic.gdx.scenes.scene2d.Touchable;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||||
|
import com.badlogic.gdx.utils.Disposable;
|
||||||
|
|
||||||
import zero1hd.rhythmbullet.util.MiniSender;
|
import zero1hd.rhythmbullet.util.MiniSender;
|
||||||
|
|
||||||
public class Page extends Group {
|
public class Page extends Group implements Disposable {
|
||||||
private Label pageTitle;
|
private Label pageTitle;
|
||||||
|
|
||||||
public MiniSender miniSender;
|
public MiniSender miniSender;
|
||||||
@ -31,4 +32,8 @@ public class Page extends Group {
|
|||||||
public float getHeightBelowTitle() {
|
public float getHeightBelowTitle() {
|
||||||
return pageTitle.getY();
|
return pageTitle.getY();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user