diff --git a/src/itdelatrisu/opsu/audio/HitSound.java b/src/itdelatrisu/opsu/audio/HitSound.java index ed23b8f4..8b7d6f44 100644 --- a/src/itdelatrisu/opsu/audio/HitSound.java +++ b/src/itdelatrisu/opsu/audio/HitSound.java @@ -20,8 +20,6 @@ package itdelatrisu.opsu.audio; import java.util.HashMap; -import javax.sound.sampled.Clip; - /** * Hit sounds. */ diff --git a/src/itdelatrisu/opsu/audio/MultiClip.java b/src/itdelatrisu/opsu/audio/MultiClip.java index 3bdbf8e6..b6375dd2 100644 --- a/src/itdelatrisu/opsu/audio/MultiClip.java +++ b/src/itdelatrisu/opsu/audio/MultiClip.java @@ -1,7 +1,5 @@ package itdelatrisu.opsu.audio; -import itdelatrisu.opsu.ErrorHandler; - import java.io.IOException; import java.util.LinkedList; @@ -21,28 +19,49 @@ public class MultiClip { AudioFormat format; /** The data for this audio sample */ - byte[] buffer; + byte[] audioData; /** The name given to this clip */ String name; - /** Constructor - * @param name - * @throws LineUnavailableException */ + /** Size of a single buffer */ + final int BUFFER_SIZE = 0x1000; + + /** Constructor */ public MultiClip(String name, AudioInputStream audioIn) throws IOException, LineUnavailableException { this.name = name; if(audioIn != null){ - buffer = new byte[audioIn.available()]; - int readed= 0; - while(readed < buffer.length) { - int read = audioIn.read(buffer, readed, buffer.length-readed); - if(read < 0 ) - break; - readed += read; - } format = audioIn.getFormat(); - } else { - System.out.println("Null multiclip"); + + LinkedList allBufs = new LinkedList(); + + int readed = 0; + boolean hasData = true; + while (hasData) { + readed = 0; + byte[] tbuf = new byte[BUFFER_SIZE]; + while (readed < tbuf.length) { + int read = audioIn.read(tbuf, readed, tbuf.length - readed); + if (read < 0) { + hasData = false; + break; + } + readed += read; + } + allBufs.add(tbuf); + } + + audioData = new byte[(allBufs.size() - 1) * BUFFER_SIZE + readed]; + + int cnt = 0; + for (byte[] tbuf : allBufs) { + int size = BUFFER_SIZE; + if (cnt == allBufs.size() - 1) { + size = readed; + } + System.arraycopy(tbuf, 0, audioData, BUFFER_SIZE * cnt, size); + cnt++; + } } getClip(); } @@ -88,7 +107,7 @@ public class MultiClip { } Clip t = AudioSystem.getClip(); if (format != null) - t.open(format, buffer, 0, buffer.length); + t.open(format, audioData, 0, audioData.length); clips.add(t); return t; } diff --git a/src/itdelatrisu/opsu/audio/SoundEffect.java b/src/itdelatrisu/opsu/audio/SoundEffect.java index fd5a78fa..03cabe3d 100644 --- a/src/itdelatrisu/opsu/audio/SoundEffect.java +++ b/src/itdelatrisu/opsu/audio/SoundEffect.java @@ -18,8 +18,6 @@ package itdelatrisu.opsu.audio; -import javax.sound.sampled.Clip; - /** * Sound effects. */