本文整理汇总了Java中org.lwjgl.system.MemoryUtil.memAllocShort方法的典型用法代码示例。如果您正苦于以下问题:Java MemoryUtil.memAllocShort方法的具体用法?Java MemoryUtil.memAllocShort怎么用?Java MemoryUtil.memAllocShort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.lwjgl.system.MemoryUtil
的用法示例。
在下文中一共展示了MemoryUtil.memAllocShort方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readVorbis
import org.lwjgl.system.MemoryUtil; //导入方法依赖的package包/类
private ShortBuffer readVorbis(String resource, int bufferSize, STBVorbisInfo info) throws Exception {
try (MemoryStack stack = MemoryStack.stackPush()) {
vorbis = Utils.ioResourceToByteBuffer(resource, bufferSize);
IntBuffer error = stack.mallocInt(1);
long decoder = stb_vorbis_open_memory(vorbis, error, null);
if (decoder == NULL) {
throw new RuntimeException("Failed to open Ogg Vorbis file. Error: " + error.get(0));
}
stb_vorbis_get_info(decoder, info);
int channels = info.channels();
int lengthSamples = stb_vorbis_stream_length_in_samples(decoder);
pcm = MemoryUtil.memAllocShort(lengthSamples);
pcm.limit(stb_vorbis_get_samples_short_interleaved(decoder, channels, pcm) * channels);
stb_vorbis_close(decoder);
return pcm;
}
}
示例2: bufferData
import org.lwjgl.system.MemoryUtil; //导入方法依赖的package包/类
@Override
public void bufferData(int buffer, Format format, short[] data, int freq) {
if(!isBuffer(buffer))
throw new ALError("alBufferData", "Argument passed as buffer is not a buffer");
if(data == null || data.length == 0)
throw new ALError("alBufferData", "Data cannot be null or empty");
ShortBuffer sbuff = MemoryUtil.memAllocShort(data.length);
sbuff.put(data);
alBufferData(buffer, format.e, sbuff, freq);
MemoryUtil.memFree(sbuff);
}