pade progress on analysis for creative and main stages
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user