circle now spins left on preGameScreen.java

This commit is contained in:
Harrison Deng 2017-05-16 17:28:16 -05:00
parent 27f2e51613
commit 1be8e0cc9d
3 changed files with 52 additions and 34 deletions

View File

@ -42,7 +42,7 @@ project(":desktop") {
compile "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
compile "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
compile "com.googlecode.soundlibs:mp3spi:1.9.5-1"
compile group: 'com.googlecode.soundlibs', name: 'mp3spi', version: '1.9.5-1'
compile "org.apache.commons:commons-math3:3.2"
@ -72,7 +72,7 @@ project(":android") {
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86"
natives "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-x86_64"
compile "com.googlecode.soundlibs:mp3spi:1.9.5-1"
compile group: 'com.googlecode.soundlibs', name: 'mp3spi', version: '1.9.5-1'
compile "org.apache.commons:commons-math3:3.2"
@ -90,7 +90,7 @@ project(":core") {
compile "com.badlogicgames.gdx:gdx:$gdxVersion"
compile "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
compile "com.googlecode.soundlibs:mp3spi:1.9.5-1"
compile group: 'com.googlecode.soundlibs', name: 'mp3spi', version: '1.9.5-1'
compile "org.apache.commons:commons-math3:3.2"

View File

@ -1,6 +1,9 @@
package zero1hd.polyjet.audio;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import javax.sound.sampled.AudioFormat;
import javax.sound.sampled.AudioInputStream;
@ -19,14 +22,16 @@ import com.badlogic.gdx.files.FileHandle;
public class Mp3AudioData implements AudioData {
private int readWindowSize = 1024;
private AudioInputStream audStream;
private AudioInputStream faudStream;
private AudioInputStream din;
private AudioFormat audioFormat;
private AudioFormat decodedFormat;
private Music playbackMusic;
private int readIndex;
private int sampleCount;
private AudioInputStream in;
public Mp3AudioData(FileHandle audioFile) {
try {
sampleCount = (int) new MP3File(audioFile.file()).getMP3AudioHeader().getNumberOfFrames();
@ -35,23 +40,26 @@ public class Mp3AudioData implements AudioData {
}
reset();
try {
audStream = AudioSystem.getAudioInputStream(audioFile.file());
AudioFormat bFormat = audStream.getFormat();
audioFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, bFormat.getSampleRate(), 16, bFormat.getChannels(), bFormat.getChannels()*2, bFormat.getSampleRate(), false);
faudStream = AudioSystem.getAudioInputStream(audioFormat, audStream);
File file = audioFile.file();
in = AudioSystem.getAudioInputStream(file);
din = null;
AudioFormat baseFormat = in.getFormat();
decodedFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, baseFormat.getSampleRate(), 16,
baseFormat.getChannels(), baseFormat.getChannels() * 2, baseFormat.getSampleRate(), false);
din = AudioSystem.getAudioInputStream(decodedFormat, in);
} catch (UnsupportedAudioFileException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
playbackMusic = Gdx.audio.newMusic(audioFile);
}
@Override
public void readIndexUpdate() {
readIndex = (int) (playbackMusic.getPosition() * audioFormat.getSampleRate() / readWindowSize);
readIndex = (int) (playbackMusic.getPosition() * decodedFormat.getSampleRate() / readWindowSize);
}
@Override
@ -67,10 +75,10 @@ public class Mp3AudioData implements AudioData {
playbackMusic = null;
}
if (audStream != null) {
if (din != null) {
try {
audStream.close();
faudStream.close();
din.close();
in.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@ -88,15 +96,27 @@ public class Mp3AudioData implements AudioData {
return playbackMusic;
}
byte[] toBeConverted = new byte[2];
@Override
public int readSamples(float[] samples) {
int samplesRead = 0;
int sampleAverage = 0;
short sampleAverage = 0;
for (int currentSample = 0; currentSample < samples.length; currentSample++) {
for (int channel = 0; channel < audioFormat.getChannels(); channel++) {
for (int channel = 0; channel < decodedFormat.getChannels(); channel++) {
try {
sampleAverage += audStream.read();
if (sampleAverage == -1) {
int readCount = din.read(toBeConverted, 0, toBeConverted.length);
ByteBuffer bBuffer = ByteBuffer.allocate(2);
bBuffer.order(ByteOrder.LITTLE_ENDIAN);
bBuffer.put(toBeConverted[0]);
bBuffer.put(toBeConverted[1]);
sampleAverage += bBuffer.getShort(0);
if (readCount == -1) {
break;
}
} catch (IOException e) {
@ -104,22 +124,20 @@ public class Mp3AudioData implements AudioData {
e.printStackTrace();
}
}
sampleAverage /= audioFormat.getChannels()*Short.MAX_VALUE+1;
sampleAverage /= decodedFormat.getChannels() * Short.MAX_VALUE + 1;
samples[currentSample] = sampleAverage;
sampleAverage = 0;
samplesRead++;
if (sampleAverage == -1) {
break;
}
}
return samplesRead;
}
@Override
public AudioFormat getFormat() {
return audioFormat;
return decodedFormat;
}
@Override
public int getSampleCount() {
return sampleCount;

View File

@ -52,10 +52,10 @@ public class PreGameScreen extends ScreenAdapter implements TransitionAdapter {
stage.clear();
Image cyberCircle1 = new Image(core.getAssetManager().get("cybercircle3B.png", Texture.class));
cyberCircle1.setScale(0.7f);
cyberCircle1.setScale(0.8f);
cyberCircle1.setOrigin(cyberCircle1.getWidth()/2, cyberCircle1.getHeight()/2);
cyberCircle1.setColor(0.8f,0.8f,0.8f,0.7f);
cyberCircle1.addAction(Actions.forever(Actions.rotateBy(-360f, 10f)));
cyberCircle1.addAction(Actions.forever(Actions.rotateBy(360f, 10f)));
cyberCircle1.setPosition(Gdx.graphics.getWidth()-cyberCircle1.getWidth()/2-10, -cyberCircle1.getHeight()*2/4f);
stage.addActor(cyberCircle1);