Java Code Examples for org.lwjgl.openal.AL10#alGenBuffers()

The following examples show how to use org.lwjgl.openal.AL10#alGenBuffers() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OpenALStreamPlayer.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new player to work on an audio stream
 * 
 * @param source The source on which we'll play the audio
 * @param ref A reference to the audio file to stream
 */
public OpenALStreamPlayer(int source, String ref) {
	this.source = source;
	this.ref = ref;
	
	bufferNames = BufferUtils.createIntBuffer(BUFFER_COUNT);
	AL10.alGenBuffers(bufferNames);
}
 
Example 2
Source File: OpenALMODPlayer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
    * Play a mod or xm track streamed from the specified location
    * 
    * @param module The moudle to play back
    * @param source The OpenAL source to play the music on
    * @param start True if the music should be started
    * @param loop True if the track should be looped
    */
public void play(Module module, int source, boolean loop, boolean start) {
	this.source = source;
	this.loop = loop;
	this.module = module;
	done = false;
	
	ibxm = new IBXM(48000);
	ibxm.set_module(module);
	songDuration = ibxm.calculate_song_duration();

	if (bufferNames != null) {
		AL10.alSourceStop(source);
		bufferNames.flip();
		AL10.alDeleteBuffers(bufferNames);
	}
	
	bufferNames = BufferUtils.createIntBuffer(2);
	AL10.alGenBuffers(bufferNames);
	remainingBufferCount = 2;
	
	for (int i=0;i<2;i++) {
        stream(bufferNames.get(i));
	}
       AL10.alSourceQueueBuffers(source, bufferNames);
	AL10.alSourcef(source, AL10.AL_PITCH, 1.0f);
	AL10.alSourcef(source, AL10.AL_GAIN, 1.0f); 
	
	if (start) {
		AL10.alSourcePlay(source);
	}
}
 
Example 3
Source File: OpenALStreamPlayer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Create a new player to work on an audio stream
 * 
 * @param source The source on which we'll play the audio
 * @param url A reference to the audio file to stream
 */
public OpenALStreamPlayer(int source, URL url) {
	this.source = source;
	this.url = url;

	bufferNames = BufferUtils.createIntBuffer(BUFFER_COUNT);
	AL10.alGenBuffers(bufferNames);
}
 
Example 4
Source File: OpenALStreamPlayer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Create a new player to work on an audio stream
 * 
 * @param source The source on which we'll play the audio
 * @param ref A reference to the audio file to stream
 */
public OpenALStreamPlayer(int source, String ref) {
	this.source = source;
	this.ref = ref;
	
	bufferNames = BufferUtils.createIntBuffer(BUFFER_COUNT);
	AL10.alGenBuffers(bufferNames);
}
 
Example 5
Source File: OpenALStreamPlayer.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new player to work on an audio stream
 * 
 * @param source The source on which we'll play the audio
 * @param url A reference to the audio file to stream
 */
public OpenALStreamPlayer(int source, URL url) {
	this.source = source;
	this.url = url;

	bufferNames = BufferUtils.createIntBuffer(BUFFER_COUNT);
	AL10.alGenBuffers(bufferNames);
}
 
Example 6
Source File: OpenALStreamPlayer.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new player to work on an audio stream
 * 
 * @param source The source on which we'll play the audio
 * @param ref A reference to the audio file to stream
 */
public OpenALStreamPlayer(int source, String ref) {
	this.source = source;
	this.ref = ref;
	
	bufferNames = BufferUtils.createIntBuffer(BUFFER_COUNT);
	AL10.alGenBuffers(bufferNames);
}
 
Example 7
Source File: Audio.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public Audio(int num_buffers) {
	al_buffers = BufferUtils.createIntBuffer(num_buffers);

	if (!AL.isCreated())
		return;
	AL10.alGenBuffers(al_buffers);
}
 
Example 8
Source File: OpenALStreamPlayer.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Create a new player to work on an audio stream
 * 
 * @param source The source on which we'll play the audio
 * @param url A reference to the audio file to stream
 */
