Search in sources :

Example 1 with WaveData

use of org.lwjgl.util.WaveData in project lwjgl by LWJGL.

the class PlayTest method execute.

/**
     * Runs the actual test, using supplied arguments
     */
protected void execute(String[] args) {
    if (args.length < 1) {
        System.out.println("no argument supplied, assuming Footsteps.wav");
        args = new String[] { "Footsteps.wav" };
    }
    if (args[0].endsWith(".ogg")) {
        System.out.print("Attempting to load Ogg Vorbis file, checking for extension...");
        if (AL10.alIsExtensionPresent("AL_EXT_vorbis")) {
            System.out.println("found");
            usingVorbis = true;
        } else {
            System.out.println("not supported");
            alExit();
            System.exit(-1);
        }
    }
    int lastError;
    //create 1 buffer and 1 source
    IntBuffer buffers = BufferUtils.createIntBuffer(1);
    IntBuffer sources = BufferUtils.createIntBuffer(1);
    // al generate buffers and sources
    buffers.position(0).limit(1);
    AL10.alGenBuffers(buffers);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    sources.position(0).limit(1);
    AL10.alGenSources(sources);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    if (usingVorbis) {
        ByteBuffer filebuffer = getData(args[0]);
        // pass directly to buffer data
        AL10.alBufferData(buffers.get(0), AL10.AL_FORMAT_VORBIS_EXT, filebuffer, -1);
        filebuffer.clear();
    } else {
        // load wave data from buffer
        WaveData wavefile = WaveData.create(args[0]);
        //copy to buffers
        AL10.alBufferData(buffers.get(0), wavefile.format, wavefile.data, wavefile.samplerate);
        //unload file again
        wavefile.dispose();
    }
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    //set up source input
    AL10.alSourcei(sources.get(0), AL10.AL_BUFFER, buffers.get(0));
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    //lets loop the sound
    AL10.alSourcei(sources.get(0), AL10.AL_LOOPING, AL10.AL_TRUE);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    //play source 0
    AL10.alSourcePlay(sources.get(0));
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    //wait 5 secs
    try {
        System.out.println("Waiting 5 seconds for sound to complete");
        Thread.sleep(5000);
    } catch (InterruptedException inte) {
    }
    //stop source 0
    AL10.alSourceStop(sources.get(0));
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    //delete buffers and sources
    sources.position(0).limit(1);
    AL10.alDeleteSources(sources);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    buffers.position(0).limit(1);
    AL10.alDeleteBuffers(buffers);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    //no errorchecking from now on, since our context is gone.
    //shutdown
    alExit();
}
Also used : IntBuffer(java.nio.IntBuffer) ByteBuffer(java.nio.ByteBuffer) WaveData(org.lwjgl.util.WaveData)

Example 2 with WaveData

use of org.lwjgl.util.WaveData in project lwjgl by LWJGL.

the class PositionTest method setup.

/**
   * Performs setup of demonstration
   */
