summaryrefslogtreecommitdiff
path: root/src/main/java/net/tylermurphy/Minecraft/Audio/SoundManager.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/net/tylermurphy/Minecraft/Audio/SoundManager.java')
-rwxr-xr-xsrc/main/java/net/tylermurphy/Minecraft/Audio/SoundManager.java45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/main/java/net/tylermurphy/Minecraft/Audio/SoundManager.java b/src/main/java/net/tylermurphy/Minecraft/Audio/SoundManager.java
new file mode 100755
index 0000000..10b7d6d
--- /dev/null
+++ b/src/main/java/net/tylermurphy/Minecraft/Audio/SoundManager.java
@@ -0,0 +1,45 @@
+package net.tylermurphy.Minecraft.Audio;
+
+import java.util.ArrayList;
+
+import java.util.List;
+
+import org.lwjgl.openal.*;
+
+public class SoundManager {
+
+ private static long device;
+ private static long context;
+ private static List<Sound> sounds;
+
+ public static void init() {
+ String defaultDeviceName = ALC10.alcGetString(0, ALC10.ALC_DEFAULT_DEVICE_SPECIFIER);
+ device = ALC10.alcOpenDevice(defaultDeviceName);
+ int[] attributes = {0};
+ context = ALC10.alcCreateContext(device, attributes);
+ ALC10.alcMakeContextCurrent(context);
+ ALCCapabilities alcCapabilities = ALC.createCapabilities(device);
+ AL.createCapabilities(alcCapabilities);
+ sounds = new ArrayList<>();
+ AL11.alDistanceModel(AL11.AL_LINEAR_DISTANCE_CLAMPED);
+ }
+
+ public static Sound loadSound(String fileName) {
+ Sound sound = new Sound(fileName);
+ sounds.add(sound);
+ return sound;
+ }
+
+ public static void cleanUp() {
+ for(Sound sound : sounds) {
+ sound.cleanUp();
+ }
+ ALC10.alcDestroyContext(context);
+ ALC10.alcCloseDevice(device);
+ }
+
+ public static void setListenerData(float x, float y, float z) {
+ AL10.alListener3f(AL10.AL_POSITION, x, y, z);
+ AL10.alListener3f(AL10.AL_VELOCITY, 0, 0, 0);
+ }
+} \ No newline at end of file