smooth rise of bars

This commit is contained in:
Harrison Deng 2017-10-05 00:33:10 -05:00
parent 74e3a999c3
commit 99dbbb41f7
5 changed files with 18 additions and 13 deletions

View File

@ -21,7 +21,7 @@ import javazoom.jl.decoder.Header;
import javazoom.jl.decoder.MP3Decoder; import javazoom.jl.decoder.MP3Decoder;
import javazoom.jl.decoder.OutputBuffer; import javazoom.jl.decoder.OutputBuffer;
public class Mp3AudioData implements MusicManager { public class Mp3Manager implements MusicManager {
private int readWindowSize = 1024; private int readWindowSize = 1024;
private int currentReadWindowIndex; private int currentReadWindowIndex;
@ -39,7 +39,7 @@ public class Mp3AudioData implements MusicManager {
private byte[] workset; private byte[] workset;
private int indexHead = -1; private int indexHead = -1;
public Mp3AudioData(FileHandle audioFile) { public Mp3Manager(FileHandle audioFile) {
try { try {
MP3File mp3File = new MP3File(audioFile.file()); MP3File mp3File = new MP3File(audioFile.file());
sampleCount = MathUtils.round((float) (mp3File.getAudioHeader().getSampleRateAsNumber()*mp3File.getMP3AudioHeader().getPreciseTrackLength())); sampleCount = MathUtils.round((float) (mp3File.getAudioHeader().getSampleRateAsNumber()*mp3File.getMP3AudioHeader().getPreciseTrackLength()));

View File

@ -27,10 +27,11 @@ public class SongList {
} }
public MusicManager getAudioData(FileHandle file) { public MusicManager getAudioData(FileHandle file) {
Gdx.app.debug("SongList", "retrieving proper music manager...");
if (file.extension().equalsIgnoreCase("wav")) { if (file.extension().equalsIgnoreCase("wav")) {
return new WavAudioData(file); return new WAVManager(file);
} else if (file.extension().equalsIgnoreCase("mp3")) { } else if (file.extension().equalsIgnoreCase("mp3")) {
return new Mp3AudioData(file); return new Mp3Manager(file);
} }
return null; return null;
} }
@ -39,6 +40,7 @@ public class SongList {
if (index > songList.size) { if (index > songList.size) {
return null; return null;
} }
return getAudioData(songList.get(index)); return getAudioData(songList.get(index));
} }

View File

@ -30,13 +30,17 @@ public class SongListController implements OnCompletionListener {
this.prefs = prefs; this.prefs = prefs;
listeners = new Array<>(); listeners = new Array<>();
this.songList = songList; this.songList = songList;
changeSong();
rand = new Random(); rand = new Random();
} }
public void play() { public void play() {
mdp.play(); Gdx.app.debug("SongListController", "playing current song.");
mdp.setVolume(prefs.getFloat("music vol")); if (mdp != null) {
mdp.play();
mdp.setVolume(prefs.getFloat("music vol"));
} else {
changeSong();
}
} }
public void setSongByIndex(int index) { public void setSongByIndex(int index) {
@ -56,6 +60,7 @@ public class SongListController implements OnCompletionListener {
@Override @Override
public void onCompletion(Music music) { public void onCompletion(Music music) {
Gdx.app.debug("SongListController", "Song complete.");
if (autoPlay) { if (autoPlay) {
if (shuffle) { if (shuffle) {
currentPlaybackID = rand.nextInt(songList.getAmountOfSongs()); currentPlaybackID = rand.nextInt(songList.getAmountOfSongs());
@ -96,7 +101,7 @@ public class SongListController implements OnCompletionListener {
if (mdp != null) { if (mdp != null) {
mdp.dispose(); mdp.dispose();
} }
Gdx.app.debug("SongListController", "Changing songs...");
this.mdp = songList.getMusicInfoFromIndex(currentPlaybackID); this.mdp = songList.getMusicInfoFromIndex(currentPlaybackID);
if (mdp == null) { if (mdp == null) {
mdp = songList.getAudioData(Gdx.files.internal("music/default.mp3")); mdp = songList.getAudioData(Gdx.files.internal("music/default.mp3"));

View File

@ -12,7 +12,7 @@ import com.badlogic.gdx.files.FileHandle;
import zero1hd.rhythmbullet.audio.wavedecoder.WavDecoder; import zero1hd.rhythmbullet.audio.wavedecoder.WavDecoder;
public class WavAudioData implements MusicManager { public class WAVManager implements MusicManager {
private int readWindowSize = 1024; private int readWindowSize = 1024;
private AudioFormat format; private AudioFormat format;
private int readIndex; private int readIndex;
@ -20,7 +20,7 @@ public class WavAudioData implements MusicManager {
private Music playbackMusic; private Music playbackMusic;
WavDecoder decoder; WavDecoder decoder;
public WavAudioData(FileHandle file) { public WAVManager(FileHandle file) {
try { try {
decoder = new WavDecoder(file); decoder = new WavDecoder(file);
} catch (InvalidParameterException | IOException e) { } catch (InvalidParameterException | IOException e) {

View File

@ -66,8 +66,6 @@ public class BasicVisualizer extends VisualizerCore {
} }
public void modify(float delta) { public void modify(float delta) {
//Averaging bins together //Averaging bins together
for (int i = 0; i < barCount; i++) { for (int i = 0; i < barCount; i++) {
float barHeight = 2; float barHeight = 2;
@ -92,7 +90,7 @@ public class BasicVisualizer extends VisualizerCore {
avg /= smoothRange*2; avg /= smoothRange*2;
barHeights[i] = avg; barHeights[i] = avg;
bars[i].setSize(barWidth, bars[i].getHeight() <= barHeights[i] ? barHeights[i] : bars[i].getHeight() - 1.1f*Gdx.graphics.getHeight()*delta); bars[i].setSize(barWidth, bars[i].getHeight() <= barHeights[i] ? bars[i].getHeight() + 0.5f*barHeights[i] : bars[i].getHeight() - 0.8f*Gdx.graphics.getHeight()*delta);
} }
} }