diff --git a/build.gradle b/build.gradle index a6a7627..0f26a17 100755 --- a/build.gradle +++ b/build.gradle @@ -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" diff --git a/core/src/zero1hd/polyjet/audio/Mp3AudioData.java b/core/src/zero1hd/polyjet/audio/Mp3AudioData.java index 8951fbc..db01f84 100755 --- a/core/src/zero1hd/polyjet/audio/Mp3AudioData.java +++ b/core/src/zero1hd/polyjet/audio/Mp3AudioData.java @@ -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; @@ -18,40 +21,45 @@ import com.badlogic.gdx.files.FileHandle; public class Mp3AudioData implements AudioData { private int readWindowSize = 1024; - - private AudioInputStream audStream; - private AudioInputStream faudStream; - - private AudioFormat audioFormat; + + private AudioInputStream din; + + 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(); } catch (IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e1) { e1.printStackTrace(); } - + 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; diff --git a/core/src/zero1hd/polyjet/screens/PreGameScreen.java b/core/src/zero1hd/polyjet/screens/PreGameScreen.java index cd5eaca..153361e 100755 --- a/core/src/zero1hd/polyjet/screens/PreGameScreen.java +++ b/core/src/zero1hd/polyjet/screens/PreGameScreen.java @@ -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);