cleaned code and tuned audio analyzer
This commit is contained in:
parent
473adee281
commit
68422f0453
@ -65,7 +65,7 @@ public class AudioAnalyzer {
|
|||||||
UMThresholdMultiplier = 2f;
|
UMThresholdMultiplier = 2f;
|
||||||
|
|
||||||
bassBinBegin = 1;
|
bassBinBegin = 1;
|
||||||
bassBinEnd = 17;
|
bassBinEnd = 15;
|
||||||
|
|
||||||
UMBinBegin = 300;
|
UMBinBegin = 300;
|
||||||
UMBinEnd = 450;
|
UMBinEnd = 450;
|
||||||
|
@ -3,8 +3,9 @@ package zero1hd.polyjet.audio;
|
|||||||
import javax.sound.sampled.AudioFormat;
|
import javax.sound.sampled.AudioFormat;
|
||||||
|
|
||||||
import com.badlogic.gdx.audio.Music;
|
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.
|
* 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.
|
* 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.
|
||||||
|
@ -20,7 +20,6 @@ import com.badlogic.gdx.audio.Music;
|
|||||||
import com.badlogic.gdx.files.FileHandle;
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
|
|
||||||
import javazoom.jl.decoder.Decoder;
|
import javazoom.jl.decoder.Decoder;
|
||||||
import javazoom.spi.mpeg.sampled.convert.DecodedMpegAudioInputStream;
|
|
||||||
|
|
||||||
public class Mp3AudioData implements AudioData {
|
public class Mp3AudioData implements AudioData {
|
||||||
private int readWindowSize = 1024;
|
private int readWindowSize = 1024;
|
||||||
@ -35,8 +34,6 @@ public class Mp3AudioData implements AudioData {
|
|||||||
|
|
||||||
private AudioInputStream in;
|
private AudioInputStream in;
|
||||||
|
|
||||||
DecodedMpegAudioInputStream dStream;
|
|
||||||
|
|
||||||
Decoder decoder = new Decoder();
|
Decoder decoder = new Decoder();
|
||||||
public Mp3AudioData(FileHandle audioFile) {
|
public Mp3AudioData(FileHandle audioFile) {
|
||||||
try {
|
try {
|
||||||
@ -149,4 +146,15 @@ public class Mp3AudioData implements AudioData {
|
|||||||
return sampleCount;
|
return sampleCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
playbackMusic.dispose();
|
||||||
|
try {
|
||||||
|
in.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -8,11 +8,10 @@ import javax.sound.sampled.AudioFormat;
|
|||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.audio.Music;
|
import com.badlogic.gdx.audio.Music;
|
||||||
import com.badlogic.gdx.files.FileHandle;
|
import com.badlogic.gdx.files.FileHandle;
|
||||||
import com.badlogic.gdx.utils.Disposable;
|
|
||||||
|
|
||||||
import zero1hd.wavedecoder.WavDecoder;
|
import zero1hd.wavedecoder.WavDecoder;
|
||||||
|
|
||||||
public class WavAudioData implements AudioData, Disposable {
|
public class WavAudioData implements AudioData {
|
||||||
private int readWindowSize = 1024;
|
private int readWindowSize = 1024;
|
||||||
private AudioFormat format;
|
private AudioFormat format;
|
||||||
int readIndex;
|
int readIndex;
|
||||||
@ -78,5 +77,6 @@ public class WavAudioData implements AudioData, Disposable {
|
|||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
playbackMusic.dispose();
|
playbackMusic.dispose();
|
||||||
|
decoder.cleanAndClose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -72,6 +72,8 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter, M
|
|||||||
core.setScreen(new MainMenu(core).postTransition());
|
core.setScreen(new MainMenu(core).postTransition());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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.Button;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
import com.badlogic.gdx.scenes.scene2d.ui.Image;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Label;
|
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.Skin;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
import com.badlogic.gdx.scenes.scene2d.ui.Table;
|
||||||
import com.badlogic.gdx.utils.Align;
|
import com.badlogic.gdx.utils.Align;
|
||||||
|
@ -2,7 +2,6 @@ package zero1hd.polyjet.ui.pages;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FilenameFilter;
|
import java.io.FilenameFilter;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@ public class CreativeStage extends Stage implements MiniListener {
|
|||||||
@Override
|
@Override
|
||||||
public void changed(ChangeEvent event, Actor actor) {
|
public void changed(ChangeEvent event, Actor actor) {
|
||||||
dispose();
|
dispose();
|
||||||
|
musicSelector.getSelectedMusic().reset();
|
||||||
core.setScreen(mainMenu);
|
core.setScreen(mainMenu);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -188,6 +189,7 @@ public class CreativeStage extends Stage implements MiniListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
|
musicSelector.getSelectedMusic().dispose();
|
||||||
super.dispose();
|
super.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,11 @@ public class BeatViewer extends Window {
|
|||||||
public void act(float delta) {
|
public void act(float delta) {
|
||||||
if (music != null && data.getBassPeaks().get(songIndex) != 0) {
|
if (music != null && data.getBassPeaks().get(songIndex) != 0) {
|
||||||
clearActions();
|
clearActions();
|
||||||
addAction(Actions.sequence(Actions.sizeTo(getWidth(), (data.getBassPeaks().get(songIndex)/data.getBassMaxValue())*bgBassBar.getHeight()), Actions.sizeTo(getWidth(), 0, 0.3f)));
|
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);
|
super.act(delta);
|
||||||
}
|
}
|
||||||
@ -62,7 +66,11 @@ public class BeatViewer extends Window {
|
|||||||
public void act(float delta) {
|
public void act(float delta) {
|
||||||
if (music != null && data.getUMPeaks().get(songIndex) != 0) {
|
if (music != null && data.getUMPeaks().get(songIndex) != 0) {
|
||||||
clearActions();
|
clearActions();
|
||||||
addAction(Actions.sequence(Actions.sizeTo(getWidth(), (data.getUMPeaks().get(songIndex)/data.getUMMaxValue())*bgUMBar.getHeight()), Actions.sizeTo(getWidth(), 0f, 0.3f)));
|
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);
|
super.act(delta);
|
||||||
}
|
}
|
||||||
|
@ -148,4 +148,11 @@ public class WavDecoder {
|
|||||||
return samplesRead;
|
return samplesRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void cleanAndClose() {
|
||||||
|
try {
|
||||||
|
readStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user