Java 类org.lwjgl.openal.ALC 实例源码

项目:LD38    文件:Mixer.java   
private void initialize(){
    device = alcOpenDevice((ByteBuffer)null);
    if(device == 0L){
        Application.error("Unable to open default audio device");
        return;
    }

    ALCCapabilities deviceCaps = ALC.createCapabilities(device);

    if(!deviceCaps.OpenALC10){
        Application.error("OpenALC10 Unsupported");
        return;
    }


    context = alcCreateContext(device, (IntBuffer)null);
    if(context == 0L){
        Application.error("Unable to create ALC Context");
        return;
    }

    ALC10.alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
项目:EmergencyLanding    文件:SoundPlayer.java   
public SoundPlayer() {
    this.device = ALC10.alcOpenDevice((ByteBuffer) null);
    if (this.device == 0) {
        throw new IllegalStateException("Failed to open the default device.");
    }
    this.context = ALC10.alcCreateContext(this.device, (IntBuffer) null);
    if (this.context == 0) {
        throw new IllegalStateException("no context?");
    }
    ALC10.alcMakeContextCurrent(this.context);
    ALCCapabilities deviceCaps = ALC.createCapabilities(this.device);
    AL.createCapabilities(deviceCaps);
    String deviceSpecifier = ALC10.alcGetString(this.device, ALC10.ALC_DEVICE_SPECIFIER);
    System.err.println("Using device " + deviceSpecifier);
    System.out.println("ALC_FREQUENCY: " + alcGetInteger(this.device, ALC_FREQUENCY) + "Hz");
    System.out.println("ALC_REFRESH: " + alcGetInteger(this.device, ALC_REFRESH) + "Hz");
    System.out.println("ALC_SYNC: " + (alcGetInteger(this.device, ALC_SYNC) == ALC_TRUE));
    System.out.println("ALC_MONO_SOURCES: " + alcGetInteger(this.device, ALC_MONO_SOURCES));
    System.out.println("ALC_STEREO_SOURCES: " + alcGetInteger(this.device, ALC_STEREO_SOURCES));
}
项目:SteamAudio-Java    文件:SoundManager.java   
public void init() throws Exception {
    this.device = alcOpenDevice((ByteBuffer) null);
    if (device == NULL) {
        throw new IllegalStateException("Failed to open the default OpenAL device.");
    }
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    this.context = alcCreateContext(device, (IntBuffer) null);
    if (context == NULL) {
        throw new IllegalStateException("Failed to create OpenAL context.");
    }
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
项目:gl3DGE    文件:AudioEngine.java   
public static void initAudioEngine(){
    device = ALC10.alcOpenDevice((ByteBuffer) null);
    if (device == NULL)
        throw new IllegalStateException("Failed to open default audio device");

    deviceCaps = ALC.createCapabilities(device);
    if (!deviceCaps.OpenALC10)
        throw new IllegalStateException("Device is not OpenALC10 capable.");

    System.out.println("OpenALC10: " + deviceCaps.OpenALC10);
    System.out.println("OpenALC11: " + deviceCaps.OpenALC11);
    System.out.println("caps.ALC_EXT_EFX = " + deviceCaps.ALC_EXT_EFX);

    if (deviceCaps.OpenALC11){
        List<String> devices = ALUtil.getStringList(NULL, ALC_ALL_DEVICES_SPECIFIER);
        if (devices == null)
            System.err.println("Whoops, something went wrong with the audio device."); //more specific error
        else {
            for (int i = 0; i < devices.size(); i++)
                System.out.println(i + ": " + devices.get(i));
        }
    }

    String defaultDeviceSpecifier = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
    if (defaultDeviceSpecifier == null)
        System.err.println("Whoops, something went wrong with the audio device."); //more specific error
    System.out.println("Default audio device: " + defaultDeviceSpecifier);

    context = alcCreateContext(device, (IntBuffer) null);
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);

    System.out.println("ALC_FREQUENCY: " + alcGetInteger(device, ALC_FREQUENCY) + "Hz");
    System.out.println("ALC_REFRESH: " + alcGetInteger(device, ALC_REFRESH) + "Hz");
    System.out.println("ALC_SYNC: " + (alcGetInteger(device, ALC_SYNC) == ALC_TRUE));
    System.out.println("ALC_MONO_SOURCES: " + alcGetInteger(device, ALC_MONO_SOURCES));
    System.out.println("ALC_STEREO_SOURCES: " + alcGetInteger(device, ALC_STEREO_SOURCES));
}
项目:ubercube    文件:AudioSystem.java   
public static void init()
{
    mainGain = 0.05f;

    device = alcOpenDevice((ByteBuffer)null);
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);

    context = alcCreateContext(device, (IntBuffer)null);
    alcMakeContextCurrent(context);
    createCapabilities(deviceCaps);

    audioPlayers = new ArrayList<>();

    alDistanceModel(AL_LINEAR_DISTANCE_CLAMPED);
}
项目:ubercube    文件:AudioSystem.java   
public static void destroy()
   {
       for (int i = 0; i < audioPlayers.size(); i++)
       {
           audioPlayers.get(i).destroy();
       }
       audioPlayers.clear();

       alcCloseDevice(device);
       alcDestroyContext(context);
    ALC.destroy();
}
项目:lwjglbook    文件:SoundManager.java   
public void init() throws Exception {
    this.device = alcOpenDevice((ByteBuffer) null);
    if (device == NULL) {
        throw new IllegalStateException("Failed to open the default OpenAL device.");
    }
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    this.context = alcCreateContext(device, (IntBuffer) null);
    if (context == NULL) {
        throw new IllegalStateException("Failed to create OpenAL context.");
    }
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
项目:lwjglbook    文件:SoundManager.java   
public void init() throws Exception {
    this.device = alcOpenDevice((ByteBuffer) null);
    if (device == NULL) {
        throw new IllegalStateException("Failed to open the default OpenAL device.");
    }
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    this.context = alcCreateContext(device, (IntBuffer) null);
    if (context == NULL) {
        throw new IllegalStateException("Failed to create OpenAL context.");
    }
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
项目:lwjglbook    文件:SoundManager.java   
public void init() throws Exception {
    this.device = alcOpenDevice((ByteBuffer) null);
    if (device == NULL) {
        throw new IllegalStateException("Failed to open the default OpenAL device.");
    }
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    this.context = alcCreateContext(device, (IntBuffer) null);
    if (context == NULL) {
        throw new IllegalStateException("Failed to create OpenAL context.");
    }
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
项目:lwjglbook    文件:SoundManager.java   
public void init() throws Exception {
    this.device = alcOpenDevice((ByteBuffer) null);
    if (device == NULL) {
        throw new IllegalStateException("Failed to open the default OpenAL device.");
    }
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    this.context = alcCreateContext(device, (IntBuffer) null);
    if (context == NULL) {
        throw new IllegalStateException("Failed to create OpenAL context.");
    }
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
项目:lwjglbook    文件:SoundManager.java   
public void init() throws Exception {
    this.device = alcOpenDevice((ByteBuffer) null);
    if (device == NULL) {
        throw new IllegalStateException("Failed to open the default OpenAL device.");
    }
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    this.context = alcCreateContext(device, (IntBuffer) null);
    if (context == NULL) {
        throw new IllegalStateException("Failed to create OpenAL context.");
    }
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
项目:lwjglbook    文件:SoundManager.java   
public void init() throws Exception {
    this.device = alcOpenDevice((ByteBuffer) null);
    if (device == NULL) {
        throw new IllegalStateException("Failed to open the default OpenAL device.");
    }
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    this.context = alcCreateContext(device, (IntBuffer) null);
    if (context == NULL) {
        throw new IllegalStateException("Failed to create OpenAL context.");
    }
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
项目:lwjglbook    文件:SoundManager.java   
public void init() throws Exception {
    this.device = alcOpenDevice((ByteBuffer) null);
    if (device == NULL) {
        throw new IllegalStateException("Failed to open the default OpenAL device.");
    }
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    this.context = alcCreateContext(device, (IntBuffer) null);
    if (context == NULL) {
        throw new IllegalStateException("Failed to create OpenAL context.");
    }
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
项目:lwjglbook    文件:SoundManager.java   
public void init() throws Exception {
    this.device = alcOpenDevice((ByteBuffer) null);
    if (device == NULL) {
        throw new IllegalStateException("Failed to open the default OpenAL device.");
    }
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    this.context = alcCreateContext(device, (IntBuffer) null);
    if (context == NULL) {
        throw new IllegalStateException("Failed to create OpenAL context.");
    }
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
项目:lwjglbook    文件:SoundManager.java   
public void init() throws Exception {
    this.device = alcOpenDevice((ByteBuffer) null);
    if (device == NULL) {
        throw new IllegalStateException("Failed to open the default OpenAL device.");
    }
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    this.context = alcCreateContext(device, (IntBuffer) null);
    if (context == NULL) {
        throw new IllegalStateException("Failed to create OpenAL context.");
    }
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
项目:lwjglbook    文件:SoundManager.java   
public void init() throws Exception {
    this.device = alcOpenDevice((ByteBuffer) null);
    if (device == NULL) {
        throw new IllegalStateException("Failed to open the default OpenAL device.");
    }
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    this.context = alcCreateContext(device, (IntBuffer) null);
    if (context == NULL) {
        throw new IllegalStateException("Failed to create OpenAL context.");
    }
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);
}
项目:gl3DGE    文件:AudioEngine.java   
public static void initAudioEngine(){
    device = ALC10.alcOpenDevice((ByteBuffer) null);
    if (device == NULL)
        throw new IllegalStateException("Failed to open default audio device");

    deviceCaps = ALC.createCapabilities(device);
    if (!deviceCaps.OpenALC10)
        throw new IllegalStateException("Device is not OpenALC10 capable.");

    System.out.println("OpenALC10: " + deviceCaps.OpenALC10);
    System.out.println("OpenALC11: " + deviceCaps.OpenALC11);
    System.out.println("caps.ALC_EXT_EFX = " + deviceCaps.ALC_EXT_EFX);

    if (deviceCaps.OpenALC11){
        List<String> devices = ALUtil.getStringList(NULL, ALC_ALL_DEVICES_SPECIFIER);
        if (devices == null)
            System.err.println("Whoops, something went wrong with the audio device."); //more specific error
        else {
            for (int i = 0; i < devices.size(); i++)
                System.out.println(i + ": " + devices.get(i));
        }
    }

    String defaultDeviceSpecifier = alcGetString(NULL, ALC_DEFAULT_DEVICE_SPECIFIER);
    if (defaultDeviceSpecifier == null)
        System.err.println("Whoops, something went wrong with the audio device."); //more specific error
    System.out.println("Default audio device: " + defaultDeviceSpecifier);

    context = alcCreateContext(device, (IntBuffer) null);
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);

    System.out.println("ALC_FREQUENCY: " + alcGetInteger(device, ALC_FREQUENCY) + "Hz");
    System.out.println("ALC_REFRESH: " + alcGetInteger(device, ALC_REFRESH) + "Hz");
    System.out.println("ALC_SYNC: " + (alcGetInteger(device, ALC_SYNC) == ALC_TRUE));
    System.out.println("ALC_MONO_SOURCES: " + alcGetInteger(device, ALC_MONO_SOURCES));
    System.out.println("ALC_STEREO_SOURCES: " + alcGetInteger(device, ALC_STEREO_SOURCES));
}
项目:CubeEngine    文件:ALContext.java   
public static ALContext create() {
    ALContext context = new ALContext();
    // AL.createCapabilities(context._device.getID());

    context._device = ALH.alhGetDefaultDevice();
    if (context._device == null) {
        return (null);
    }
    context._id = ALC10.alcCreateContext(context._device.getID(), (IntBuffer) null);
    context._listener = new ALListener();

    context._capac = ALC.createCapabilities(context._device.getID());

    return (context);
}
项目:x00FA9A    文件:x00FA9AClient.java   
public static void run() {
        glEnable(GL_BLEND);
        glEnable(GL_POLYGON_SMOOTH);
        glEnable(GL_LINE_SMOOTH);
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        glClearColor(0.0f, 0.98f, 0.60f, 0.0f);

//        int vertexShader = Resources.getShader("res/shaders/shadow_vertex_shader.glsl", GL_VERTEX_SHADER);
//        int fragmentShader = Resources.getShader("res/shaders/shadow_fragment_shader.glsl", GL_FRAGMENT_SHADER);
//        int program = glCreateProgram();
//        glAttachShader(program, vertexShader);
//        glAttachShader(program, fragmentShader);
//        glLinkProgram(program);
//        glValidateProgram(program);
//        int status = glGetProgrami(program, GL_LINK_STATUS);
//        System.out.println(status == GL_TRUE);
//        glUseProgram(program);

        float lastUpdateTime = (float)glfwGetTime();
        while(glfwWindowShouldClose(window) == GL_FALSE) {
            tick((float)glfwGetTime() - lastUpdateTime);
            draw();
            lastUpdateTime = (float)glfwGetTime();
        }
        glDisable(GL_LINE_SMOOTH);
        glDisable(GL_POLYGON_SMOOTH);
        glDisable(GL_BLEND);
        glfwDestroyWindow(window);
        glfwTerminate();
        context.destroy();
        ALC.destroy();
    }
项目:SilenceEngine    文件:LwjglAudioDevice.java   
LwjglAudioDevice()
{
    device = alcOpenDevice((ByteBuffer) null);
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);

    context = alcCreateContext(device, (IntBuffer) null);
    alcMakeContextCurrent(context);
    AL.createCapabilities(deviceCaps);

    SilenceEngine.eventManager.addDisposeHandler(this::cleanUp);
}
项目:JAwesomeEngine    文件:ALSoundEnvironment.java   
public ALSoundEnvironment() {
    device = alcOpenDevice((ByteBuffer) null);
    ALCCapabilities deviceCaps = ALC.createCapabilities(device);
    context = alcCreateContext(device, (int[]) null);

    if (!alcMakeContextCurrent(context)) {
        System.err.println("Failed to make context current.");
    }
    AL.createCapabilities(deviceCaps);

    setDistanceModel(DistanceModel.InverseDistance);
}
项目:Null-Engine    文件:Test.java   
public static void main(String[] args) {
    System.setProperty("org.lwjgl.librarypath", new File("natives/windows").getAbsolutePath());
    String deviceName = ALC10.alcGetString(0, ALC10.ALC_DEFAULT_DEVICE_SPECIFIER);
    long device = ALC10.alcOpenDevice(deviceName);
    long context = ALC10.alcCreateContext(device, new int[] {0});
    ALC10.alcMakeContextCurrent(context);
    ALCCapabilities alcCaps = ALC.createCapabilities(device);
    ALCapabilities alCaps = AL.createCapabilities(alcCaps);

    if (alCaps.OpenAL10) {
        String file = "C:\\Users\\Isaac\\Desktop\\workspace\\assets\\audio\\gunshot2.ogg";

        MemoryStack.stackPush();
        IntBuffer channelsBuf = MemoryStack.stackMallocInt(1);
        MemoryStack.stackPush();
        IntBuffer sampleRateBuf = MemoryStack.stackMallocInt(1);

        ShortBuffer audioBuffer = STBVorbis.stb_vorbis_decode_filename(file, channelsBuf, sampleRateBuf);

        int channels = channelsBuf.get();
        int sampleRate = sampleRateBuf.get();

        MemoryStack.stackPop();
        MemoryStack.stackPop();

        int format = -1;
        if (channels == 1) {
            format = AL10.AL_FORMAT_MONO16;
        } else if (channels == 2) {
            format = AL10.AL_FORMAT_STEREO16;
        }

        int buffer = AL10.alGenBuffers();

        AL10.alBufferData(buffer, format, audioBuffer, sampleRate);

        Stdlib.free(audioBuffer);

        int[] sources = new int[4];
        AL10.alGenSources(sources);

        for (int source : sources) {
            AL10.alSourcei(source, AL10.AL_BUFFER, buffer);
            AL10.alSourcei(source, AL10.AL_LOOPING, AL10.AL_TRUE);
        }

        float length = (float) (AL10.alGetBufferi(buffer, AL10.AL_SIZE) / 2 / channels) / sampleRate;

        try {
            AL10.alSourcePlay(sources[0]);
            Thread.sleep((long) (length * 250));
            AL10.alSourcePlay(sources[1]);
            Thread.sleep((long) (length * 250));
            AL10.alSourcePlay(sources[2]);
            Thread.sleep((long) (length * 250));
            AL10.alSourcePlay(sources[3]);
        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {}

        new Scanner(System.in).nextLine();

        AL10.alSourceStopv(sources);
        AL10.alDeleteSources(sources);
        AL10.alDeleteBuffers(buffer);
    }

    ALC10.alcDestroyContext(context);
    ALC10.alcCloseDevice(device);
    ALC.destroy();
}