Refactored (name change); minor data logic improvement; structure
change;
This commit is contained in:
parent
55cac998ed
commit
0f296bfe1c
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
|
||||
}
|
||||
|
@ -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.
|
@ -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();
|
Loading…
Reference in New Issue
Block a user