本文整理汇总了Java中org.lwjgl.util.WaveData.create方法的典型用法代码示例。如果您正苦于以下问题:Java WaveData.create方法的具体用法?Java WaveData.create怎么用?Java WaveData.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.lwjgl.util.WaveData
的用法示例。
在下文中一共展示了WaveData.create方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: executeMidStreamCreationTest
import org.lwjgl.util.WaveData; //导入方法依赖的package包/类
private void executeMidStreamCreationTest() {
try {
AudioInputStream ais = AudioSystem.getAudioInputStream(WaveDataTest.class.getClassLoader().getResource(filePath));
int totalSize = ais.getFormat().getChannels() * (int) ais.getFrameLength() * ais.getFormat().getSampleSizeInBits() / 8;
// skip 1/4 of the stream
int skip = totalSize / 4;
long skipped = ais.skip(skip);
WaveData wd = WaveData.create(ais);
if(wd == null) {
System.out.println("executeMidStreamCreationTest::success");
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例3: 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();
}
示例4: initBuffer
import org.lwjgl.util.WaveData; //导入方法依赖的package包/类
private IntBuffer initBuffer(String filename) {
// WaveData waveFile = WaveData.create(getResource("Sounds/" +
// filename));
WaveData waveFile = null;
try {
waveFile = WaveData.create(
new BufferedInputStream(new FileInputStream("sound" + File.separatorChar + filename + ".wav")));
} catch (FileNotFoundException e) {
System.err.println("Tried to load sound " + filename + ".wav , didn't work");
e.printStackTrace();
}
IntBuffer buffer = BufferUtils.createIntBuffer(1);
AL10.alGenBuffers(buffer);
if (AL10.alGetError() != AL10.AL_NO_ERROR) {
System.out.println("Error loading file: " + filename);
return null;
}
AL10.alBufferData(buffer.get(0), waveFile.format, waveFile.data, waveFile.samplerate);
return buffer;
}
示例5: Sound
import org.lwjgl.util.WaveData; //导入方法依赖的package包/类
/**
* Creates a new sound with the specified sound file.
*
* @param soundName the location of the sound file.
*/
public Sound(String soundName)
{
try
{
FileInputStream input = new FileInputStream("res/sounds/" + soundName + ".wav");
data = WaveData.create(new BufferedInputStream(input));
buffer = alGenBuffers();
alBufferData(buffer, data.format, data.data, data.samplerate);
data.dispose();
source = alGenSources();
alSourcei(source, AL_BUFFER, buffer);
GameData.soundManager.addSound(this);
}
catch (FileNotFoundException e)
{
e.printStackTrace();
}
}
示例6: 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;
}
示例7: 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);
}
示例8: executeStreamCreationTest
import org.lwjgl.util.WaveData; //导入方法依赖的package包/类
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();
}
}
示例9: 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());
}
}
示例10: 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;
}
示例11: readAudio
import org.lwjgl.util.WaveData; //导入方法依赖的package包/类
public Audio readAudio(InputStream in) throws Exception {
if (!al) {
return CODEC_JAVASOUND.readAudio(in);
}
AudioInputStream ais = AudioSystem.getAudioInputStream(in);
AudioFormat af = ais.getFormat();
int buffer = -1;
try {
IntBuffer buf = BufferUtils.createIntBuffer(1);
WaveData data = WaveData.create(ais);
alGenBuffers(buf);
alBufferData(buf.get(0),
data.format,
data.data,
data.samplerate);
buffer = buf.get(0);
} catch (Exception e) {
ErrorHandler.alert(e);
}
if (buffer == -1) {
throw new IOException("unable to load: " + in);
}
ALAudio ala = new ALAudio(buffer, af);
return ala;
}
示例12: executeCreationTest
import org.lwjgl.util.WaveData; //导入方法依赖的package包/类
private void executeCreationTest() {
WaveData wd = WaveData.create(filePath);
if(wd != null) {
System.out.println("executeCreationTest::success");
}
}
示例13: executeBrokenCreationTest
import org.lwjgl.util.WaveData; //导入方法依赖的package包/类
private void executeBrokenCreationTest() {
WaveData wd = WaveData.create("");
if(wd == null) {
System.out.println("executeBrokenCreationTest::success");
}
}
示例14: 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();
}
示例15: 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);
}
}