From f8c326d8e462df2e5c34fc2dc35b35ea41527d7e Mon Sep 17 00:00:00 2001 From: Recrown Date: Thu, 25 May 2017 11:59:14 -0500 Subject: [PATCH] pade progress on analysis for creative and main stages --- .../zero1hd/polyjet/audio/AudioAnalyzer.java | 23 +++++++++++-------- .../polyjet/screens/PreGameScreen.java | 1 + .../zero1hd/polyjet/ui/pages/AnalyzePage.java | 2 ++ .../polyjet/ui/stages/CreativeStage.java | 1 + .../zero1hd/polyjet/ui/windows/FPSWindow.java | 2 +- 5 files changed, 19 insertions(+), 10 deletions(-) diff --git a/core/src/zero1hd/polyjet/audio/AudioAnalyzer.java b/core/src/zero1hd/polyjet/audio/AudioAnalyzer.java index d6d7091..56b1438 100755 --- a/core/src/zero1hd/polyjet/audio/AudioAnalyzer.java +++ b/core/src/zero1hd/polyjet/audio/AudioAnalyzer.java @@ -46,6 +46,7 @@ public class AudioAnalyzer { public MiniSender sender; + boolean work; private volatile int progress; public AudioAnalyzer() { sender = new MiniSender(); @@ -80,7 +81,7 @@ public class AudioAnalyzer { fft = new FloatFFT_1D(audiofile.getReadWindowSize()); - while (audiofile.readSamples(audioPCM) > 0) { + while (audiofile.readSamples(audioPCM) > 0 && work) { tasksDone++; fft.realForward(audioPCM); @@ -91,7 +92,7 @@ public class AudioAnalyzer { float fluxVal = 0; //bass detection fluxVal = 0; - for (int i = bassBinBegin; i < bassBinEnd; i++) { + for (int i = bassBinBegin; i < bassBinEnd && work; i++) { fluxVal += ((int) (spectrum[i] - lastSpectrum[i])) > 0 ? (int) (spectrum[i] - lastSpectrum[i]) : 0; } @@ -99,7 +100,7 @@ public class AudioAnalyzer { //main detection fluxVal = 0; - for (int i = UMBinBegin; i < UMBinEnd; i++) { + for (int i = UMBinBegin; i < UMBinEnd && work; i++) { fluxVal += ((int) (spectrum[i] - lastSpectrum[i])) > 0 ? (int) (spectrum[i] - lastSpectrum[i]) : 0; } @@ -123,7 +124,7 @@ public class AudioAnalyzer { public void run() { //threshold calculation - for (int i = 0; i < UMSpectralFlux.size; i++) { + for (int i = 0; i < UMSpectralFlux.size && work; i++) { int UMStart = Math.max(0, i - UMThresholdCalcRange/2); int UMEnd = Math.min(UMSpectralFlux.size - 1, i + UMThresholdCalcRange/2); @@ -150,7 +151,7 @@ public class AudioAnalyzer { //pruning data float prunnedCurrentVal; - for (int i = 0; i < UMSpectralFlux.size; i++) { + for (int i = 0; i < UMSpectralFlux.size && work; i++) { prunnedCurrentVal = bassSpectralFlux.get(i) - bassThreshold.get(i); if (prunnedCurrentVal >= 0) { @@ -170,7 +171,7 @@ public class AudioAnalyzer { Gdx.app.debug("Audio Analyzer", "Data prunned."); //peak detection - for (int i = 0; i < UMPrunned.size-1; i++) { + 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) { bassMaxValue = bassPeaks.get(i); @@ -185,7 +186,7 @@ public class AudioAnalyzer { Gdx.app.debug("Audio Analyzer", "Found all peaks."); //overlapping beats - for (int i = 0; i < UMPeaks.size; i++) { + for (int i = 0; i < UMPeaks.size && work; i++) { if (bassPeaks.get(i) != 0 && UMPeaks.get(i) != 0) { overlappedBeats.add(bassPeaks.get(i)+UMPeaks.get(i)/2); } else { @@ -239,7 +240,7 @@ public class AudioAnalyzer { spectrum = new float[(audiofile.getReadWindowSize()/2)+1]; lastSpectrum = new float[(audiofile.getReadWindowSize()/2)+1]; this.audiofile = audiofile; - + work = true; Thread analyticalThread = new Thread(analysisAlgorithm); analyticalThread.start(); } @@ -247,7 +248,7 @@ public class AudioAnalyzer { public void runThresholdCleaning(float baseThresholdMultiplier, float UMThresholdMultiplier) { this.bassThresholdMultiplier = baseThresholdMultiplier; this.UMThresholdMultiplier = UMThresholdMultiplier; - + work = true; Thread thresholdClean = new Thread(thresholdCalculator); thresholdClean.start(); } @@ -306,4 +307,8 @@ public class AudioAnalyzer { public boolean isFinalized() { return finalized; } + + public void stop() { + work = false; + } } diff --git a/core/src/zero1hd/polyjet/screens/PreGameScreen.java b/core/src/zero1hd/polyjet/screens/PreGameScreen.java index 5cd128e..9d99763 100755 --- a/core/src/zero1hd/polyjet/screens/PreGameScreen.java +++ b/core/src/zero1hd/polyjet/screens/PreGameScreen.java @@ -92,6 +92,7 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter, M ap = new AnalyzePage(core.getDefaultSkin(), core.getAssetManager()); ap.getAudioAnalyzer().sender.addListener(this); + ap.miniSender.addListener(this); ap.setPosition(Gdx.graphics.getWidth(), ap.getY()); stage.addActor(ap); return this; diff --git a/core/src/zero1hd/polyjet/ui/pages/AnalyzePage.java b/core/src/zero1hd/polyjet/ui/pages/AnalyzePage.java index 6ac034a..0083e5a 100755 --- a/core/src/zero1hd/polyjet/ui/pages/AnalyzePage.java +++ b/core/src/zero1hd/polyjet/ui/pages/AnalyzePage.java @@ -49,6 +49,7 @@ public class AnalyzePage extends Page { @Override public void changed(ChangeEvent event, Actor actor) { miniSender.send(MiniEvents.BACK); + audioAnalyzer.stop(); } }); songInfo.setSize(getWidth(), getHeightBelowTitle()); @@ -70,6 +71,7 @@ public class AnalyzePage extends Page { } + @Override public void act(float delta) { status.setText("Initial analysis: " + audioAnalyzer.getProgress()); diff --git a/core/src/zero1hd/polyjet/ui/stages/CreativeStage.java b/core/src/zero1hd/polyjet/ui/stages/CreativeStage.java index 0f12c0e..420253c 100755 --- a/core/src/zero1hd/polyjet/ui/stages/CreativeStage.java +++ b/core/src/zero1hd/polyjet/ui/stages/CreativeStage.java @@ -217,6 +217,7 @@ public class CreativeStage extends Stage implements MiniListener { volumeWindow.setMusic(musicPlayBackControls.getAudiofile()); beatViewer.setMusic(musicPlayBackControls.getAudiofile()); graphViewer.setData(analyzer.getBassPeaks(), analyzer.getUMPeaks(), musicPlayBackControls.getAudiofile()); + break; } } } diff --git a/core/src/zero1hd/polyjet/ui/windows/FPSWindow.java b/core/src/zero1hd/polyjet/ui/windows/FPSWindow.java index 9741e99..480b480 100755 --- a/core/src/zero1hd/polyjet/ui/windows/FPSWindow.java +++ b/core/src/zero1hd/polyjet/ui/windows/FPSWindow.java @@ -18,7 +18,7 @@ public class FPSWindow extends Window { }; add(FPS).center(); - setSize(70, 70); + setSize(140, 70); } } \ No newline at end of file