worked on analysis progress and ui of analysis page
This commit is contained in:
parent
e698b9bc69
commit
e096444500
@ -149,7 +149,7 @@ public class Polyjet extends Game {
|
||||
|
||||
defaultSkin.add("large-font", default_fontGenerator.generateFont(new FreeTypeFontParameter() {
|
||||
{
|
||||
size = fontScale(0.08f);
|
||||
size = fontScale(0.085f);
|
||||
}
|
||||
}));
|
||||
|
||||
|
@ -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;
|
||||
|
||||
private int sampleCount;
|
||||
public Mp3AudioData(FileHandle audioFile) {
|
||||
try {
|
||||
sampleCount = (int) new MP3File(audioFile.file()).getMP3AudioHeader().getNumberOfFrames();
|
||||
} catch (IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
public Mp3AudioData(FileHandle setAudio) {
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
@ -59,13 +59,7 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter {
|
||||
cyberCircle1.setPosition(Gdx.graphics.getWidth()-cyberCircle1.getWidth()/2-10, -cyberCircle1.getHeight()*2/4f);
|
||||
stage.addActor(cyberCircle1);
|
||||
|
||||
Image cyberCircle2 = new Image(core.assetManager.get("cybercircle1.png", Texture.class));
|
||||
cyberCircle2.setPosition(1.5f*Gdx.graphics.getWidth()-cyberCircle2.getWidth()/2+20, (Gdx.graphics.getHeight()-cyberCircle2.getHeight())/2);
|
||||
cyberCircle2.setColor(0.8f,0.8f,0.8f,0.7f);
|
||||
cyberCircle2.addAction(Actions.alpha(0.7f));
|
||||
stage.addActor(cyberCircle2);
|
||||
|
||||
analyzePage = new AnalyzePage(core.defaultSkin, cameraTarget);
|
||||
analyzePage = new AnalyzePage(core.defaultSkin, cameraTarget, core.assetManager);
|
||||
analyzePage.setPosition(1f*Gdx.graphics.getWidth(), 0);
|
||||
stage.addActor(analyzePage);
|
||||
|
||||
|
@ -1,7 +1,11 @@
|
||||
package zero1hd.polyjet.ui.pages;
|
||||
|
||||
import com.badlogic.gdx.assets.AssetManager;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Slider;
|
||||
@ -25,14 +29,22 @@ public class AnalyzePage extends Page {
|
||||
private Skin skin;
|
||||
|
||||
private TextButton back;
|
||||
public AnalyzePage(Skin skin, Vector3 camPos) {
|
||||
private Image loadingCircle;
|
||||
|
||||
private Label status;
|
||||
public AnalyzePage(Skin skin, Vector3 camPos, AssetManager assets) {
|
||||
super("Results", skin);
|
||||
this.skin = skin;
|
||||
cameraPos = camPos;
|
||||
audioAnalyzer = new AudioAnalyzer();
|
||||
songInfo = new Table(skin);
|
||||
songInfo.debug();
|
||||
|
||||
loadingCircle = new Image(assets.get("cybercircle1.png", Texture.class));
|
||||
loadingCircle.setPosition((getWidth()-loadingCircle.getWidth())/2, (getHeightBelowTitle()-loadingCircle.getHeight())/2);
|
||||
loadingCircle.setColor(0.8f,0.8f,0.8f,0.7f);
|
||||
loadingCircle.setOrigin(loadingCircle.getWidth()/2, loadingCircle.getHeight()/2);
|
||||
loadingCircle.addAction(Actions.forever(Actions.rotateBy(-360f, 4f)));
|
||||
addActor(loadingCircle);
|
||||
|
||||
back = new TextButton("Back", skin);
|
||||
back.setPosition(getWidth()-back.getWidth()-15f, getHeightBelowTitle());
|
||||
@ -45,6 +57,7 @@ public class AnalyzePage extends Page {
|
||||
});
|
||||
songInfo.setSize(getWidth(), getHeightBelowTitle());
|
||||
|
||||
status = new Label(null, skin, "sub-font", skin.getColor("default"));
|
||||
|
||||
addActor(back);
|
||||
}
|
||||
@ -55,13 +68,16 @@ public class AnalyzePage extends Page {
|
||||
cameraPos.x = 1.5f*getWidth();
|
||||
this.music = music;
|
||||
audioAnalyzer.startAnalyticalThread(music);
|
||||
songInfo.add(new Label(audioInfo.getSongName(), skin));
|
||||
songInfo.add(new Label(audioInfo.getSongName(), skin, "large-font", skin.getColor("default")));
|
||||
songInfo.row();
|
||||
songInfo.add(status);
|
||||
addActor(songInfo);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void act(float delta) {
|
||||
status.setText("Initial analysis: " + audioAnalyzer.getProgress());
|
||||
super.act(delta);
|
||||
}
|
||||
|
||||
|
@ -109,7 +109,6 @@ public class MusicSelectionPage extends Page {
|
||||
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
System.out.println();
|
||||
ap.setSong(Audio.getAudioData(selectable.getMusicFile()), selectable.getAudioInfo());
|
||||
}
|
||||
});
|
||||
|
@ -189,7 +189,7 @@ public class CreativeStage extends Stage {
|
||||
postAnalysisComplete = false;
|
||||
}
|
||||
|
||||
if (!postAnalysisComplete && analyzer.containsData) {
|
||||
if (!postAnalysisComplete && analyzer.containsData()) {
|
||||
postAnalysisComplete = true;
|
||||
musicPlayBackControls.setMusicReady(true);
|
||||
beatViewer.setMusicReady(true);
|
||||
|
@ -49,7 +49,6 @@ public class LoadingWindow extends Window implements Disposable {
|
||||
Image loading = new Image(skin, "loading");
|
||||
loading.addAction(Actions.forever(Actions.rotateBy(-360f, 2f)));
|
||||
add(loading).left();
|
||||
System.out.println(loading.getHeight());
|
||||
|
||||
setSize(loading.getWidth()+20f, loading.getHeight()+40f);
|
||||
|
||||
@ -67,8 +66,6 @@ public class LoadingWindow extends Window implements Disposable {
|
||||
|
||||
public void playOpenSound() {
|
||||
openSound.play(vol/100f);
|
||||
System.out.println(vol);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user