worked on analysis progress and ui of analysis page
This commit is contained in:
@@ -1,12 +1,14 @@
|
||||
package zero1hd.polyjet.audio;
|
||||
|
||||
import org.jaudiotagger.audio.AudioFile;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.utils.FloatArray;
|
||||
|
||||
import edu.emory.mathcs.jtransforms.fft.FloatFFT_1D;
|
||||
|
||||
public class AudioAnalyzer {
|
||||
public boolean containsData;
|
||||
private boolean containsData;
|
||||
|
||||
FloatFFT_1D fft;
|
||||
public AudioData audiofile;
|
||||
@@ -42,11 +44,17 @@ public class AudioAnalyzer {
|
||||
int UMThresholdCalcRange;
|
||||
int bassThresholdCalcRange;
|
||||
|
||||
|
||||
private volatile int progress;
|
||||
public AudioAnalyzer() {
|
||||
analysisAlgorithm = new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
progress = 0;
|
||||
int tasksDone = 0;
|
||||
int totalTasks = audiofile.getSampleCount()/audiofile.getReadWindowSize();
|
||||
|
||||
bassThresholdMultiplier = 1.5f;
|
||||
UMThresholdMultiplier = 2f;
|
||||
|
||||
@@ -69,7 +77,7 @@ public class AudioAnalyzer {
|
||||
|
||||
fft = new FloatFFT_1D(audiofile.getReadWindowSize());
|
||||
while (audiofile.readSamples(audioPCM) > 0) {
|
||||
|
||||
tasksDone++;
|
||||
|
||||
fft.realForward(audioPCM);
|
||||
|
||||
@@ -92,6 +100,8 @@ public class AudioAnalyzer {
|
||||
? (int) (spectrum[i] - lastSpectrum[i]) : 0;
|
||||
}
|
||||
UMSpectralFlux.add(fluxVal);
|
||||
|
||||
progress = (int) (100f*tasksDone/totalTasks);
|
||||
}
|
||||
|
||||
Gdx.app.debug("Audio Analyzer", "Done getting spectral flux.");
|
||||
@@ -273,4 +283,8 @@ public class AudioAnalyzer {
|
||||
public boolean containsData() {
|
||||
return containsData;
|
||||
}
|
||||
|
||||
public synchronized int getProgress() {
|
||||
return progress;
|
||||
}
|
||||
}
|
||||
|
@@ -46,4 +46,10 @@ public interface AudioData {
|
||||
* @return
|
||||
*/
|
||||
public AudioFormat getFormat();
|
||||
|
||||
/**
|
||||
* Returns object containing basic audio data;
|
||||
* @return
|
||||
*/
|
||||
public int getSampleCount();
|
||||
}
|
||||
|
@@ -7,6 +7,11 @@ import javax.sound.sampled.AudioInputStream;
|
||||
import javax.sound.sampled.AudioSystem;
|
||||
import javax.sound.sampled.UnsupportedAudioFileException;
|
||||
|
||||
import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException;
|
||||
import org.jaudiotagger.audio.exceptions.ReadOnlyFileException;
|
||||
import org.jaudiotagger.audio.mp3.MP3File;
|
||||
import org.jaudiotagger.tag.TagException;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.audio.Music;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
@@ -21,11 +26,17 @@ public class Mp3AudioData implements AudioData {
|
||||
private Music playbackMusic;
|
||||
private int readIndex;
|
||||
|
||||
|
||||
public Mp3AudioData(FileHandle setAudio) {
|
||||
private int sampleCount;
|
||||
public Mp3AudioData(FileHandle audioFile) {
|
||||
try {
|
||||
sampleCount = (int) new MP3File(audioFile.file()).getMP3AudioHeader().getNumberOfFrames();
|
||||
} catch (IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
reset();
|
||||
try {
|
||||
audStream = AudioSystem.getAudioInputStream(setAudio.file());
|
||||
audStream = AudioSystem.getAudioInputStream(audioFile.file());
|
||||
AudioFormat bFormat = audStream.getFormat();
|
||||
audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, bFormat.getSampleRate(), 16, bFormat.getChannels(), bFormat.getChannels()*2, bFormat.getSampleRate(), false);
|
||||
faudStream = AudioSystem.getAudioInputStream(audioFormat, audStream);
|
||||
@@ -34,7 +45,7 @@ public class Mp3AudioData implements AudioData {
|
||||
}
|
||||
|
||||
|
||||
playbackMusic = Gdx.audio.newMusic(setAudio);
|
||||
playbackMusic = Gdx.audio.newMusic(audioFile);
|
||||
}
|
||||
|
||||
|
||||
@@ -108,4 +119,10 @@ public class Mp3AudioData implements AudioData {
|
||||
return audioFormat;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getSampleCount() {
|
||||
return sampleCount;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -70,4 +70,9 @@ public class WavAudioData implements AudioData {
|
||||
public AudioFormat getFormat() {
|
||||
return format;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSampleCount() {
|
||||
return decoder.getDataSize()/(2*decoder.getChannels());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user