furthered usage of new mini context object

This commit is contained in:
Harrison Deng 2017-09-01 03:12:36 -05:00
parent d00f434275
commit ba8a2182fb
7 changed files with 64 additions and 97 deletions

View File

@ -113,7 +113,7 @@ public class RhythmBullet extends Game {
public void dispose() {
Gdx.app.debug("Core", "disposing...");
if (initComplete) {
skinAtlas.dispose();
// skinAtlas.dispose();
getDefaultSkin().dispose();
default_fontGenerator.dispose();
darktech_ldr_fontGenerator.dispose();

View File

@ -12,7 +12,6 @@ import zero1hd.rhythmbullet.util.MiniSender;
public class AudioAnalyzer {
private boolean containsData;
private boolean finalized;
FloatFFT_1D fft;
private CoreMusicInfo musicInfo;
@ -20,8 +19,9 @@ public class AudioAnalyzer {
float[] spectrum;
float[] lastSpectrum;
Runnable analysisAlgorithm;
Runnable thresholdCalculator;
private ExecutorService exec = Executors.newSingleThreadExecutor();
private Runnable analysisAlgorithm;
private Runnable thresholdCalculator;
int bassBinBegin;
int bassBinEnd;
@ -57,7 +57,7 @@ public class AudioAnalyzer {
private float secondsPerWindow;
private AudioDataPackage pack;
public AudioAnalyzer() {
public AudioAnalyzer(CoreMusicInfo audiofile) {
sender = new MiniSender();
analysisAlgorithm = () -> {
@ -297,11 +297,18 @@ public class AudioAnalyzer {
pack.setMusicInfo(musicInfo);
if (work) {
finalized = true;
Gdx.app.debug("Audio Analyzer", "data cleaned and ready for map gen.");
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() {
@ -310,24 +317,12 @@ public class AudioAnalyzer {
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) {
this.bassThresholdMultiplier -= rangeModifier;
this.umThresholdMultiplier -= rangeModifier;
work = true;
if (containsData) {
ExecutorService exec = Executors.newSingleThreadExecutor();
exec.submit(thresholdCalculator);
} else {
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() {
work = true;
if (containsData) {
ExecutorService exec = Executors.newSingleThreadExecutor();
exec.submit(thresholdCalculator);
} else {
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()));
}
public float getBassMaxValue() {
return bassMaxValue;
}
public float getmMaxValue() {
return mMaxValue;
}
public float getUMMaxValue() {
return umMaxValue;
}
public boolean containsData() {
return containsData;
}
@ -368,44 +350,13 @@ public class AudioAnalyzer {
return progress;
}
public boolean isFinalized() {
return finalized;
}
public void stop() {
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() {
if (pack != null) {
exec.shutdown();
return pack;
} else {
throw new NullPointerException("Pack isn't filled yet... You made a mistake somewhere!");

View File

@ -41,8 +41,13 @@ public class MainMenu extends ScreenAdapter implements TransitionAdapter {
@Override
public void preTransition() {
stage.clear();
mainPage.dispose();
optionsPage.dispose();
creditsPage.dispose();
moreOptionsPage.dispose();
}
@Override
public void postTransition() {
mainPage = new MainPage(core, targetPosition);
mainPage.setPosition(0, 0);

View File

@ -52,7 +52,8 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter, M
@Override
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);
}
@ -78,6 +79,8 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter, M
@Override
public void preTransition() {
stage.clear();
ap.dispose();
ms.dispose();
}
@Override
@ -89,14 +92,10 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter, M
ap = new AnalyzePage(core);
ap.miniSender.addListener(this);
ap.setPosition(Gdx.graphics.getWidth(), ap.getY());
ap.setPosition(Gdx.graphics.getWidth(), 0);
stage.addActor(ap);
}
public void setPhase(int phase) {
cameraPos.x = Gdx.graphics.getWidth()*(phase + 0.5f);
}
@Override
public void show() {
Gdx.input.setInputProcessor(stage);

View File

@ -15,6 +15,7 @@ import com.badlogic.gdx.scenes.scene2d.utils.ChangeListener;
import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.audio.AudioAnalyzer;
import zero1hd.rhythmbullet.audio.AudioDataPackage;
import zero1hd.rhythmbullet.audio.map.RhythmMapAlgorithm;
import zero1hd.rhythmbullet.screens.MainMenu;
import zero1hd.rhythmbullet.stages.GamePlayArea;
@ -246,40 +247,37 @@ public class CreativeHUD extends Stage implements MiniListener {
musicPlayBackControls.getAudiofile().dispose();
}
musicPlayBackControls.setAudiofile(null);
analyzer = new AudioAnalyzer();
analyzer = new AudioAnalyzer(musicSelector.getSelectedMusic());
analyzer.sender.addListener(this);
analyzer.startAnalyticalThread(musicSelector.getSelectedMusic());
break;
case SPECTRAL_FLUX_DONE:
analyzer.runThresholdCleaning();
break;
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.getSender().addListener(this);
Thread mapGenThread = new Thread(mapGen);
mapGenThread.start();
}
break;
case MAP_GENERATED:
Gdx.app.debug("creative", "successfully generated map.");
musicPlayBackControls.setAudiofile(analyzer.getAudioData());
volumeWindow.setMusic(analyzer.getAudioData());
beatViewer.setMusic(analyzer.getAudioData(), analyzer.getAudioDataPackage());
AudioDataPackage adp = analyzer.getAudioDataPackage();
musicPlayBackControls.setAudiofile(adp.getMusicInfo());
volumeWindow.setMusic(adp.getMusicInfo());
beatViewer.setMusic(adp.getMusicInfo(), analyzer.getAudioDataPackage());
ghud.setMusic(null);
bassUMgraphWindow.setData(analyzer.getAudioDataPackage().getBassPeaks(), analyzer.getAudioDataPackage().getuMPeaks(), analyzer.getAudioData());
bassUMgraphWindow.getGraph().avgG1 = analyzer.getBassAvg();
bassUMgraphWindow.getGraph().normalDataG1 = analyzer.getBassMaxValue();
bassUMgraphWindow.getGraph().avgG2 = analyzer.getUmAvg();
bassUMgraphWindow.getGraph().normalDataG2 = analyzer.getUMMaxValue();
bassUMgraphWindow.setData(analyzer.getAudioDataPackage().getBassPeaks(), analyzer.getAudioDataPackage().getuMPeaks(), adp.getMusicInfo());
bassUMgraphWindow.getGraph().avgG1 = adp.getBassAvg();
bassUMgraphWindow.getGraph().normalDataG1 = adp.getBassMaxVal();
bassUMgraphWindow.getGraph().avgG2 = adp.getuMAvg();
bassUMgraphWindow.getGraph().normalDataG2 = adp.getuMMaxval();
mGraphWindow.setData(analyzer.getAudioDataPackage().getmPeaks(), null, analyzer.getAudioData());
mGraphWindow.getGraph().normalDataG1 = analyzer.getmMaxValue();
mGraphWindow.getGraph().avgG1 = analyzer.getmAvg();
mGraphWindow.setData(analyzer.getAudioDataPackage().getmPeaks(), null, adp.getMusicInfo());
mGraphWindow.getGraph().normalDataG1 = adp.getmMaxVal();
mGraphWindow.getGraph().avgG1 = adp.getmAvg();
gpa.setAudioMap(mapGen.getMap());
ghud.setMusic(analyzer.getAudioData().getPlaybackMusic());
ghud.setMusic(adp.getMusicInfo().getPlaybackMusic());
break;
default:
break;

View File

@ -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.utils.ChangeListener;
import com.badlogic.gdx.utils.Align;
import com.badlogic.gdx.utils.Disposable;
import zero1hd.rhythmbullet.RhythmBullet;
import zero1hd.rhythmbullet.audio.AudioAnalyzer;
@ -27,7 +28,7 @@ import zero1hd.rhythmbullet.ui.builders.ScrollText;
import zero1hd.rhythmbullet.util.MiniEvents;
import zero1hd.rhythmbullet.util.MiniListener;
public class AnalyzePage extends Page implements MiniListener {
public class AnalyzePage extends Page implements MiniListener, Disposable {
private AnalyzePage ap = this;
AudioAnalyzer audioAnalyzer;
@ -194,12 +195,12 @@ public class AnalyzePage extends Page implements MiniListener {
songInfo.clear();
songInfo.defaults().align(Align.left | Align.top);
audioAnalyzer = new AudioAnalyzer();
audioAnalyzer.sender.addListener(this);
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);
for (int i = 0; i < info.length; i++) {
@ -311,4 +312,12 @@ public class AnalyzePage extends Page implements MiniListener {
public GamePlayMap getMap() {
return mapGenAlgorithm.getMap();
}
@Override
public void dispose() {
if (audioAnalyzer != null) {
audioAnalyzer.stop();
audioAnalyzer = null;
}
}
}

View File

@ -5,10 +5,11 @@ import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.Touchable;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.utils.Disposable;
import zero1hd.rhythmbullet.util.MiniSender;
public class Page extends Group {
public class Page extends Group implements Disposable {
private Label pageTitle;
public MiniSender miniSender;
@ -31,4 +32,8 @@ public class Page extends Group {
public float getHeightBelowTitle() {
return pageTitle.getY();
}
@Override
public void dispose() {
}
}