Search in sources :

Example 1 with ALCcontext

use of org.lwjgl.openal.ALCcontext in project jmonkeyengine by jMonkeyEngine.

the class LwjglALC method alcGetString.

public String alcGetString(int parameter) {
    ALCcontext context = ALC10.alcGetCurrentContext();
    ALCdevice device = ALC10.alcGetContextsDevice(context);
    return ALC10.alcGetString(device, parameter);
}
Also used : ALCdevice(org.lwjgl.openal.ALCdevice) ALCcontext(org.lwjgl.openal.ALCcontext)

Example 2 with ALCcontext

use of org.lwjgl.openal.ALCcontext in project jmonkeyengine by jMonkeyEngine.

the class LwjglALC method alcIsExtensionPresent.

public boolean alcIsExtensionPresent(String extension) {
    ALCcontext context = ALC10.alcGetCurrentContext();
    ALCdevice device = ALC10.alcGetContextsDevice(context);
    return ALC10.alcIsExtensionPresent(device, extension);
}
Also used : ALCdevice(org.lwjgl.openal.ALCdevice) ALCcontext(org.lwjgl.openal.ALCcontext)

Example 3 with ALCcontext

use of org.lwjgl.openal.ALCcontext in project jmonkeyengine by jMonkeyEngine.

the class LwjglALC method alcGetInteger.

public void alcGetInteger(int param, IntBuffer buffer, int size) {
    if (buffer.position() != 0)
        throw new AssertionError();
    if (buffer.limit() != size)
        throw new AssertionError();
    ALCcontext context = ALC10.alcGetCurrentContext();
    ALCdevice device = ALC10.alcGetContextsDevice(context);
    ALC10.alcGetInteger(device, param, buffer);
}
Also used : ALCdevice(org.lwjgl.openal.ALCdevice) ALCcontext(org.lwjgl.openal.ALCcontext)

Example 4 with ALCcontext

use of org.lwjgl.openal.ALCcontext in project lwjgl by LWJGL.

the class EFX10Test method silentTests.

/**
     * Runs a series of API calls similar to the tutorials in the Effects Extension Guide of the
     * OpenAL SDK. Nothing is played in this method.
     */
