当前位置: 首页>>代码示例>>Java>>正文


Java WaveData类代码示例

本文整理汇总了Java中org.lwjgl.util.WaveData的典型用法代码示例。如果您正苦于以下问题:Java WaveData类的具体用法?Java WaveData怎么用?Java WaveData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WaveData类属于org.lwjgl.util包,在下文中一共展示了WaveData类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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++;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:25,代码来源:SoundManager.java

示例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();
	}
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:19,代码来源:WaveDataTest.java

示例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();
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:23,代码来源:StressTest.java

示例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;
}
 
开发者ID:Radseq,项目名称:Mystic-Bastion,代码行数:23,代码来源:SoundManager.java

示例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();
  }
}
 
开发者ID:l50,项目名称:redrun,代码行数:24,代码来源:Sound.java

示例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;
}
 
开发者ID:TauOmicronMu,项目名称:TeamProject,代码行数:36,代码来源:AudioEngine.java

示例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);
}
 
开发者ID:nitrodragon,项目名称:lwjgl_collection,代码行数:34,代码来源:OpenALDemo.java

示例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();
	}
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:12,代码来源:WaveDataTest.java

示例9: getData

import org.lwjgl.util.WaveData; //导入依赖的package包/类
/**
 * Reads the file into a ByteBuffer
 *
 * @param filename Name of file to load
 * @return ByteBuffer containing file data
 */
protected ByteBuffer getData(String filename) {
  ByteBuffer buffer = null;

  System.out.println("Attempting to load: " + filename);
  
  try {
    BufferedInputStream bis = new BufferedInputStream(WaveData.class.getClassLoader().getResourceAsStream(filename));
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    
    int bufferLength = 4096;
    byte[] readBuffer = new byte[bufferLength];
    int read = -1;
    
    while((read = bis.read(readBuffer, 0, bufferLength)) != -1) {
      baos.write(readBuffer, 0, read);
    }
    
    //done reading, close
    bis.close();
    
    // if ogg vorbis data, we need to pass it unmodified to alBufferData
    buffer = ByteBuffer.allocateDirect(baos.size());
    buffer.order(ByteOrder.nativeOrder());
    buffer.put(baos.toByteArray());
    buffer.rewind();
  } catch (Exception ioe) {
    ioe.printStackTrace();
  }
  return buffer;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:37,代码来源:PlayTest.java

示例10: getData

import org.lwjgl.util.WaveData; //导入依赖的package包/类
/**
 * Reads the file into a ByteBuffer
 *
 * @param filename Name of file to load
 * @return ByteBuffer containing file data
 */
protected ByteBuffer getData(String filename) {
    ByteBuffer buffer = null;

    System.out.println("Attempting to load: " + filename);
    
    try {
        BufferedInputStream bis = new BufferedInputStream(WaveData.class.getClassLoader().getResourceAsStream(filename));
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        
        int bufferLength = 4096;
        byte[] readBuffer = new byte[bufferLength];
        int read = -1;
        
        while((read = bis.read(readBuffer, 0, bufferLength)) != -1) {
            baos.write(readBuffer, 0, read);
        }
        
        //done reading, close
        bis.close();
        
        // if ogg vorbis data, we need to pass it unmodified to alBufferData
        if(usingVorbis) {
          buffer = ByteBuffer.allocateDirect(baos.size());
        } else {
          buffer = ByteBuffer.allocate(baos.size());
        }
        buffer.order(ByteOrder.nativeOrder());
        buffer.put(baos.toByteArray());
        buffer.rewind();
    } catch (Exception ioe) {
        ioe.printStackTrace();
    }
    return buffer;
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:41,代码来源:PlayTestMemory.java

示例11: 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());
	}
}
 
开发者ID:pdsimari,项目名称:CubeQuest,代码行数:10,代码来源:CubeQuest.java

示例12: 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;
}
 
开发者ID:AXDOOMER,项目名称:KillBox,代码行数:29,代码来源:Sound.java


注:本文中的org.lwjgl.util.WaveData类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。