minor structure change for adding analysis page
This commit is contained in:
@@ -16,8 +16,9 @@ public class AudioAnalyzer {
|
||||
float[] lastSpectrum;
|
||||
float[] fftData;
|
||||
|
||||
Thread analyticalThread;
|
||||
Runnable analysisAlgorithm;
|
||||
Runnable thresholdCalculator;
|
||||
|
||||
int bassBinBegin;
|
||||
int bassBinEnd;
|
||||
private FloatArray bassSpectralFlux = new FloatArray();
|
||||
@@ -94,6 +95,16 @@ public class AudioAnalyzer {
|
||||
}
|
||||
|
||||
Gdx.app.debug("Audio Analyzer", "Done getting spectral flux.");
|
||||
|
||||
shrinkData();
|
||||
containsData = true;
|
||||
}
|
||||
};
|
||||
|
||||
thresholdCalculator = new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
//threshold calculation
|
||||
for (int i = 0; i < UMSpectralFlux.size; i++) {
|
||||
@@ -166,13 +177,10 @@ public class AudioAnalyzer {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Gdx.app.debug("Audio Analyzer", "overlapped beats checked.");
|
||||
shrinkData();
|
||||
containsData = true;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public void resetVars() {
|
||||
@@ -212,39 +220,16 @@ public class AudioAnalyzer {
|
||||
lastSpectrum = new float[(audiofile.getReadWindowSize()/2)+1];
|
||||
this.audiofile = audiofile;
|
||||
|
||||
analyticalThread = new Thread(analysisAlgorithm);
|
||||
Thread analyticalThread = new Thread(analysisAlgorithm);
|
||||
analyticalThread.start();
|
||||
}
|
||||
|
||||
public float[][] splitChannelData(float[] samples, int channelCount) {
|
||||
int byteIndex = 0;
|
||||
float[][] splitSamples = new float[channelCount][samples.length / (channelCount * 2)];
|
||||
for (int currentByte = 0; currentByte < samples.length;) {
|
||||
for (int channel = 0; channel < channelCount; channel++) {
|
||||
int low = (int) samples[currentByte];
|
||||
currentByte++;
|
||||
int high = (int) samples[currentByte];
|
||||
currentByte++;
|
||||
splitSamples[channel][byteIndex] = (high << 8) + (low & 0x00ff);
|
||||
}
|
||||
byteIndex++;
|
||||
}
|
||||
return splitSamples;
|
||||
}
|
||||
|
||||
public float[] convertPCM(float[] leftChannel, float[] rightChannel) {
|
||||
float[] result = new float[leftChannel.length];
|
||||
for (int i = 0; i < leftChannel.length; i++)
|
||||
result[i] = (leftChannel[i] + rightChannel[i]) / 2 / 32768.0f;
|
||||
return result;
|
||||
}
|
||||
|
||||
public float[] byteToFloat(byte[] byteArray) {
|
||||
float[] floatArray = new float[byteArray.length];
|
||||
for (int i = 0; i < byteArray.length; i++) {
|
||||
floatArray[i] = byteArray[i];
|
||||
}
|
||||
return floatArray;
|
||||
|
||||
public void runThresholdCleaning(float baseThresholdMultiplier, float UMThresholdMultiplier) {
|
||||
this.bassThresholdMultiplier = baseThresholdMultiplier;
|
||||
this.UMThresholdMultiplier = UMThresholdMultiplier;
|
||||
|
||||
Thread thresholdClean = new Thread(thresholdCalculator);
|
||||
thresholdClean.start();
|
||||
}
|
||||
|
||||
public FloatArray getBassPeaks() {
|
||||
|
Reference in New Issue
Block a user