cleaned code and tuned audio analyzer

This commit is contained in:
Harrison Deng 2017-05-28 23:09:10 -05:00
parent 473adee281
commit 68422f0453
10 changed files with 37 additions and 11 deletions

View File

@ -65,7 +65,7 @@ public class AudioAnalyzer {
UMThresholdMultiplier = 2f;
bassBinBegin = 1;
bassBinEnd = 17;
bassBinEnd = 15;
UMBinBegin = 300;
UMBinEnd = 450;

View File

@ -3,8 +3,9 @@ package zero1hd.polyjet.audio;
import javax.sound.sampled.AudioFormat;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.utils.Disposable;
public interface AudioData {
public interface AudioData extends Disposable {
/**
* sets a integer variable to the current window of audio data the playback is at.
* Useful for efficiency because we compute once for that frame then get the values everytime it is required instead of calculating every time we get the index.

View File

@ -20,7 +20,6 @@ import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.files.FileHandle;
import javazoom.jl.decoder.Decoder;
import javazoom.spi.mpeg.sampled.convert.DecodedMpegAudioInputStream;
public class Mp3AudioData implements AudioData {
private int readWindowSize = 1024;
@ -35,8 +34,6 @@ public class Mp3AudioData implements AudioData {
private AudioInputStream in;
DecodedMpegAudioInputStream dStream;
Decoder decoder = new Decoder();
public Mp3AudioData(FileHandle audioFile) {
try {
@ -149,4 +146,15 @@ public class Mp3AudioData implements AudioData {
return sampleCount;
}
@Override
public void dispose() {
playbackMusic.dispose();
try {
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

View File

@ -8,11 +8,10 @@ import javax.sound.sampled.AudioFormat;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.files.FileHandle;
import com.badlogic.gdx.utils.Disposable;
import zero1hd.wavedecoder.WavDecoder;
public class WavAudioData implements AudioData, Disposable {
public class WavAudioData implements AudioData {
private int readWindowSize = 1024;
private AudioFormat format;
int readIndex;
@ -78,5 +77,6 @@ public class WavAudioData implements AudioData, Disposable {
@Override
public void dispose() {
playbackMusic.dispose();
decoder.cleanAndClose();
}
}

View File

@ -72,6 +72,8 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter, M
core.setScreen(new MainMenu(core).postTransition());
}
break;
default:
break;
}
}

View File

@ -7,7 +7,6 @@ import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.ScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Skin;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.utils.Align;

View File

@ -2,7 +2,6 @@ package zero1hd.polyjet.ui.pages;
import java.io.File;
import java.io.FilenameFilter;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;

View File

@ -58,6 +58,7 @@ public class CreativeStage extends Stage implements MiniListener {
@Override
public void changed(ChangeEvent event, Actor actor) {
dispose();
musicSelector.getSelectedMusic().reset();
core.setScreen(mainMenu);
}
});
@ -188,6 +189,7 @@ public class CreativeStage extends Stage implements MiniListener {
@Override
public void dispose() {
musicSelector.getSelectedMusic().dispose();
super.dispose();
}

View File

@ -43,7 +43,11 @@ public class BeatViewer extends Window {
public void act(float delta) {
if (music != null && data.getBassPeaks().get(songIndex) != 0) {
clearActions();
try {
addAction(Actions.sequence(Actions.sizeTo(getWidth(), (data.getBassPeaks().get(songIndex)/data.getBassMaxValue())*bgBassBar.getHeight()), Actions.sizeTo(getWidth(), 0, 0.3f)));
} catch (IndexOutOfBoundsException e) {
}
}
super.act(delta);
}
@ -62,7 +66,11 @@ public class BeatViewer extends Window {
public void act(float delta) {
if (music != null && data.getUMPeaks().get(songIndex) != 0) {
clearActions();
try {
addAction(Actions.sequence(Actions.sizeTo(getWidth(), (data.getUMPeaks().get(songIndex)/data.getUMMaxValue())*bgUMBar.getHeight()), Actions.sizeTo(getWidth(), 0f, 0.3f)));
} catch (IndexOutOfBoundsException e) {
}
}
super.act(delta);
}

View File

@ -148,4 +148,11 @@ public class WavDecoder {
return samplesRead;
}
public void cleanAndClose() {
try {
readStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}