fixed issue caused by misunderstanding(?) of samplerate
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package zero1hd.rhythmbullet.audio.analyzer;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.utils.FloatArray;
|
||||
|
||||
import edu.emory.mathcs.jtransforms.fft.FloatFFT_1D;
|
||||
@@ -28,7 +29,7 @@ public class SpectralFluxAnalysisRunnable implements Runnable {
|
||||
public void run() {
|
||||
progress = 0;
|
||||
int tasksDone = 0;
|
||||
long totalTasks = musicManager.getSampleCount()/musicManager.getReadWindowSize();
|
||||
long totalTasks = MathUtils.round((float)musicManager.getSampleCount()/musicManager.getChannelCount()/musicManager.getReadWindowSize());
|
||||
|
||||
float[] audioPCM = new float[musicManager.getReadWindowSize()];
|
||||
float[] spectrum = new float[(musicManager.getReadWindowSize()/2)+1];
|
||||
@@ -52,7 +53,7 @@ public class SpectralFluxAnalysisRunnable implements Runnable {
|
||||
FloatFFT_1D fft = new FloatFFT_1D(musicManager.getReadWindowSize());
|
||||
int seedDigit = 0;
|
||||
|
||||
while (musicManager.readSamples(audioPCM) > 0 && work) {
|
||||
while (musicManager.readSampleFrames(audioPCM) > 0 && work) {
|
||||
|
||||
fft.realForward(audioPCM);
|
||||
|
||||
|
@@ -31,7 +31,7 @@ public class WAVSampleReader {
|
||||
return audioInputStream.getFrameLength();
|
||||
}
|
||||
|
||||
public int readSamples(float[] samples) throws IOException {
|
||||
public int readSamplesAsFrames(float[] samples) throws IOException {
|
||||
int framesRead = 0;
|
||||
for (int sampleID = 0; sampleID < samples.length; sampleID++) {
|
||||
if (audioInputStream.read(buffer) > 0) {
|
||||
@@ -53,28 +53,6 @@ public class WAVSampleReader {
|
||||
return framesRead;
|
||||
}
|
||||
|
||||
public int readSamples(short[] samples) throws IOException {
|
||||
int framesRead = 0;
|
||||
|
||||
for (int sampleID = 0; sampleID < samples.length; sampleID++) {
|
||||
if (audioInputStream.read(buffer) > 0) {
|
||||
samples[sampleID] += (buffer[1] << 8) + (buffer[0] & 0x00ff);
|
||||
if (audioInputStream.getFormat().getChannels() > 1) {
|
||||
short altChan = (short) ((buffer[3] << 8) + (buffer[2] & 0x00ff));
|
||||
if (mergeChannels) {
|
||||
samples[sampleID] = altChan > samples[sampleID] ? altChan : samples[sampleID];
|
||||
} else {
|
||||
sampleID++;
|
||||
samples[sampleID] = altChan;
|
||||
}
|
||||
}
|
||||
framesRead ++;
|
||||
}
|
||||
|
||||
}
|
||||
return framesRead;
|
||||
}
|
||||
|
||||
public AudioInputStream getAudioInputStream() {
|
||||
return audioInputStream;
|
||||
}
|
||||
|
@@ -31,7 +31,7 @@ public interface MusicManager extends Disposable {
|
||||
* @param samples the array that should contain said samples
|
||||
* @return amount read. Will return 0 if end of stream.
|
||||
*/
|
||||
public int readSamples(float[] samples);
|
||||
public int readSampleFrames(float[] samples);
|
||||
|
||||
/**
|
||||
* returns sample count.
|
||||
|
Reference in New Issue
Block a user