public OpenALStreamPlayer(int source, URL url) {
	this.source = source;
	this.url = url;

	bufferNames = BufferUtils.createIntBuffer(BUFFER_COUNT);
	AL10.alGenBuffers(bufferNames);
}
 
Example 9
Source File: LwjglAL.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void alGenBuffers(int numBuffers, IntBuffer buffers) {
    if (buffers.position() != 0) throw new AssertionError();
    if (buffers.limit() != numBuffers) throw new AssertionError();
    AL10.alGenBuffers(buffers);
}
 
Example 10
Source File: LwjglAL.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void alGenBuffers(final int numBuffers, final IntBuffer buffers) {
    if (buffers.position() != 0) throw new AssertionError();
    if (buffers.limit() != numBuffers) throw new AssertionError();
    AL10.alGenBuffers(buffers);
}
 
Example 11
Source File: Sonics.java    From AnyaBasic with MIT License 4 votes vote down vote up
public int load( String filename, boolean isLooping )
{
    // Load wav data into a buffer.
    AL10.alGenBuffers(buffer);

    if(AL10.alGetError() != AL10.AL_NO_ERROR)
        return AL10.AL_FALSE;

    URL url = this.getClass().getClassLoader().getResource(filename);

    InputStream in ;
    WaveData waveFile = null;
    try
    {
        in = url.openStream();
        //Loads the wave file from this class's package in your classpath
        waveFile = WaveData.create(in);
        in.close();
        if(waveFile == null )
        {
            System.out.println("Error Loading sound data!");
        }
    }
    catch( IOException e )
    {
        e.printStackTrace();
    }


    AL10.alBufferData(buffer.get(0), waveFile.format, waveFile.data, waveFile.samplerate);
    waveFile.dispose();

    // Bind the buffer with the source.
    AL10.alGenSources(source);

    if (AL10.alGetError() != AL10.AL_NO_ERROR)
        return AL10.AL_FALSE;

    AL10.alSourcei(source.get(0), AL10.AL_BUFFER,   buffer.get(0) );
    AL10.alSourcef(source.get(0), AL10.AL_PITCH,    1.0f          );
    AL10.alSourcef(source.get(0), AL10.AL_GAIN,     1.0f          );
    AL10.alSource (source.get(0), AL10.AL_POSITION, sourcePos     );
    AL10.alSource (source.get(0), AL10.AL_VELOCITY, sourceVel     );
    if( isLooping ) AL10.alSourcei(source.get(0), AL10.AL_LOOPING,  AL10.AL_TRUE  );

    setListenerValues();

    // Do another error check and return.
    if (AL10.alGetError() == AL10.AL_NO_ERROR)
        return AL10.AL_TRUE;

    return AL10.AL_FALSE;
}
 
Example 12
Source File: SoundStore.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Get the Sound based on a specified WAV file
 * 
 * @param ref The reference to the WAV file in the classpath
 * @param in The stream to the WAV to load
 * @return The Sound read from the WAV file
 * @throws IOException Indicates a failure to load the WAV
 */
public Audio getWAV(String ref, InputStream in) throws IOException {
	if (!soundWorks) {
		return new NullAudio();
	}
	if (!inited) {
		throw new RuntimeException("Can't load sounds until SoundStore is init(). Use the container init() method.");
	}
	if (deferred) {
		return new DeferredSound(ref, in, DeferredSound.WAV);
	}
	
	int buffer = -1;
	
	if (loaded.get(ref) != null) {
		buffer = ((Integer) loaded.get(ref)).intValue();
	} else {
		try {
			IntBuffer buf = BufferUtils.createIntBuffer(1);
			
			WaveData data = WaveData.create(in);
			AL10.alGenBuffers(buf);
			AL10.alBufferData(buf.get(0), data.format, data.data, data.samplerate);
			
			loaded.put(ref,new Integer(buf.get(0)));
			buffer = buf.get(0);
		} catch (Exception e) {
			Log.error(e);
			IOException x = new IOException("Failed to load: "+ref);
			x.initCause(e);
			
			throw x;
		}
	}
	
	if (buffer == -1) {
		throw new IOException("Unable to load: "+ref);
	}
	
	return new AudioImpl(this, buffer);
}
 
