minor structure change for adding analysis page
This commit is contained in:
parent
6bc04d85c9
commit
cc2d9329b5
@ -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();
|
||||
@ -95,6 +96,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++) {
|
||||
int UMStart = Math.max(0, i - UMThresholdCalcRange/2);
|
||||
@ -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 void runThresholdCleaning(float baseThresholdMultiplier, float UMThresholdMultiplier) {
|
||||
this.bassThresholdMultiplier = baseThresholdMultiplier;
|
||||
this.UMThresholdMultiplier = UMThresholdMultiplier;
|
||||
|
||||
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;
|
||||
Thread thresholdClean = new Thread(thresholdCalculator);
|
||||
thresholdClean.start();
|
||||
}
|
||||
|
||||
public FloatArray getBassPeaks() {
|
||||
|
@ -1,12 +1,49 @@
|
||||
package zero1hd.polyjet.screens;
|
||||
|
||||
import com.badlogic.gdx.scenes.scene2d.Actor;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Slider;
|
||||
import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
||||
import com.badlogic.gdx.utils.SnapshotArray;
|
||||
|
||||
import zero1hd.polyjet.audio.AudioAnalyzer;
|
||||
import zero1hd.polyjet.audio.AudioData;
|
||||
import zero1hd.polyjet.ui.pages.Page;
|
||||
|
||||
public class AnalyzePage extends Page {
|
||||
AudioAnalyzer audioAnalyzer;
|
||||
AudioData music;
|
||||
|
||||
Table songInfo;
|
||||
Slider difficultyModifier;
|
||||
Label difficultyModifierPercentage;
|
||||
|
||||
public AnalyzePage(Skin skin) {
|
||||
super("Results", skin);
|
||||
audioAnalyzer = new AudioAnalyzer();
|
||||
}
|
||||
|
||||
public void setSong(AudioData music, SnapshotArray<Actor> uiMusicInfo) {
|
||||
this.music = music;
|
||||
audioAnalyzer.startAnalyticalThread(music);
|
||||
songInfo.add(uiMusicInfo.get(0)).spaceBottom(20f);
|
||||
songInfo.add(uiMusicInfo.pop()).expandX().center();
|
||||
songInfo.row();
|
||||
for (int currentActor = 1; currentActor < uiMusicInfo.size; currentActor++) {
|
||||
songInfo.add(uiMusicInfo.get(currentActor));
|
||||
songInfo.row();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasAudioData() {
|
||||
if (music != null) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
public void clearAUdioData() {
|
||||
music = null;
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter {
|
||||
|
||||
private MainMenu mainMenu;
|
||||
private MusicSelectionPage musicSelection;
|
||||
|
||||
private AnalyzePage analyzePage;
|
||||
public PreGameScreen(final Polyjet core, MainMenu mainMenu) {
|
||||
this.core = core;
|
||||
analyzer = new AudioAnalyzer();
|
||||
@ -58,8 +58,12 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter {
|
||||
cyberCircle1.setPosition(Gdx.graphics.getWidth()-cyberCircle1.getWidth()/2-10, -cyberCircle1.getHeight()*2/4f);
|
||||
stage.addActor(cyberCircle1);
|
||||
|
||||
analyzePage = new AnalyzePage(core.defaultSkin);
|
||||
analyzePage.setPosition(1f*Gdx.graphics.getWidth(), 0);
|
||||
stage.addActor(analyzePage);
|
||||
|
||||
//draw music selector
|
||||
musicSelection = new MusicSelectionPage(core, mainMenu);
|
||||
musicSelection = new MusicSelectionPage(core, mainMenu, analyzePage);
|
||||
stage.addActor(musicSelection);
|
||||
musicSelection.beginMusicSearch();
|
||||
|
||||
@ -82,7 +86,7 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter {
|
||||
stage.getCamera().position.lerp(cameraTarget, 0.25f);
|
||||
}
|
||||
|
||||
if (cameraTarget.x != 1.5f*Gdx.graphics.getWidth() && musicSelection.getAudio() != null) {
|
||||
if (cameraTarget.x != 1.5f*Gdx.graphics.getWidth() && analyzePage.hasAudioData()) {
|
||||
cameraTarget.x = 1.5f*Gdx.graphics.getWidth();
|
||||
}
|
||||
super.render(delta);
|
||||
|
@ -26,9 +26,6 @@ import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
||||
import com.badlogic.gdx.utils.Align;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
|
||||
import zero1hd.polyjet.audio.AudioData;
|
||||
import zero1hd.polyjet.audio.Mp3AudioData;
|
||||
import zero1hd.polyjet.audio.WavAudioData;
|
||||
import zero1hd.wavedecoder.WavInfo;
|
||||
|
||||
public class MusicSelectable extends Button implements Disposable {
|
||||
|
@ -19,6 +19,7 @@ import com.badlogic.gdx.utils.Align;
|
||||
import zero1hd.polyjet.Polyjet;
|
||||
import zero1hd.polyjet.audio.Audio;
|
||||
import zero1hd.polyjet.audio.AudioData;
|
||||
import zero1hd.polyjet.screens.AnalyzePage;
|
||||
import zero1hd.polyjet.screens.MainMenu;
|
||||
import zero1hd.polyjet.ui.builders.MusicSelectable;
|
||||
import zero1hd.polyjet.ui.windows.LoadingWindow;
|
||||
@ -34,13 +35,14 @@ public class MusicSelectionPage extends Page {
|
||||
protected volatile boolean cancel;
|
||||
private TextButton back;
|
||||
|
||||
private AudioData audio;
|
||||
public MusicSelectionPage(final Polyjet core, final MainMenu mainMenu) {
|
||||
private AnalyzePage ap;
|
||||
public MusicSelectionPage(final Polyjet core, final MainMenu mainMenu, AnalyzePage analyzePage) {
|
||||
super("Select music", core.defaultSkin);
|
||||
this.core = core;
|
||||
|
||||
musicFileAnnotation = Gdx.app.getPreferences("music_file_annotation");
|
||||
|
||||
this.ap = analyzePage;
|
||||
|
||||
back = new TextButton("Back", core.defaultSkin);
|
||||
back.setPosition(getWidth()-back.getWidth()-15f, getHeight()-back.getHeight()-15f);
|
||||
@ -124,7 +126,7 @@ public class MusicSelectionPage extends Page {
|
||||
|
||||
@Override
|
||||
public void changed(ChangeEvent event, Actor actor) {
|
||||
audio = Audio.getAudioData(selectable.getMusicFile());
|
||||
ap.setSong(Audio.getAudioData(selectable.getMusicFile()), selectable.getChildren());
|
||||
}
|
||||
}, Align.right);
|
||||
|
||||
@ -161,12 +163,4 @@ public class MusicSelectionPage extends Page {
|
||||
public float panelWidthCalc(float origWidth) {
|
||||
return (float) (Math.sqrt(getWidth()*35f)+80f);
|
||||
}
|
||||
|
||||
public AudioData getAudio() {
|
||||
return audio;
|
||||
}
|
||||
|
||||
public void removeAudio() {
|
||||
audio = null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user