本文整理汇总了Java中org.lwjgl.util.WaveData.dispose方法的典型用法代码示例。如果您正苦于以下问题:Java WaveData.dispose方法的具体用法?Java WaveData.dispose怎么用?Java WaveData.dispose使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.lwjgl.util.WaveData
的用法示例。
在下文中一共展示了WaveData.dispose方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addSound
import org.lwjgl.util.WaveData; //导入方法依赖的package包/类
/**
* 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++;
}
示例2: loadSamples
import org.lwjgl.util.WaveData; //导入方法依赖的package包/类
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();
}
示例3: loadALData
import org.lwjgl.util.WaveData; //导入方法依赖的package包/类
/**
* Load in the data from the disk to OpenAL as a buffer, and create a source
* to play our buffer.
* @param filepath The path to the .wav file to load.
* @return Returns AL10.AL_TRUE on success, and otherwise returns AL10.AL_FALSE.
*/
private int loadALData(String filepath) {
/** Load the wav data into the buffer */
AL10.alGenBuffers(buffer);
if(AL10.alGetError() != AL10.AL_NO_ERROR) return AL10.AL_FALSE;
/** Load the wave file from the classpath */
WaveData waveFile = WaveData.create(filepath);
/** Set up the buffer with the format (etc.) of the wav file.*/
AL10.alBufferData(buffer.get(0), waveFile.format, waveFile.data, waveFile.samplerate);
waveFile.dispose();
/** Bind the buffer to the corresponding source */
AL10.alGenSources(source);
if(AL10.alGetError() != AL10.AL_NO_ERROR) return AL10.AL_FALSE;
/** Configure the AL data to do what we want. */
AL10.alSourcei (source.get(0), AL10.AL_BUFFER, buffer.get(0));
AL10.alSourcef (source.get(0), AL10.AL_PITCH, pitch);
AL10.alSourcef (source.get(0), AL10.AL_GAIN, gain);
AL10.alSourcefv(source.get(0), AL10.AL_POSITION, sourcePos);
AL10.alSourcefv(source.get(0), AL10.AL_VELOCITY, sourceVel);
/** Do a final error check, return AL10.AL_TRUE if everything worked. */
if(AL10.alGetError() == AL10.AL_NO_ERROR) return AL10.AL_TRUE;
/** Otherwise, return AL10.AL_FALSE because something went wrong.*/
return AL10.AL_FALSE;
}
示例4: main
import org.lwjgl.util.WaveData; //导入方法依赖的package包/类
public static void main(String[] args) throws FileNotFoundException {
try {
Display.setDisplayMode(new DisplayMode(640, 480));
Display.setTitle("OpenAL Demo");
Display.create();
AL.create();
} catch (LWJGLException e) {
e.printStackTrace();
Display.destroy();
AL.destroy();
System.exit(1);
}
WaveData data = WaveData.create(new BufferedInputStream(new FileInputStream("res" + File.separatorChar +
"sounds" + File.separatorChar + "thump.wav")));
int buffer = alGenBuffers();
alBufferData(buffer, data.format, data.data, data.samplerate);
data.dispose();
int source = alGenSources();
alSourcei(source, AL_BUFFER, buffer);
while (!Display.isCloseRequested()) {
while (Keyboard.next()) {
if (Keyboard.isKeyDown(Keyboard.KEY_SPACE)) {
alSourcePlay(source);
}
}
Display.update();
Display.sync(60);
}
alDeleteBuffers(buffer);
AL.destroy();
Display.destroy();
System.exit(0);
}
示例5: loadWavIntoBuffer
import org.lwjgl.util.WaveData; //导入方法依赖的package包/类
private static void loadWavIntoBuffer(int buffer, String path) {
try {
WaveData wd = WaveData.create(new BufferedInputStream(new FileInputStream(path)));
alBufferData(buffer,wd.format,wd.data,wd.samplerate);
wd.dispose();
} catch (FileNotFoundException e) {
System.out.println(e.toString());
}
}
示例6: CacheSound
import org.lwjgl.util.WaveData; //导入方法依赖的package包/类
public boolean CacheSound(String File)
{
if (!LoadedFiles.contains(File))
{
try
{
// Load the sound, create a buffer and save the filename.
WaveData Data = WaveData.create(new BufferedInputStream(new FileInputStream("res/sounds/" + File)));
int Buffer = alGenBuffers();
alBufferData(Buffer, Data.format, Data.data, Data.samplerate);
Data.dispose();
if (!LoadedFiles.contains(File))
{
LoadedFiles.add(File);
SoundBuffers.add(Buffer);
}
//IntSources.add(alGenSources());
}
catch (Exception ex)
{
return false;
}
}
return true;
}
示例7: playbackTest
import org.lwjgl.util.WaveData; //导入方法依赖的package包/类
/**
* 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();
}
示例8: playOpenAL
import org.lwjgl.util.WaveData; //导入方法依赖的package包/类
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);
}
}
示例9: load
import org.lwjgl.util.WaveData; //导入方法依赖的package包/类
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;
}