Example 13
Source File: SoundStore.java    From opsu with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Get the Sound based on a specified OGG file
 * 
 * @param ref The reference to the OGG file in the classpath
 * @param in The stream to the OGG to load
 * @return The Sound read from the OGG file
 * @throws IOException Indicates a failure to load the OGG
 */
public Audio getOgg(String ref, InputStream in) throws IOException {
	if (!soundWorks) {
		return new NullAudio();
	}
	if (!inited) {
		throw new RuntimeException("Can't load sounds until SoundStore is init(). Use the container init() method.");
	}
	if (deferred) {
		return new DeferredSound(ref, in, DeferredSound.OGG);
	}
	
	int buffer = -1;
	
	if (loaded.get(ref) != null) {
		buffer = ((Integer) loaded.get(ref)).intValue();
	} else {
		try {
			IntBuffer buf = BufferUtils.createIntBuffer(1);
			
			OggDecoder decoder = new OggDecoder();
			OggData ogg = decoder.getData(in);
			
			AL10.alGenBuffers(buf);
			AL10.alBufferData(buf.get(0), ogg.channels > 1 ? AL10.AL_FORMAT_STEREO16 : AL10.AL_FORMAT_MONO16, ogg.data, ogg.rate);
			
			loaded.put(ref,new Integer(buf.get(0)));
			                     
			buffer = buf.get(0);
		} catch (Exception e) {
			Log.error(e);
			Sys.alert("Error","Failed to load: "+ref+" - "+e.getMessage());
			throw new IOException("Unable to load: "+ref);
		}
	}
	
	if (buffer == -1) {
		throw new IOException("Unable to load: "+ref);
	}
	
	return new AudioImpl(this, buffer);
}
 
Example 14
Source File: SoundStore.java    From opsu-dance with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Get the Sound based on a specified OGG file
 * 
 * @param ref The reference to the OGG file in the classpath
 * @param in The stream to the OGG to load
 * @return The Sound read from the OGG file
 * @throws IOException Indicates a failure to load the OGG
 */
public Audio getOgg(String ref, InputStream in) throws IOException {
	if (!soundWorks) {
		return new NullAudio();
	}
	if (!inited) {
		throw new RuntimeException("Can't load sounds until SoundStore is init(). Use the container init() method.");
	}
	if (deferred) {
		return new DeferredSound(ref, in, DeferredSound.OGG);
	}
	
	int buffer = -1;
	
	if (loaded.get(ref) != null) {
		buffer = ((Integer) loaded.get(ref)).intValue();
	} else {
		try {
			IntBuffer buf = BufferUtils.createIntBuffer(1);
			
			OggDecoder decoder = new OggDecoder();
			OggData ogg = decoder.getData(in);
			
			AL10.alGenBuffers(buf);
			AL10.alBufferData(buf.get(0), ogg.channels > 1 ? AL10.AL_FORMAT_STEREO16 : AL10.AL_FORMAT_MONO16, ogg.data, ogg.rate);
			
			loaded.put(ref,new Integer(buf.get(0)));
			                     
			buffer = buf.get(0);
		} catch (Exception e) {
			Log.error(e);
			Sys.alert("Error","Failed to load: "+ref+" - "+e.getMessage());
			throw new IOException("Unable to load: "+ref);
		}
	}
	
	if (buffer == -1) {
		throw new IOException("Unable to load: "+ref);
	}
	
	return new AudioImpl(this, buffer);
}
 
Example 15
Source File: SoundStore.java    From opsu-dance with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Get the Sound based on a specified WAV file
 * 
 * @param ref The reference to the WAV file in the classpath
 * @param in The stream to the WAV to load
 * @return The Sound read from the WAV file
 * @throws IOException Indicates a failure to load the WAV
 */
