pade progress on analysis for creative and main stages

This commit is contained in:
Harrison Deng 2017-05-25 11:59:14 -05:00
parent 7e2839eb55
commit f8c326d8e4
5 changed files with 19 additions and 10 deletions

View File

@ -46,6 +46,7 @@ public class AudioAnalyzer {
public MiniSender sender; public MiniSender sender;
boolean work;
private volatile int progress; private volatile int progress;
public AudioAnalyzer() { public AudioAnalyzer() {
sender = new MiniSender(); sender = new MiniSender();
@ -80,7 +81,7 @@ public class AudioAnalyzer {
fft = new FloatFFT_1D(audiofile.getReadWindowSize()); fft = new FloatFFT_1D(audiofile.getReadWindowSize());
while (audiofile.readSamples(audioPCM) > 0) { while (audiofile.readSamples(audioPCM) > 0 && work) {
tasksDone++; tasksDone++;
fft.realForward(audioPCM); fft.realForward(audioPCM);
@ -91,7 +92,7 @@ public class AudioAnalyzer {
float fluxVal = 0; float fluxVal = 0;
//bass detection //bass detection
fluxVal = 0; fluxVal = 0;
for (int i = bassBinBegin; i < bassBinEnd; i++) { for (int i = bassBinBegin; i < bassBinEnd && work; i++) {
fluxVal += ((int) (spectrum[i] - lastSpectrum[i])) > 0 fluxVal += ((int) (spectrum[i] - lastSpectrum[i])) > 0
? (int) (spectrum[i] - lastSpectrum[i]) : 0; ? (int) (spectrum[i] - lastSpectrum[i]) : 0;
} }
@ -99,7 +100,7 @@ public class AudioAnalyzer {
//main detection //main detection
fluxVal = 0; fluxVal = 0;
for (int i = UMBinBegin; i < UMBinEnd; i++) { for (int i = UMBinBegin; i < UMBinEnd && work; i++) {
fluxVal += ((int) (spectrum[i] - lastSpectrum[i])) > 0 fluxVal += ((int) (spectrum[i] - lastSpectrum[i])) > 0
? (int) (spectrum[i] - lastSpectrum[i]) : 0; ? (int) (spectrum[i] - lastSpectrum[i]) : 0;
} }
@ -123,7 +124,7 @@ public class AudioAnalyzer {
public void run() { public void run() {
//threshold calculation //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 UMStart = Math.max(0, i - UMThresholdCalcRange/2);
int UMEnd = Math.min(UMSpectralFlux.size - 1, i + UMThresholdCalcRange/2); int UMEnd = Math.min(UMSpectralFlux.size - 1, i + UMThresholdCalcRange/2);
@ -150,7 +151,7 @@ public class AudioAnalyzer {
//pruning data //pruning data
float prunnedCurrentVal; 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); prunnedCurrentVal = bassSpectralFlux.get(i) - bassThreshold.get(i);
if (prunnedCurrentVal >= 0) { if (prunnedCurrentVal >= 0) {
@ -170,7 +171,7 @@ public class AudioAnalyzer {
Gdx.app.debug("Audio Analyzer", "Data prunned."); Gdx.app.debug("Audio Analyzer", "Data prunned.");
//peak detection //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)); bassPeaks.add((bassPrunned.get(i) > bassPrunned.get(i+1) ? bassPrunned.get(i) : 0));
if (bassPeaks.get(i) > bassMaxValue) { if (bassPeaks.get(i) > bassMaxValue) {
bassMaxValue = bassPeaks.get(i); bassMaxValue = bassPeaks.get(i);
@ -185,7 +186,7 @@ public class AudioAnalyzer {
Gdx.app.debug("Audio Analyzer", "Found all peaks."); Gdx.app.debug("Audio Analyzer", "Found all peaks.");
//overlapping beats //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) { if (bassPeaks.get(i) != 0 && UMPeaks.get(i) != 0) {
overlappedBeats.add(bassPeaks.get(i)+UMPeaks.get(i)/2); overlappedBeats.add(bassPeaks.get(i)+UMPeaks.get(i)/2);
} else { } else {
@ -239,7 +240,7 @@ public class AudioAnalyzer {
spectrum = new float[(audiofile.getReadWindowSize()/2)+1]; spectrum = new float[(audiofile.getReadWindowSize()/2)+1];
lastSpectrum = new float[(audiofile.getReadWindowSize()/2)+1]; lastSpectrum = new float[(audiofile.getReadWindowSize()/2)+1];
this.audiofile = audiofile; this.audiofile = audiofile;
work = true;
Thread analyticalThread = new Thread(analysisAlgorithm); Thread analyticalThread = new Thread(analysisAlgorithm);
analyticalThread.start(); analyticalThread.start();
} }
@ -247,7 +248,7 @@ public class AudioAnalyzer {
public void runThresholdCleaning(float baseThresholdMultiplier, float UMThresholdMultiplier) { public void runThresholdCleaning(float baseThresholdMultiplier, float UMThresholdMultiplier) {
this.bassThresholdMultiplier = baseThresholdMultiplier; this.bassThresholdMultiplier = baseThresholdMultiplier;
this.UMThresholdMultiplier = UMThresholdMultiplier; this.UMThresholdMultiplier = UMThresholdMultiplier;
work = true;
Thread thresholdClean = new Thread(thresholdCalculator); Thread thresholdClean = new Thread(thresholdCalculator);
thresholdClean.start(); thresholdClean.start();
} }
@ -306,4 +307,8 @@ public class AudioAnalyzer {
public boolean isFinalized() { public boolean isFinalized() {
return finalized; return finalized;
} }
public void stop() {
work = false;
}
} }

View File

@ -92,6 +92,7 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter, M
ap = new AnalyzePage(core.getDefaultSkin(), core.getAssetManager()); ap = new AnalyzePage(core.getDefaultSkin(), core.getAssetManager());
ap.getAudioAnalyzer().sender.addListener(this); ap.getAudioAnalyzer().sender.addListener(this);
ap.miniSender.addListener(this);
ap.setPosition(Gdx.graphics.getWidth(), ap.getY()); ap.setPosition(Gdx.graphics.getWidth(), ap.getY());
stage.addActor(ap); stage.addActor(ap);
return this; return this;

View File

@ -49,6 +49,7 @@ public class AnalyzePage extends Page {
@Override @Override
public void changed(ChangeEvent event, Actor actor) { public void changed(ChangeEvent event, Actor actor) {
miniSender.send(MiniEvents.BACK); miniSender.send(MiniEvents.BACK);
audioAnalyzer.stop();
} }
}); });
songInfo.setSize(getWidth(), getHeightBelowTitle()); songInfo.setSize(getWidth(), getHeightBelowTitle());
@ -70,6 +71,7 @@ public class AnalyzePage extends Page {
} }
@Override @Override
public void act(float delta) { public void act(float delta) {
status.setText("Initial analysis: " + audioAnalyzer.getProgress()); status.setText("Initial analysis: " + audioAnalyzer.getProgress());

View File

@ -217,6 +217,7 @@ public class CreativeStage extends Stage implements MiniListener {
volumeWindow.setMusic(musicPlayBackControls.getAudiofile()); volumeWindow.setMusic(musicPlayBackControls.getAudiofile());
beatViewer.setMusic(musicPlayBackControls.getAudiofile()); beatViewer.setMusic(musicPlayBackControls.getAudiofile());
graphViewer.setData(analyzer.getBassPeaks(), analyzer.getUMPeaks(), musicPlayBackControls.getAudiofile()); graphViewer.setData(analyzer.getBassPeaks(), analyzer.getUMPeaks(), musicPlayBackControls.getAudiofile());
break;
} }
} }
} }

View File

@ -18,7 +18,7 @@ public class FPSWindow extends Window {
}; };
add(FPS).center(); add(FPS).center();
setSize(70, 70); setSize(140, 70);
} }
} }