smooth rise of bars
This commit is contained in:
parent
74e3a999c3
commit
99dbbb41f7
@ -21,7 +21,7 @@ import javazoom.jl.decoder.Header;
|
||||
import javazoom.jl.decoder.MP3Decoder;
|
||||
import javazoom.jl.decoder.OutputBuffer;
|
||||
|
||||
public class Mp3AudioData implements MusicManager {
|
||||
public class Mp3Manager implements MusicManager {
|
||||
private int readWindowSize = 1024;
|
||||
|
||||
private int currentReadWindowIndex;
|
||||
@ -39,7 +39,7 @@ public class Mp3AudioData implements MusicManager {
|
||||
private byte[] workset;
|
||||
private int indexHead = -1;
|
||||
|
||||
public Mp3AudioData(FileHandle audioFile) {
|
||||
public Mp3Manager(FileHandle audioFile) {
|
||||
try {
|
||||
MP3File mp3File = new MP3File(audioFile.file());
|
||||
sampleCount = MathUtils.round((float) (mp3File.getAudioHeader().getSampleRateAsNumber()*mp3File.getMP3AudioHeader().getPreciseTrackLength()));
|
@ -27,10 +27,11 @@ public class SongList {
|
||||
}
|
||||
|
||||
public MusicManager getAudioData(FileHandle file) {
|
||||
Gdx.app.debug("SongList", "retrieving proper music manager...");
|
||||
if (file.extension().equalsIgnoreCase("wav")) {
|
||||
return new WavAudioData(file);
|
||||
return new WAVManager(file);
|
||||
} else if (file.extension().equalsIgnoreCase("mp3")) {
|
||||
return new Mp3AudioData(file);
|
||||
return new Mp3Manager(file);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@ -39,6 +40,7 @@ public class SongList {
|
||||
if (index > songList.size) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return getAudioData(songList.get(index));
|
||||
}
|
||||
|
||||
|
@ -30,13 +30,17 @@ public class SongListController implements OnCompletionListener {
|
||||
this.prefs = prefs;
|
||||
listeners = new Array<>();
|
||||
this.songList = songList;
|
||||
changeSong();
|
||||
rand = new Random();
|
||||
}
|
||||
|
||||
public void play() {
|
||||
mdp.play();
|
||||
mdp.setVolume(prefs.getFloat("music vol"));
|
||||
Gdx.app.debug("SongListController", "playing current song.");
|
||||
if (mdp != null) {
|
||||
mdp.play();
|
||||
mdp.setVolume(prefs.getFloat("music vol"));
|
||||
} else {
|
||||
changeSong();
|
||||
}
|
||||
}
|
||||
|
||||
public void setSongByIndex(int index) {
|
||||
@ -56,6 +60,7 @@ public class SongListController implements OnCompletionListener {
|
||||
|
||||
@Override
|
||||
public void onCompletion(Music music) {
|
||||
Gdx.app.debug("SongListController", "Song complete.");
|
||||
if (autoPlay) {
|
||||
if (shuffle) {
|
||||
currentPlaybackID = rand.nextInt(songList.getAmountOfSongs());
|
||||
@ -96,7 +101,7 @@ public class SongListController implements OnCompletionListener {
|
||||
if (mdp != null) {
|
||||
mdp.dispose();
|
||||
}
|
||||
|
||||
Gdx.app.debug("SongListController", "Changing songs...");
|
||||
this.mdp = songList.getMusicInfoFromIndex(currentPlaybackID);
|
||||
if (mdp == null) {
|
||||
mdp = songList.getAudioData(Gdx.files.internal("music/default.mp3"));
|
||||
|
@ -12,7 +12,7 @@ import com.badlogic.gdx.files.FileHandle;
|
||||
|
||||
import zero1hd.rhythmbullet.audio.wavedecoder.WavDecoder;
|
||||
|
||||
public class WavAudioData implements MusicManager {
|
||||
public class WAVManager implements MusicManager {
|
||||
private int readWindowSize = 1024;
|
||||
private AudioFormat format;
|
||||
private int readIndex;
|
||||
@ -20,7 +20,7 @@ public class WavAudioData implements MusicManager {
|
||||
private Music playbackMusic;
|
||||
WavDecoder decoder;
|
||||
|
||||
public WavAudioData(FileHandle file) {
|
||||
public WAVManager(FileHandle file) {
|
||||
try {
|
||||
decoder = new WavDecoder(file);
|
||||
} catch (InvalidParameterException | IOException e) {
|
@ -66,8 +66,6 @@ public class BasicVisualizer extends VisualizerCore {
|
||||
}
|
||||
|
||||
public void modify(float delta) {
|
||||
|
||||
|
||||
//Averaging bins together
|
||||
for (int i = 0; i < barCount; i++) {
|
||||
float barHeight = 2;
|
||||
@ -92,7 +90,7 @@ public class BasicVisualizer extends VisualizerCore {
|
||||
avg /= smoothRange*2;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user