Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
valoeghese committed Nov 13, 2020
2 parents d42f50b + 2c52d6f commit 3ce0f9b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 25 deletions.
4 changes: 1 addition & 3 deletions src/main/java/valoeghese/scalpel/util/ALUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import org.lwjgl.openal.AL;
import org.lwjgl.openal.AL10;
import org.lwjgl.openal.ALC;
import org.lwjgl.openal.ALCCapabilities;
import org.lwjgl.stb.STBVorbis;
import org.lwjgl.stb.STBVorbisInfo;
import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.MemoryUtil;
Expand Down Expand Up @@ -59,7 +57,7 @@ public static AudioBuffer createBuffer(String fileName) throws IOException { //
final int bufferSize = 32 * 1024;

try (MemoryStack stack = MemoryStack.stackPush()) {
ByteBuffer vorbis = ResourceLoader.loadAsByteBufferAL(fileName, bufferSize);
ByteBuffer vorbis = ResourceLoader.loadAsByteBuffer(fileName, bufferSize);
IntBuffer error = stack.mallocInt(1);
long decoder = stb_vorbis_open_memory(vorbis, error, null);

Expand Down
23 changes: 1 addition & 22 deletions src/main/java/valoeghese/scalpel/util/ResourceLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,22 +40,7 @@ public static String loadAsString(String location) throws IOException {
return new String(buffer.toByteArray(), StandardCharsets.UTF_8);
}

public static ByteBuffer loadAsByteBuffer(String location) throws IOException {
InputStream is = load(location);
ByteBufferOutputStream buffer = new ByteBufferOutputStream();

int nBytesRead;
byte[] bufferBuffer = new byte[0x4000];

while ((nBytesRead = is.read(bufferBuffer, 0, bufferBuffer.length)) != -1) {
buffer.write(bufferBuffer, 0, nBytesRead);
}

is.close();
return buffer.toByteBuffer();
}

public static ByteBuffer loadAsByteBufferAL(String resource, int bufferSize) throws IOException { // https://www.youtube.com/watch?v=Mrcs9vIHSws
public static ByteBuffer loadAsByteBuffer(String resource, int bufferSize) throws IOException { // https://www.youtube.com/watch?v=Mrcs9vIHSws
ByteBuffer buffer;
Path path = Paths.get(resource);

Expand Down Expand Up @@ -90,10 +75,4 @@ public static ByteBuffer loadAsByteBufferAL(String resource, int bufferSize) thr
buffer.flip();
return buffer;
}

public static class ByteBufferOutputStream extends ByteArrayOutputStream {
public ByteBuffer toByteBuffer() {
return ByteBuffer.wrap(this.buf);
}
}
}

0 comments on commit 3ce0f9b

Please sign in to comment.