summaryrefslogtreecommitdiff
path: root/src/main/java/net/tylermurphy/Minecraft/Audio/SoundManager.java
blob: 10b7d6dbbff3cc7f0f96b02742d68ad0450f83df (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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);
	}
}