Search in sources :

Example 6 with WaveData

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

the class StressTest method loadSamples.

private void loadSamples() throws Exception {
    AL10.alGetError();
    WaveData data = WaveData.create("ding.wav");
    for (int i = 1; i <= 10; i++) {
        AL10.alBufferData(buffers.get(i - 1), data.format, data.data, data.samplerate);
        if (AL10.alGetError() != AL10.AL_NO_ERROR) {
            System.out.println("Failed to load " + i + ".wav into buffer");
            sources.position(0).limit(4);
            AL10.alDeleteSources(sources);
            buffers.position(0).limit(10);
            AL10.alDeleteBuffers(buffers);
            alExit();
        }
    }
    data.dispose();
}
Also used : WaveData(org.lwjgl.util.WaveData)

Example 7 with WaveData

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

the class SoundManager method addSound.

/**
   * Adds a sound to the Sound Managers pool
   *
   * @param path Path to file to load
   * @return index into SoundManagers buffer list
   */
public int addSound(String path) {
    // Generate 1 buffer entry
    scratchBuffer.rewind().position(0).limit(1);
    AL10.alGenBuffers(scratchBuffer);
    buffers[bufferIndex] = scratchBuffer.get(0);
    // load wave data from buffer
    WaveData wavefile = WaveData.create("spaceinvaders/" + path);
    // copy to buffers
    AL10.alBufferData(buffers[bufferIndex], wavefile.format, wavefile.data, wavefile.samplerate);
    // unload file again
    wavefile.dispose();
    // return index for this sound
    return bufferIndex++;
}
Also used : WaveData(org.lwjgl.util.WaveData)

Example 8 with WaveData

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

the class MovingSoundTest 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" };
    }
    try {
        setDisplayMode();
        Display.create();
    } catch (Exception e) {
        e.printStackTrace();
    }
    int lastError;
    Vector3f sourcePosition = new Vector3f();
    Vector3f listenerPosition = new Vector3f();
    //initialize keyboard
    try {
        Keyboard.create();
    } catch (Exception e) {
        e.printStackTrace();
        exit(-1);
    }
    //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);
    }
    //load wave data
    WaveData wavefile = WaveData.create(args[0]);
    //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);
    }
    AL10.alSourcef(sources.get(0), AL10.AL_REFERENCE_DISTANCE, 1024.0f);
    AL10.alSourcef(sources.get(0), AL10.AL_ROLLOFF_FACTOR, 0.5f);
    //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);
    }
    System.out.println("Move source with arrow keys\nMove listener with right shift and arrowkeys\nExit with ESC");
    while (!Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
        Display.update();
        Keyboard.poll();
        if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
            if (Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
                listenerPosition.x -= MOVEMENT;
                AL10.alListener3f(AL10.AL_POSITION, listenerPosition.x, listenerPosition.y, listenerPosition.z);
                System.out.println("listenerx: " + listenerPosition.x);
            } else {
                sourcePosition.x -= MOVEMENT;
                AL10.alSource3f(sources.get(0), AL10.AL_POSITION, sourcePosition.x, sourcePosition.y, sourcePosition.z);
                System.out.println("sourcex: " + sourcePosition.x);
            }
        }
        if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
            if (Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
                listenerPosition.x += MOVEMENT;
                AL10.alListener3f(AL10.AL_POSITION, listenerPosition.x, listenerPosition.y, listenerPosition.z);
                System.out.println("listenerx: " + listenerPosition.x);
            } else {
                sourcePosition.x += MOVEMENT;
                AL10.alSource3f(sources.get(0), AL10.AL_POSITION, sourcePosition.x, sourcePosition.y, sourcePosition.z);
                System.out.println("sourcex: " + sourcePosition.x);
            }
        }
        if (Display.isCloseRequested()) {
            break;
        }
        try {
            Thread.sleep(100);
        } 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);
    }
    //shutdown
    alExit();
}
Also used : Vector3f(org.lwjgl.util.vector.Vector3f) IntBuffer(java.nio.IntBuffer) WaveData(org.lwjgl.util.WaveData)

Example 9 with WaveData

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

the class PlayTestMemory 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);
    }
    //load wave data
    ByteBuffer filebuffer = getData(args[0]);
    if (filebuffer == null) {
        System.out.println("Error loading file: " + args[0]);
        System.exit(-1);
    }
    System.out.println("loaded " + filebuffer.capacity());
    //ALUTLoadWAVData file = alut.loadWAVMemory(Sys.getDirectBufferAddress(filebuffer));
    if (usingVorbis) {
        // 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(filebuffer.array());
        //copy to buffers
        AL10.alBufferData(buffers.get(0), wavefile.format, wavefile.data, wavefile.samplerate);
        //unload file again
        wavefile.dispose();
    }
    // check for errors
    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.
    alExit();
}
Also used : IntBuffer(java.nio.IntBuffer) ByteBuffer(java.nio.ByteBuffer) WaveData(org.lwjgl.util.WaveData)

Example 10 with WaveData

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

the class WaveDataTest method executeStreamCreationTest.

private void executeStreamCreationTest() {
    try {
        AudioInputStream ais = AudioSystem.getAudioInputStream(new File(filePath));
        WaveData wd = WaveData.create(ais);
        if (wd == null) {
            System.out.println("executeMidStreamCreationTest::success");
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : AudioInputStream(javax.sound.sampled.AudioInputStream) File(java.io.File) WaveData(org.lwjgl.util.WaveData) LWJGLException(org.lwjgl.LWJGLException)

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