private void setup() throws Exception {
    // Setup Window
    // =====================================================
    LWJGLUtil.log("Setting up window");
    // calc center
    int centerX = (Display.getDisplayMode().getWidth() - WINDOW_WIDTH) / 2;
    int centerY = (Display.getDisplayMode().getHeight() - WINDOW_HEIGHT) / 2;
    // setup window
    setDisplayMode();
    Display.create();
    // -----------------------------------------------------
    // Setup OpenGL
    // =====================================================
    LWJGLUtil.log("Setting up OpenGL");
    glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(50.0f, (float) WINDOW_WIDTH / WINDOW_HEIGHT, 0.0f, 50.0f);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glTranslatef(0.0f, 0.0f, -6.6f);
    glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
    glut = this.new GLUT();
    Display.setVSyncEnabled(true);
    // -----------------------------------------------------
    // Setup OpenAL
    // =====================================================
    LWJGLUtil.log("Setting up OpenAL");
    alListener(AL_POSITION, listenerPosition);
    alListener(AL_VELOCITY, listenerVelocity);
    alListener(AL_ORIENTATION, listenerOrientation);
    // creating buffers
    LWJGLUtil.log("Creating buffers");
    alGenBuffers(soundBuffers);
    soundBuffers.rewind();
    // creating sources
    alGenSources(soundSources);
    soundSources.rewind();
    // load sound files (left, center, right).wav
    LWJGLUtil.log("Loading soundfiles...");
    LWJGLUtil.log("Loading left.wav");
    WaveData left = WaveData.create("left.wav");
    alBufferData(soundBuffers.get(LEFT), left.format, left.data, left.samplerate);
    alSourcef(soundSources.get(LEFT), AL_PITCH, 1.0f);
    alSourcef(soundSources.get(LEFT), AL_GAIN, 1.0f);
    alSource(soundSources.get(LEFT), AL_POSITION, leftPosition);
    alSource(soundSources.get(LEFT), AL_VELOCITY, leftVelocity);
    alSourcei(soundSources.get(LEFT), AL_BUFFER, soundBuffers.get(LEFT));
    alSourcei(soundSources.get(LEFT), AL_LOOPING, AL_TRUE);
    LWJGLUtil.log("Loading center.wav");
    WaveData center = WaveData.create("center.wav");
    alBufferData(soundBuffers.get(CENTER), center.format, center.data, center.samplerate);
    alSourcef(soundSources.get(CENTER), AL_PITCH, 1.0f);
    alSourcef(soundSources.get(CENTER), AL_GAIN, 1.0f);
    alSource(soundSources.get(CENTER), AL_POSITION, centerPosition);
    alSource(soundSources.get(CENTER), AL_VELOCITY, centerVelocity);
    alSourcei(soundSources.get(CENTER), AL_BUFFER, soundBuffers.get(CENTER));
    alSourcei(soundSources.get(CENTER), AL_LOOPING, AL_TRUE);
    LWJGLUtil.log("Loading right.wav");
    WaveData right = WaveData.create("right.wav");
    alBufferData(soundBuffers.get(RIGHT), right.format, right.data, right.samplerate);
    alSourcef(soundSources.get(RIGHT), AL_PITCH, 1.0f);
    alSourcef(soundSources.get(RIGHT), AL_GAIN, 1.0f);
    alSource(soundSources.get(RIGHT), AL_POSITION, rightPosition);
    alSource(soundSources.get(RIGHT), AL_VELOCITY, rightVelocity);
    alSourcei(soundSources.get(RIGHT), AL_BUFFER, soundBuffers.get(RIGHT));
    alSourcei(soundSources.get(RIGHT), AL_LOOPING, AL_TRUE);
    LWJGLUtil.log("Soundfiles loaded successfully");
    // -----------------------------------------------------
    Mouse.setGrabbed(true);
}
Also used : WaveData(org.lwjgl.util.WaveData)

Example 3 with WaveData

use of org.lwjgl.util.WaveData in project lwjgl by LWJGL.

the class EFX10Test method playbackTest.

/**
     * Plays a sound with various effects applied to it.
     */
private static void playbackTest() throws Exception {
    setupEfx();
    // Create a source and buffer audio data
    final int source = AL10.alGenSources();
    final int buffer = AL10.alGenBuffers();
    WaveData waveFile = WaveData.create("Footsteps.wav");
    if (waveFile == null) {
        System.out.println("Failed to load Footsteps.wav! Skipping playback test.");
        AL.destroy();
        return;
    }
    AL10.alBufferData(buffer, waveFile.format, waveFile.data, waveFile.samplerate);
    waveFile.dispose();
    AL10.alSourcei(source, AL10.AL_BUFFER, buffer);
    AL10.alSourcei(source, AL10.AL_LOOPING, AL10.AL_TRUE);
    System.out.println("Playing sound unaffected by EFX ...");
    AL10.alSourcePlay(source);
    Thread.sleep(7500);
    // Add reverb effect
    final int effectSlot = EFX10.alGenAuxiliaryEffectSlots();
    final int reverbEffect = EFX10.alGenEffects();
    EFX10.alEffecti(reverbEffect, EFX10.AL_EFFECT_TYPE, EFX10.AL_EFFECT_REVERB);
    EFX10.alEffectf(reverbEffect, EFX10.AL_REVERB_DECAY_TIME, 5.0f);
    EFX10.alAuxiliaryEffectSloti(effectSlot, EFX10.AL_EFFECTSLOT_EFFECT, reverbEffect);
    AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, effectSlot, 0, EFX10.AL_FILTER_NULL);
    System.out.println("Playing sound with reverb ...");
    AL10.alSourcePlay(source);
    Thread.sleep(7500);
    // Add low-pass filter directly to source
    final int filter = EFX10.alGenFilters();
    EFX10.alFilteri(filter, EFX10.AL_FILTER_TYPE, EFX10.AL_FILTER_LOWPASS);
    EFX10.alFilterf(filter, EFX10.AL_LOWPASS_GAIN, 0.5f);
    EFX10.alFilterf(filter, EFX10.AL_LOWPASS_GAINHF, 0.5f);
    AL10.alSourcei(source, EFX10.AL_DIRECT_FILTER, filter);
    System.out.println("Playing sound with reverb and direct low pass filter ...");
    AL10.alSourcePlay(source);
    Thread.sleep(7500);
    AL10.alSourcei(source, EFX10.AL_DIRECT_FILTER, EFX10.AL_FILTER_NULL);
    // Add low-pass filter to source send
    //AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, effectSlot, 0, filter);
    //
    //System.out.println("Playing sound with reverb and aux send low pass filter ...");
    //AL10.alSourcePlay(source);
    //Thread.sleep(7500);
    // Cleanup
    AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, EFX10.AL_EFFECTSLOT_NULL, 0, EFX10.AL_FILTER_NULL);
    EFX10.alAuxiliaryEffectSloti(effectSlot, EFX10.AL_EFFECTSLOT_EFFECT, EFX10.AL_EFFECT_NULL);
    EFX10.alDeleteEffects(reverbEffect);
    EFX10.alDeleteFilters(filter);
    // Echo effect
    final int echoEffect = EFX10.alGenEffects();
    EFX10.alEffecti(echoEffect, EFX10.AL_EFFECT_TYPE, EFX10.AL_EFFECT_ECHO);
    //EFX10.alEffectf(echoEffect, EFX10.AL_ECHO_DELAY, 5.0f);
    EFX10.alAuxiliaryEffectSloti(effectSlot, EFX10.AL_EFFECTSLOT_EFFECT, echoEffect);
    AL11.alSource3i(source, EFX10.AL_AUXILIARY_SEND_FILTER, effectSlot, 0, EFX10.AL_FILTER_NULL);
    System.out.println("Playing sound with echo effect ...");
    AL10.alSourcePlay(source);
    Thread.sleep(7500);
    AL.destroy();
}
Also used : WaveData(org.lwjgl.util.WaveData)

