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

The following examples show how to use org.lwjgl.openal.AL10#alBufferData() . 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: Audio.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public Audio(URL file) {
	this(1);
	if (!AL.isCreated())
		return;
	Wave wave;
	try {
		wave = new Wave(file);
	} catch (Exception e) {
		// Assume it's an ogg vorbis file
		wave = loadOGG(file);
	}
	AL10.alBufferData(al_buffers.get(0), wave.getFormat(), wave.getData(), wave.getSampleRate());
}
 
Example 2
Source File: QueuedAudioPlayer.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
private final void fillBufferFromStream(int al_buffer) {
		buffer_stream.buffer().flip();
/*		buffer_stream.buffer().limit(256);
		buffer_stream.buffer().position(0);
		for (int i = 0; i < buffer_stream.buffer().remaining(); i++)
			buffer_stream.buffer().put(i, (byte)0);*/
//System.out.println("al_buffer = " + al_buffer);
//		assert buffer_stream.buffer().remaining()%512 == 0;
		AL10.alBufferData(al_buffer, Wave.getFormat(channels, 16), buffer_stream.buffer(), ogg_stream.getRate());
	}
 
Example 3
Source File: OpenALMODPlayer.java    From slick2d-maven with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Stream one section from the mod/xm into an OpenAL buffer
 * 
 * @param bufferId The ID of the buffer to fill
 * @return True if another section was available
 */
public boolean stream(int bufferId) {
	int frames = sectionSize;
	boolean reset = false;
	boolean more = true;
	
	if (frames > songDuration) {
		frames = songDuration;
		reset = true;
	}
	
	ibxm.get_audio(data, frames);
	bufferData.clear();
	bufferData.put(data);
	bufferData.limit(frames * 4);
	
	if (reset) {
		if (loop) {
			ibxm.seek(0); 
			ibxm.set_module(module);
			songDuration = ibxm.calculate_song_duration();
		} else {
			more = false;
			songDuration -= frames;
		}
	} else {
		songDuration -= frames;
	}

	bufferData.flip();
	AL10.alBufferData(bufferId, AL10.AL_FORMAT_STEREO16, bufferData, 48000);
	
	return more;
}
 
Example 4
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 5
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 6
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 7
Source File: LwjglAL.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void alBufferData(int buffer, int format, ByteBuffer data, int size, int frequency) {
    if (data.position() != 0) throw new AssertionError();
    if (data.limit() != size) throw new AssertionError();
    AL10.alBufferData(buffer, format, data, frequency);
}
 
Example 8
Source File: LwjglAL.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void alBufferData(final int buffer, final int format, final ByteBuffer data, final int size, final int frequency) {
    if (data.position() != 0) throw new AssertionError();
    if (data.limit() != size) throw new AssertionError();
    AL10.alBufferData(buffer, format, data, frequency);
}
 
Example 9
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 10
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 11
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 12
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);
}