diff --git a/core/src/zero1hd/rhythmbullet/audio/RhythmBulletAudioThread.java b/core/src/zero1hd/rhythmbullet/audio/RhythmBulletAudioThread.java index fd24013..3d98512 100755 --- a/core/src/zero1hd/rhythmbullet/audio/RhythmBulletAudioThread.java +++ b/core/src/zero1hd/rhythmbullet/audio/RhythmBulletAudioThread.java @@ -5,11 +5,11 @@ import com.badlogic.gdx.audio.AudioDevice; import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.audio.Music.OnCompletionListener; -import zero1hd.rhythmbullet.audio.processor.SampleProcessor; +import zero1hd.rhythmbullet.audio.processor.PCMProcessor; public class RhythmBulletAudioThread extends Thread { private AudioDevice ad; - private SampleProcessor sp; + private PCMProcessor sp; private Music music; private volatile OnCompletionListener ocl; private short[] pcm; @@ -19,7 +19,11 @@ public class RhythmBulletAudioThread extends Thread { public RhythmBulletAudioThread(int windowSize, VisualizableMusic vm) { music = vm; this.sp = vm.getSampleProcessor(); - pcm = new short[sp.getChannels()*windowSize]; + pcm = new short[sp.getChannels()*windowSize*2]; + setName("RhythmBullet-AudioPlayback-Thread"); + play(); + start(); + } @Override diff --git a/core/src/zero1hd/rhythmbullet/audio/VisualizableMusic.java b/core/src/zero1hd/rhythmbullet/audio/VisualizableMusic.java index f1fa4a8..1ca5142 100755 --- a/core/src/zero1hd/rhythmbullet/audio/VisualizableMusic.java +++ b/core/src/zero1hd/rhythmbullet/audio/VisualizableMusic.java @@ -8,9 +8,9 @@ import javax.sound.sampled.UnsupportedAudioFileException; import com.badlogic.gdx.audio.Music; import com.badlogic.gdx.files.FileHandle; -import zero1hd.rhythmbullet.audio.processor.MP3SampleProcessor; -import zero1hd.rhythmbullet.audio.processor.SampleProcessor; -import zero1hd.rhythmbullet.audio.processor.WAVSampleProcessor; +import zero1hd.rhythmbullet.audio.processor.MP3PCMProcessor; +import zero1hd.rhythmbullet.audio.processor.PCMProcessor; +import zero1hd.rhythmbullet.audio.processor.WAVPCMProcessor; public class VisualizableMusic implements Music { private int windowSize = 1024; @@ -18,18 +18,18 @@ public class VisualizableMusic implements Music { private boolean looping; private RhythmBulletAudioThread rat; private File musicFile; - private SampleProcessor sampleProcessor; + private PCMProcessor sampleProcessor; public VisualizableMusic(FileHandle file) { musicFile = file.file(); if (musicFile.getName().toLowerCase().endsWith("wav")) { try { - sampleProcessor = new WAVSampleProcessor(musicFile, windowSize); + sampleProcessor = new WAVPCMProcessor(musicFile, windowSize); } catch (IOException | UnsupportedAudioFileException e) { e.printStackTrace(); } } else if (musicFile.getName().toLowerCase().endsWith("mp3")) { - sampleProcessor = new MP3SampleProcessor(musicFile, windowSize); + sampleProcessor = new MP3PCMProcessor(musicFile, windowSize); } } @@ -37,11 +37,11 @@ public class VisualizableMusic implements Music { public void play() { if (rat == null) { rat = new RhythmBulletAudioThread(windowSize, this); + rat.setOnCompletionListener(ocl); + rat.start(); + } else { + rat.play(); } - - rat.setOnCompletionListener(ocl); - rat.play(); - rat.start(); } @Override @@ -112,7 +112,7 @@ public class VisualizableMusic implements Music { } } - protected SampleProcessor getSampleProcessor() { + protected PCMProcessor getSampleProcessor() { return sampleProcessor; } } diff --git a/core/src/zero1hd/rhythmbullet/audio/processor/MP3SampleProcessor.java b/core/src/zero1hd/rhythmbullet/audio/processor/MP3PCMProcessor.java similarity index 83% rename from core/src/zero1hd/rhythmbullet/audio/processor/MP3SampleProcessor.java rename to core/src/zero1hd/rhythmbullet/audio/processor/MP3PCMProcessor.java index e3d8ceb..6ea65f6 100755 --- a/core/src/zero1hd/rhythmbullet/audio/processor/MP3SampleProcessor.java +++ b/core/src/zero1hd/rhythmbullet/audio/processor/MP3PCMProcessor.java @@ -2,10 +2,10 @@ package zero1hd.rhythmbullet.audio.processor; import java.io.File; -public class MP3SampleProcessor implements SampleProcessor { +public class MP3PCMProcessor implements PCMProcessor { private int channels; - public MP3SampleProcessor(File musicFile, int windowSize) { + public MP3PCMProcessor(File musicFile, int windowSize) { } diff --git a/core/src/zero1hd/rhythmbullet/audio/processor/SampleProcessor.java b/core/src/zero1hd/rhythmbullet/audio/processor/PCMProcessor.java similarity index 92% rename from core/src/zero1hd/rhythmbullet/audio/processor/SampleProcessor.java rename to core/src/zero1hd/rhythmbullet/audio/processor/PCMProcessor.java index 983d90d..d0e3a3d 100755 --- a/core/src/zero1hd/rhythmbullet/audio/processor/SampleProcessor.java +++ b/core/src/zero1hd/rhythmbullet/audio/processor/PCMProcessor.java @@ -2,7 +2,7 @@ package zero1hd.rhythmbullet.audio.processor; import com.badlogic.gdx.utils.Disposable; -public interface SampleProcessor extends Disposable { +public interface PCMProcessor extends Disposable { /** * Called once, contains the initiation to the stream, only called when play-back begins. diff --git a/core/src/zero1hd/rhythmbullet/audio/processor/WAVSampleProcessor.java b/core/src/zero1hd/rhythmbullet/audio/processor/WAVPCMProcessor.java similarity index 93% rename from core/src/zero1hd/rhythmbullet/audio/processor/WAVSampleProcessor.java rename to core/src/zero1hd/rhythmbullet/audio/processor/WAVPCMProcessor.java index 2c92ae4..4e6673d 100755 --- a/core/src/zero1hd/rhythmbullet/audio/processor/WAVSampleProcessor.java +++ b/core/src/zero1hd/rhythmbullet/audio/processor/WAVPCMProcessor.java @@ -8,7 +8,7 @@ import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.UnsupportedAudioFileException; -public class WAVSampleProcessor implements SampleProcessor { +public class WAVPCMProcessor implements PCMProcessor { private int channels; private int sampleRate; private byte[] buffer; @@ -17,7 +17,7 @@ public class WAVSampleProcessor implements SampleProcessor { private volatile float volume, pan; private volatile boolean initiated; - public WAVSampleProcessor(File musicFile, int windowSize) throws IOException, UnsupportedAudioFileException { + public WAVPCMProcessor(File musicFile, int windowSize) throws IOException, UnsupportedAudioFileException { this.file = musicFile; AudioFormat format = AudioSystem.getAudioFileFormat(file).getFormat(); channels = format.getChannels();