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[] lastSpectrum;
|
||||||
float[] fftData;
|
float[] fftData;
|
||||||
|
|
||||||
Thread analyticalThread;
|
|
||||||
Runnable analysisAlgorithm;
|
Runnable analysisAlgorithm;
|
||||||
|
Runnable thresholdCalculator;
|
||||||
|
|
||||||
int bassBinBegin;
|
int bassBinBegin;
|
||||||
int bassBinEnd;
|
int bassBinEnd;
|
||||||
private FloatArray bassSpectralFlux = new FloatArray();
|
private FloatArray bassSpectralFlux = new FloatArray();
|
||||||
@ -95,6 +96,16 @@ public class AudioAnalyzer {
|
|||||||
|
|
||||||
Gdx.app.debug("Audio Analyzer", "Done getting spectral flux.");
|
Gdx.app.debug("Audio Analyzer", "Done getting spectral flux.");
|
||||||
|
|
||||||
|
shrinkData();
|
||||||
|
containsData = true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
thresholdCalculator = new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
|
||||||
//threshold calculation
|
//threshold calculation
|
||||||
for (int i = 0; i < UMSpectralFlux.size; i++) {
|
for (int i = 0; i < UMSpectralFlux.size; i++) {
|
||||||
int UMStart = Math.max(0, i - UMThresholdCalcRange/2);
|
int UMStart = Math.max(0, i - UMThresholdCalcRange/2);
|
||||||
@ -166,13 +177,10 @@ public class AudioAnalyzer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Gdx.app.debug("Audio Analyzer", "overlapped beats checked.");
|
Gdx.app.debug("Audio Analyzer", "overlapped beats checked.");
|
||||||
shrinkData();
|
|
||||||
containsData = true;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetVars() {
|
public void resetVars() {
|
||||||
@ -212,39 +220,16 @@ public class AudioAnalyzer {
|
|||||||
lastSpectrum = new float[(audiofile.getReadWindowSize()/2)+1];
|
lastSpectrum = new float[(audiofile.getReadWindowSize()/2)+1];
|
||||||
this.audiofile = audiofile;
|
this.audiofile = audiofile;
|
||||||
|
|
||||||
analyticalThread = new Thread(analysisAlgorithm);
|
Thread analyticalThread = new Thread(analysisAlgorithm);
|
||||||
analyticalThread.start();
|
analyticalThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public float[][] splitChannelData(float[] samples, int channelCount) {
|
public void runThresholdCleaning(float baseThresholdMultiplier, float UMThresholdMultiplier) {
|
||||||
int byteIndex = 0;
|
this.bassThresholdMultiplier = baseThresholdMultiplier;
|
||||||
float[][] splitSamples = new float[channelCount][samples.length / (channelCount * 2)];
|
this.UMThresholdMultiplier = UMThresholdMultiplier;
|
||||||
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) {
|
Thread thresholdClean = new Thread(thresholdCalculator);
|
||||||
float[] result = new float[leftChannel.length];
|
thresholdClean.start();
|
||||||
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 FloatArray getBassPeaks() {
|
public FloatArray getBassPeaks() {
|
||||||
|
@ -1,12 +1,49 @@
|
|||||||
package zero1hd.polyjet.screens;
|
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.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;
|
import zero1hd.polyjet.ui.pages.Page;
|
||||||
|
|
||||||
public class AnalyzePage extends Page {
|
public class AnalyzePage extends Page {
|
||||||
|
AudioAnalyzer audioAnalyzer;
|
||||||
|
AudioData music;
|
||||||
|
|
||||||
|
Table songInfo;
|
||||||
|
Slider difficultyModifier;
|
||||||
|
Label difficultyModifierPercentage;
|
||||||
|
|
||||||
public AnalyzePage(Skin skin) {
|
public AnalyzePage(Skin skin) {
|
||||||
super("Results", 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 MainMenu mainMenu;
|
||||||
private MusicSelectionPage musicSelection;
|
private MusicSelectionPage musicSelection;
|
||||||
|
private AnalyzePage analyzePage;
|
||||||
public PreGameScreen(final Polyjet core, MainMenu mainMenu) {
|
public PreGameScreen(final Polyjet core, MainMenu mainMenu) {
|
||||||
this.core = core;
|
this.core = core;
|
||||||
analyzer = new AudioAnalyzer();
|
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);
|
cyberCircle1.setPosition(Gdx.graphics.getWidth()-cyberCircle1.getWidth()/2-10, -cyberCircle1.getHeight()*2/4f);
|
||||||
stage.addActor(cyberCircle1);
|
stage.addActor(cyberCircle1);
|
||||||
|
|
||||||
|
analyzePage = new AnalyzePage(core.defaultSkin);
|
||||||
|
analyzePage.setPosition(1f*Gdx.graphics.getWidth(), 0);
|
||||||
|
stage.addActor(analyzePage);
|
||||||
|
|
||||||
//draw music selector
|
//draw music selector
|
||||||
musicSelection = new MusicSelectionPage(core, mainMenu);
|
musicSelection = new MusicSelectionPage(core, mainMenu, analyzePage);
|
||||||
stage.addActor(musicSelection);
|
stage.addActor(musicSelection);
|
||||||
musicSelection.beginMusicSearch();
|
musicSelection.beginMusicSearch();
|
||||||
|
|
||||||
@ -82,7 +86,7 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter {
|
|||||||
stage.getCamera().position.lerp(cameraTarget, 0.25f);
|
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();
|
cameraTarget.x = 1.5f*Gdx.graphics.getWidth();
|
||||||
}
|
}
|
||||||
super.render(delta);
|
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.Align;
|
||||||
import com.badlogic.gdx.utils.Disposable;
|
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;
|
import zero1hd.wavedecoder.WavInfo;
|
||||||
|
|
||||||
public class MusicSelectable extends Button implements Disposable {
|
public class MusicSelectable extends Button implements Disposable {
|
||||||
|
@ -19,6 +19,7 @@ import com.badlogic.gdx.utils.Align;
|
|||||||
import zero1hd.polyjet.Polyjet;
|
import zero1hd.polyjet.Polyjet;
|
||||||
import zero1hd.polyjet.audio.Audio;
|
import zero1hd.polyjet.audio.Audio;
|
||||||
import zero1hd.polyjet.audio.AudioData;
|
import zero1hd.polyjet.audio.AudioData;
|
||||||
|
import zero1hd.polyjet.screens.AnalyzePage;
|
||||||
import zero1hd.polyjet.screens.MainMenu;
|
import zero1hd.polyjet.screens.MainMenu;
|
||||||
import zero1hd.polyjet.ui.builders.MusicSelectable;
|
import zero1hd.polyjet.ui.builders.MusicSelectable;
|
||||||
import zero1hd.polyjet.ui.windows.LoadingWindow;
|
import zero1hd.polyjet.ui.windows.LoadingWindow;
|
||||||
@ -34,13 +35,14 @@ public class MusicSelectionPage extends Page {
|
|||||||
protected volatile boolean cancel;
|
protected volatile boolean cancel;
|
||||||
private TextButton back;
|
private TextButton back;
|
||||||
|
|
||||||
private AudioData audio;
|
private AnalyzePage ap;
|
||||||
public MusicSelectionPage(final Polyjet core, final MainMenu mainMenu) {
|
public MusicSelectionPage(final Polyjet core, final MainMenu mainMenu, AnalyzePage analyzePage) {
|
||||||
super("Select music", core.defaultSkin);
|
super("Select music", core.defaultSkin);
|
||||||
this.core = core;
|
this.core = core;
|
||||||
|
|
||||||
musicFileAnnotation = Gdx.app.getPreferences("music_file_annotation");
|
musicFileAnnotation = Gdx.app.getPreferences("music_file_annotation");
|
||||||
|
|
||||||
|
this.ap = analyzePage;
|
||||||
|
|
||||||
back = new TextButton("Back", core.defaultSkin);
|
back = new TextButton("Back", core.defaultSkin);
|
||||||
back.setPosition(getWidth()-back.getWidth()-15f, getHeight()-back.getHeight()-15f);
|
back.setPosition(getWidth()-back.getWidth()-15f, getHeight()-back.getHeight()-15f);
|
||||||
@ -124,7 +126,7 @@ public class MusicSelectionPage extends Page {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void changed(ChangeEvent event, Actor actor) {
|
public void changed(ChangeEvent event, Actor actor) {
|
||||||
audio = Audio.getAudioData(selectable.getMusicFile());
|
ap.setSong(Audio.getAudioData(selectable.getMusicFile()), selectable.getChildren());
|
||||||
}
|
}
|
||||||
}, Align.right);
|
}, Align.right);
|
||||||
|
|
||||||
@ -161,12 +163,4 @@ public class MusicSelectionPage extends Page {
|
|||||||
public float panelWidthCalc(float origWidth) {
|
public float panelWidthCalc(float origWidth) {
|
||||||
return (float) (Math.sqrt(getWidth()*35f)+80f);
|
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