private static void silentTests() throws Exception {
    setupEfx();
    final ALCdevice device = AL.getDevice();
    // Create context (only necessary if LWJGL context isn't sufficient, done as example)
    final IntBuffer contextAttribList = BufferUtils.createIntBuffer(8);
    contextAttribList.put(ALC10.ALC_FREQUENCY);
    contextAttribList.put(44100);
    contextAttribList.put(ALC10.ALC_REFRESH);
    contextAttribList.put(60);
    contextAttribList.put(ALC10.ALC_SYNC);
    contextAttribList.put(ALC10.ALC_FALSE);
    contextAttribList.rewind();
    // ALC_MAX_AUXILIARY_SENDS won't go above compile-time max. Set to compile-time max if
    // greater.
    contextAttribList.put(EFX10.ALC_MAX_AUXILIARY_SENDS);
    contextAttribList.put(2);
    final ALCcontext newContext = ALC10.alcCreateContext(device, contextAttribList);
    if (newContext == null) {
        throw new Exception("Failed to create context.");
    }
    final int contextCurResult = ALC10.alcMakeContextCurrent(newContext);
    if (contextCurResult == ALC10.ALC_FALSE) {
        throw new Exception("Failed to make context current.");
    }
    // Query EFX ALC values
    System.out.println("AL_VERSION: " + AL10.alGetString(AL10.AL_VERSION));
    final IntBuffer buff = BufferUtils.createIntBuffer(1);
    ALC10.alcGetInteger(device, EFX10.ALC_EFX_MAJOR_VERSION, buff);
    System.out.println("ALC_EFX_MAJOR_VERSION: " + buff.get(0));
    ALC10.alcGetInteger(device, EFX10.ALC_EFX_MINOR_VERSION, buff);
    System.out.println("ALC_EFX_MINOR_VERSION: " + buff.get(0));
    ALC10.alcGetInteger(device, EFX10.ALC_MAX_AUXILIARY_SENDS, buff);
    final int maxAuxSends = buff.get(0);
    System.out.println("ALC_MAX_AUXILIARY_SENDS: " + maxAuxSends);
    // Try to create 4 Auxiliary Effect Slots
    int numAuxSlots = 0;
    // try more to test
    final int[] auxEffectSlots = new int[4];
    AL10.alGetError();
    for (numAuxSlots = 0; numAuxSlots < 4; numAuxSlots++) {
        auxEffectSlots[numAuxSlots] = EFX10.alGenAuxiliaryEffectSlots();
        if (AL10.alGetError() != AL10.AL_NO_ERROR) {
            break;
        }
    }
    System.out.println("Created " + numAuxSlots + " aux effect slots.");
    // Try to create 2 Effects
    int numEffects = 0;
    final int[] effects = new int[2];
    for (numEffects = 0; numEffects < 2; numEffects++) {
        effects[numEffects] = EFX10.alGenEffects();
        if (AL10.alGetError() != AL10.AL_NO_ERROR) {
            break;
        }
    }
    System.out.println("Created " + numEffects + " effects.");
    // Set first Effect Type to Reverb and change Decay Time
    AL10.alGetError();
    if (EFX10.alIsEffect(effects[0])) {
        EFX10.alEffecti(effects[0], EFX10.AL_EFFECT_TYPE, EFX10.AL_EFFECT_REVERB);
        if (AL10.alGetError() != AL10.AL_NO_ERROR) {
            System.out.println("Reverb effect not supported.");
        } else {
            EFX10.alEffectf(effects[0], EFX10.AL_REVERB_DECAY_TIME, 5.0f);
            System.out.println("Reverb effect created.");
        }
    } else {
        throw new Exception("First effect not a valid effect.");
    }
    // Set second Effect Type to Flanger and change Phase
    AL10.alGetError();
    if (EFX10.alIsEffect(effects[1])) {
        EFX10.alEffecti(effects[1], EFX10.AL_EFFECT_TYPE, EFX10.AL_EFFECT_FLANGER);
        if (AL10.alGetError() != AL10.AL_NO_ERROR) {
            System.out.println("Flanger effect not support.");
        } else {
            EFX10.alEffecti(effects[1], EFX10.AL_FLANGER_PHASE, 180);
            System.out.println("Flanger effect created.");
        }
    } else {
        throw new Exception("Second effect not a valid effect.");
    }
    // Try to create a Filter
    AL10.alGetError();
    final int filter = EFX10.alGenFilters();
    if (AL10.alGetError() != AL10.AL_NO_ERROR) {
        throw new Exception("Failed to create filter.");
    }
    System.out.println("Generated a filter.");
    if (EFX10.alIsFilter(filter)) {
        // Set Filter type to Low-Pass and set parameters
        EFX10.alFilteri(filter, EFX10.AL_FILTER_TYPE, EFX10.AL_FILTER_LOWPASS);
        if (AL10.alGetError() != AL10.AL_NO_ERROR) {
            System.out.println("Low pass filter not supported.");
        } else {
            EFX10.alFilterf(filter, EFX10.AL_LOWPASS_GAIN, 0.5f);
            EFX10.alFilterf(filter, EFX10.AL_LOWPASS_GAINHF, 0.5f);
            System.out.println("Low pass filter created.");
        }
    }
    // Attach Effect to Auxiliary Effect Slot
    AL10.alGetError();
    EFX10.alAuxiliaryEffectSloti(auxEffectSlots[0], EFX10.AL_EFFECTSLOT_EFFECT, effects[0]);
    if (AL10.alGetError() != AL10.AL_NO_ERROR) {
        throw new Exception("Failed to attach effect to aux effect slot.");
    }
    System.out.println("Successfully loaded effect into effect slot.");
    // Configure Source Auxiliary Effect Slot Sends
    final int source = AL10.alGenSources();
    // Set Source Send 0 to feed auxEffectSlots[0] without filtering
    AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, auxEffectSlots[0], 0, EFX10.AL_FILTER_NULL);
    if (AL10.alGetError() != AL10.AL_NO_ERROR) {
        throw new Exception("Failed to configure Source Send 0");
    }
    System.out.println("Linked aux effect slot to soutce slot 0");
    // Set Source Send 1 to feed uiEffectSlot[1] with filter filter
    AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, auxEffectSlots[1], 1, filter);
    if (AL10.alGetError() != AL10.AL_NO_ERROR) {
        // e.g. if only 1 send per source is available
        throw new Exception("Failed to configure Source Send 1");
    }
    System.out.println("Linked aux effect slot to soutce slot 1");
    // Disable Send 0
    AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, EFX10.AL_EFFECTSLOT_NULL, 0, EFX10.AL_FILTER_NULL);
    if (AL10.alGetError() != AL10.AL_NO_ERROR) {
        throw new Exception("Failed to disable Source Send 0");
    }
    System.out.println("Disabled source send 0");
    // Disable Send 1
    AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, EFX10.AL_EFFECTSLOT_NULL, 1, EFX10.AL_FILTER_NULL);
    if (AL10.alGetError() != AL10.AL_NO_ERROR) {
        throw new Exception("Failed to disable Source Send 1");
    }
    System.out.println("Disabled source send 1");
    // Filter 'source', a generated Source
    AL10.alSourcei(source, EFX10.AL_DIRECT_FILTER, filter);
    if (AL10.alGetError() == AL10.AL_NO_ERROR) {
        {
            System.out.println("Successfully applied a direct path filter");
            // Remove filter from 'source'
            AL10.alSourcei(source, EFX10.AL_DIRECT_FILTER, EFX10.AL_FILTER_NULL);
            if (AL10.alGetError() == AL10.AL_NO_ERROR) {
                System.out.println("Successfully removed direct filter");
            }
        }
        // Filter the Source send 0 from 'source' to Auxiliary Effect Slot auxEffectSlot[0]
        // using Filter uiFilter[0]
        AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, auxEffectSlots[0], 0, filter);
        if (AL10.alGetError() == AL10.AL_NO_ERROR) {
            {
                System.out.println("Successfully applied aux send filter");
                // Remove Filter from Source Auxiliary Send
                AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, auxEffectSlots[0], 0, EFX10.AL_FILTER_NULL);
                if (AL10.alGetError() == AL10.AL_NO_ERROR) {
                    System.out.println("Successfully removed filter");
                }
            }
        }
    }
    // Set Source Cone Outer Gain HF value
    AL10.alSourcef(source, EFX10.AL_CONE_OUTER_GAINHF, 0.5f);
    if (AL10.alGetError() == AL10.AL_NO_ERROR) {
        System.out.println("Successfully set cone outside gain filter");
    }
    // Set distance units to be in feet
    AL10.alListenerf(EFX10.AL_METERS_PER_UNIT, 0.3f);
    if (AL10.alGetError() == AL10.AL_NO_ERROR) {
        System.out.println("Successfully set distance units");
    }
    // Cleanup
    final IntBuffer auxEffectSlotsBuf = (IntBuffer) BufferUtils.createIntBuffer(auxEffectSlots.length).put(auxEffectSlots).rewind();
    EFX10.alDeleteAuxiliaryEffectSlots(auxEffectSlotsBuf);
    final IntBuffer effectsBuf = (IntBuffer) BufferUtils.createIntBuffer(effects.length).put(effects).rewind();
    EFX10.alDeleteEffects(effectsBuf);
    EFX10.alDeleteFilters(filter);
    AL.destroy();
}
Also used : IntBuffer(java.nio.IntBuffer) ALCdevice(org.lwjgl.openal.ALCdevice) ALCcontext(org.lwjgl.openal.ALCcontext)

Aggregations

ALCcontext (org.lwjgl.openal.ALCcontext)4 ALCdevice (org.lwjgl.openal.ALCdevice)4 IntBuffer (java.nio.IntBuffer)1