本文整理汇总了Java中org.lwjgl.stb.STBVorbisInfo.malloc方法的典型用法代码示例。如果您正苦于以下问题:Java STBVorbisInfo.malloc方法的具体用法?Java STBVorbisInfo.malloc怎么用?Java STBVorbisInfo.malloc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.lwjgl.stb.STBVorbisInfo
的用法示例。
在下文中一共展示了STBVorbisInfo.malloc方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Decoder
import org.lwjgl.stb.STBVorbisInfo; //导入方法依赖的package包/类
public Decoder(String path, IntBuffer buffers){
this.buffers = buffers;
vorbis = ResourceLoader.getBytes(path);
IntBuffer error = BufferUtils.createIntBuffer(1);
handle = stb_vorbis_open_memory(vorbis, error, null);
if(handle == 0L){
throw new RuntimeException("Unable to open stb");
}
STBVorbisInfo info = STBVorbisInfo.malloc();
stb_vorbis_get_info(handle, info);
channels = info.channels();
sampleRate = info.sample_rate();
format = (channels == 1) ? AL10.AL_FORMAT_MONO16 : AL10.AL_FORMAT_STEREO16;
lengthSamples = stb_vorbis_stream_length_in_samples(handle);
lengthSeconds = stb_vorbis_stream_length_in_seconds(handle);
pcm = BufferUtils.createShortBuffer(BUFFER_SIZE);
samplesLeft = lengthSamples;
}
示例2: allocate
import org.lwjgl.stb.STBVorbisInfo; //导入方法依赖的package包/类
private void allocate(){
ByteBuffer buffer = ResourceLoader.getBytes(path);
IntBuffer error = BufferUtils.createIntBuffer(1);
long decoder = stb_vorbis_open_memory(buffer, error, null);
if(decoder == 0L){
Application.error("Unable to open STB Vorbis");
return;
}
STBVorbisInfo info = STBVorbisInfo.malloc();
stb_vorbis_get_info(decoder, info);
int channels = info.channels();
int lengthSamples = stb_vorbis_stream_length_in_samples(decoder);
ShortBuffer pcm = BufferUtils.createShortBuffer(lengthSamples);
pcm.limit(stb_vorbis_get_samples_short_interleaved(decoder, channels, pcm) * channels);
stb_vorbis_close(decoder);
AL10.alBufferData(id, info.channels() == 1? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, pcm, info.sample_rate());
}
示例3: SoundBuffer
import org.lwjgl.stb.STBVorbisInfo; //导入方法依赖的package包/类
public SoundBuffer(String file) throws Exception {
this.bufferId = alGenBuffers();
try (STBVorbisInfo info = STBVorbisInfo.malloc()) {
ShortBuffer pcm = readVorbis(file, 32 * 1024, info);
// Copy to buffer
alBufferData(bufferId, info.channels() == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, pcm,
info.sample_rate());
}
}
示例4: SoundBuffer
import org.lwjgl.stb.STBVorbisInfo; //导入方法依赖的package包/类
public SoundBuffer(String file) throws Exception {
this.bufferId = alGenBuffers();
try (STBVorbisInfo info = STBVorbisInfo.malloc()) {
ShortBuffer pcm = readVorbis(file, 32 * 1024, info);
// Copy to buffer
alBufferData(bufferId, info.channels() == 1 ? AL_FORMAT_MONO16 : AL_FORMAT_STEREO16, pcm, info.sample_rate());
}
}
示例5: decodeToPCM
import org.lwjgl.stb.STBVorbisInfo; //导入方法依赖的package包/类
/**
* This method reads in the OGG data, and convert it into PCM samples ready to be fed into the mouth of OpenAL
* ALBuffer class.
*/
private void decodeToPCM(DirectBuffer input)
{
// Create a memory representation to read from memory
ByteBuffer memoryBuffer = (ByteBuffer) input.nativeBuffer();
// Open the vorbis file to get stb_vorbis*
IntBuffer error = BufferUtils.createIntBuffer(1);
long handle = stb_vorbis_open_memory(memoryBuffer, error, null);
if (handle == NULL)
throw new SilenceException("Error " + error.get(0) + ": decoding the OGG data");
// Get the information about the OGG header
STBVorbisInfo info = STBVorbisInfo.malloc();
stb_vorbis_get_info(handle, info);
int channels = info.channels();
sampleRate = info.sample_rate();
format = channels == 1 ? ALFormat.MONO_16 : ALFormat.STEREO_16;
// Read all the samples once for all
int numSamples = stb_vorbis_stream_length_in_samples(handle);
ByteBuffer pcm = BufferUtils.createByteBuffer(numSamples * Short.BYTES);
stb_vorbis_get_samples_short_interleaved(handle, channels, pcm.asShortBuffer());
// Convert the audio bytes and store the data buffer
data = pcm;
// Close the stb_vorbis* handle
stb_vorbis_close(handle);
info.free();
}
示例6: loadSound
import org.lwjgl.stb.STBVorbisInfo; //导入方法依赖的package包/类
public static int loadSound(File file) {
STBVorbisInfo info = STBVorbisInfo.malloc();
ByteBuffer vorbis;
try {
vorbis = loadSoundToByteBuffer(file, (int) file.length());
} catch (IOException e) {
throw new RuntimeException(e);
}
IntBuffer error = BufferUtils.createIntBuffer(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 lengthSamples = stb_vorbis_stream_length_in_samples(decoder);
ShortBuffer pcm = BufferUtils.createShortBuffer(info.channels() * lengthSamples);
stb_vorbis_get_samples_short_interleaved(decoder, info.channels(), pcm);
stb_vorbis_close(decoder);
int buffer = alGenBuffers();
alBufferData(buffer, info.channels() == 2 ? AL10.AL_FORMAT_STEREO16 : AL10.AL_FORMAT_MONO16, pcm,
info.sample_rate());
return buffer;
}
示例7: readVorbis
import org.lwjgl.stb.STBVorbisInfo; //导入方法依赖的package包/类
public static ALBufferData readVorbis(Supplier<InputStream> resource) {
try (STBVorbisInfo info = STBVorbisInfo.malloc()) {
ByteBuffer vorbis;
try {
vorbis = LUtils.inputStreamToDirectByteBuffer(resource);
} catch (IOException e) {
throw new RuntimeException(e);
}
IntBuffer error = BufferUtils.createIntBuffer(1);
long decoder = stb_vorbis_open_memory(vorbis, error, null);
if (decoder == MemoryUtil.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);
ShortBuffer pcm = BufferUtils.createShortBuffer(lengthSamples);
pcm.limit(stb_vorbis_get_samples_short_interleaved(decoder, channels, pcm) * channels);
stb_vorbis_close(decoder);
return ALBufferData.create(channels == 1 ? AL10.AL_FORMAT_MONO16 : AL10.AL_FORMAT_STEREO16, pcm,
info.sample_rate());
}
}
示例8: loadOGGFormat
import org.lwjgl.stb.STBVorbisInfo; //导入方法依赖的package包/类
public void loadOGGFormat(){
STBVorbisInfo info = STBVorbisInfo.malloc();
ByteBuffer buff = BufferUtils.createByteBuffer(0);
//lecture du fichier
//----------------------------------------------------------------------------------------------------------------
try {
File file = new File(fileName);
if ( file.isFile() ) {
FileInputStream fis = new FileInputStream(file);
FileChannel fc = fis.getChannel();
buff = BufferUtils.createByteBuffer((int)fc.size() + 1);
while ( fc.read(buff) != -1 ) ;
fis.close();
fc.close();
} else {
System.err.println("File not found !");
return;
}
buff.flip();
} catch (IOException e) {
throw new RuntimeException(e);
}
//----------------------------------------------------------------------------------------------------------------
IntBuffer error = BufferUtils.createIntBuffer(1);
long decoder = stb_vorbis_open_memory(buff, 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();
stb_vorbis_seek_start(decoder);
int lengthSamples = stb_vorbis_stream_length_in_samples(decoder);
ShortBuffer pcm = BufferUtils.createShortBuffer(lengthSamples * channels);
stb_vorbis_get_samples_short_interleaved(decoder, channels, pcm);
stb_vorbis_close(decoder);
buffer = alGenBuffers();
source = alGenSources();
if(channels == 1)alBufferData(buffer, AL_FORMAT_MONO16, pcm, info.sample_rate());
else alBufferData(buffer, AL_FORMAT_STEREO16, pcm, info.sample_rate());
}