pade progress on analysis for creative and main stages
This commit is contained in:
parent
7e2839eb55
commit
f8c326d8e4
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ public class FPSWindow extends Window {
|
||||
};
|
||||
|
||||
add(FPS).center();
|
||||
setSize(70, 70);
|
||||
setSize(140, 70);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user