public Audio getWAV(String ref, InputStream in) throws IOException {
	if (!soundWorks) {
		return new NullAudio();
	}
	if (!inited) {
		throw new RuntimeException("Can't load sounds until SoundStore is init(). Use the container init() method.");
	}
	if (deferred) {
		return new DeferredSound(ref, in, DeferredSound.WAV);
	}
	
	int buffer = -1;
	
	if (loaded.get(ref) != null) {
		buffer = ((Integer) loaded.get(ref)).intValue();
	} else {
		try {
			IntBuffer buf = BufferUtils.createIntBuffer(1);
			
			WaveData data = WaveData.create(in);
			AL10.alGenBuffers(buf);
			AL10.alBufferData(buf.get(0), data.format, data.data, data.samplerate);
			
			loaded.put(ref,new Integer(buf.get(0)));
			buffer = buf.get(0);
		} catch (Exception e) {
			Log.error(e);
			IOException x = new IOException("Failed to load: "+ref);
			x.initCause(e);
			
			throw x;
		}
	}
	
	if (buffer == -1) {
		throw new IOException("Unable to load: "+ref);
	}
	
	return new AudioImpl(this, buffer);
}
 
Example 16
Source File: SoundStore.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Get the Sound based on a specified WAV file
 * 
 * @param ref The reference to the WAV file in the classpath
 * @param in The stream to the WAV to load
 * @return The Sound read from the WAV file
 * @throws IOException Indicates a failure to load the WAV
 */
public Audio getWAV(String ref, InputStream in) throws IOException {
	if (!soundWorks) {
		return new NullAudio();
	}
	if (!inited) {
		throw new RuntimeException("Can't load sounds until SoundStore is init(). Use the container init() method.");
	}
	if (deferred) {
		return new DeferredSound(ref, in, DeferredSound.WAV);
	}
	
	int buffer = -1;
	
	if (loaded.get(ref) != null) {
		buffer = ((Integer) loaded.get(ref)).intValue();
	} else {
		try {
			IntBuffer buf = BufferUtils.createIntBuffer(1);
			
			WaveData data = WaveData.create(in);
			AL10.alGenBuffers(buf);
			AL10.alBufferData(buf.get(0), data.format, data.data, data.samplerate);
			
			loaded.put(ref,new Integer(buf.get(0)));
			buffer = buf.get(0);
		} catch (Exception e) {
			Log.error(e);
			IOException x = new IOException("Failed to load: "+ref);
			x.initCause(e);
			
			throw x;
		}
	}
	
	if (buffer == -1) {
		throw new IOException("Unable to load: "+ref);
	}
	
	return new AudioImpl(this, buffer);
}
 
Example 17
Source File: SoundStore.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Get the Sound based on a specified OGG file
 * 
 * @param ref The reference to the OGG file in the classpath
 * @param in The stream to the OGG to load
 * @return The Sound read from the OGG file
 * @throws IOException Indicates a failure to load the OGG
 */
public Audio getOgg(String ref, InputStream in) throws IOException {
	if (!soundWorks) {
		return new NullAudio();
	}
	if (!inited) {
		throw new RuntimeException("Can't load sounds until SoundStore is init(). Use the container init() method.");
	}
	if (deferred) {
		return new DeferredSound(ref, in, DeferredSound.OGG);
	}
	
	int buffer = -1;
	
	if (loaded.get(ref) != null) {
		buffer = ((Integer) loaded.get(ref)).intValue();
	} else {
		try {
			IntBuffer buf = BufferUtils.createIntBuffer(1);
			
			OggDecoder decoder = new OggDecoder();
			OggData ogg = decoder.getData(in);
			
			AL10.alGenBuffers(buf);
			AL10.alBufferData(buf.get(0), ogg.channels > 1 ? AL10.AL_FORMAT_STEREO16 : AL10.AL_FORMAT_MONO16, ogg.data, ogg.rate);
			
			loaded.put(ref,new Integer(buf.get(0)));
			                     
			buffer = buf.get(0);
		} catch (Exception e) {
			Log.error(e);
			Sys.alert("Error","Failed to load: "+ref+" - "+e.getMessage());
			throw new IOException("Unable to load: "+ref);
		}
	}
	
	if (buffer == -1) {
		throw new IOException("Unable to load: "+ref);
	}
	
	return new AudioImpl(this, buffer);
}