Example 4 with WaveData

use of org.lwjgl.util.WaveData in project lwjgl by LWJGL.

the class OpenALCreationTest method executeAudioTest.

/**
	 * Executes the audio test, which just plays some sound
	 */
private void executeAudioTest() {
    int lastError;
    //create 1 buffer and 1 source
    IntBuffer buffers = createIntBuffer(1);
    IntBuffer sources = createIntBuffer(1);
    // al generate buffers and sources
    buffers.position(0).limit(1);
    AL10.alGenBuffers(buffers);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    sources.position(0).limit(1);
    AL10.alGenSources(sources);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    //load wave data
    WaveData wavefile = WaveData.create("Footsteps.wav");
    //copy to buffers
    AL10.alBufferData(buffers.get(0), wavefile.format, wavefile.data, wavefile.samplerate);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    //unload file again
    wavefile.dispose();
    //set up source input
    AL10.alSourcei(sources.get(0), AL10.AL_BUFFER, buffers.get(0));
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    //lets loop the sound
    AL10.alSourcei(sources.get(0), AL10.AL_LOOPING, AL10.AL_TRUE);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    //play source 0
    AL10.alSourcePlay(sources.get(0));
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    //wait 5 secs
    try {
        System.out.print("Playing 'Footsteps.wav' for 2 seconds...");
        Thread.sleep(2000);
    } catch (InterruptedException inte) {
    }
    System.out.println("done");
    //stop source 0
    AL10.alSourceStop(sources.get(0));
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    //delete buffers and sources
    sources.position(0).limit(1);
    AL10.alDeleteSources(sources);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    buffers.position(0).limit(1);
    AL10.alDeleteBuffers(buffers);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
}
Also used : IntBuffer(java.nio.IntBuffer) WaveData(org.lwjgl.util.WaveData)

Example 5 with WaveData

use of org.lwjgl.util.WaveData in project lwjgl by LWJGL.

the class OpenAL method playOpenAL.

private void playOpenAL() {
    int lastError;
    // al generate buffers and sources
    buffers.position(0).limit(1);
    AL10.alGenBuffers(buffers);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    sources.position(0).limit(1);
    AL10.alGenSources(sources);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    // load wave data from buffer
    WaveData wavefile = WaveData.create(getClass().getClassLoader().getResourceAsStream("Footsteps.wav"));
    //copy to buffers
    AL10.alBufferData(buffers.get(0), wavefile.format, wavefile.data, wavefile.samplerate);
    //unload file again
    wavefile.dispose();
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    //set up source input
    AL10.alSourcei(sources.get(0), AL10.AL_BUFFER, buffers.get(0));
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    //lets loop the sound
    AL10.alSourcei(sources.get(0), AL10.AL_LOOPING, AL10.AL_TRUE);
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
    //play source 0
    AL10.alSourcePlay(sources.get(0));
    if ((lastError = AL10.alGetError()) != AL10.AL_NO_ERROR) {
        exit(lastError);
    }
}
Also used : WaveData(org.lwjgl.util.WaveData)

Aggregations

WaveData (org.lwjgl.util.WaveData)11 IntBuffer (java.nio.IntBuffer)4 ByteBuffer (java.nio.ByteBuffer)2 AudioInputStream (javax.sound.sampled.AudioInputStream)2 LWJGLException (org.lwjgl.LWJGLException)2 File (java.io.File)1 Vector3f (org.lwjgl.util.vector.Vector3f)1