2013-12-19 22 views
0

地狱程序员,我目前正在研究的OpenAL与LWJGL,我不明白这行代码做(的意见代表什么,我认为他们正在做的,可以请你告诉我正确的事情?我看过的Javadoc并没有明白的事情。我用Google搜索和Google搜索。)爪哇 - LWJGL - OpenAL的 - 了解一些代码

WaveData data = WaveData.create(new BufferedInputStream(new FileInputStream("res/sound.wav")));//generate data from the file (binary data?) 
    int buffer = alGenBuffers();//generate an empty buffer 
    alBufferData(buffer,data.format,data.data,data.samplerate);//assign previously generated data to buffer 
    data.dispose();//what does this line do? (I can not understand what dispose means. Throw away or give the data?)  
    int source = alGenSources();//generate source(What does source mean here?) 
    alSourcei(source , AL_BUFFER, buffer);//set a property the the source. arg # 1 is the property type , arg # 0 is the source to set the property at and arg # 3 is the value to pass as a property. 

请帮助我成为一个更好的程序员。 问候〜张志贤

回答

1

正如你可以在这里看到:https://github.com/LWJGL/lwjgl/blob/master/src/java/org/lwjgl/util/WaveData.java data.dispose()清除不丢弃数据,但重置读/写位置(参见http://docs.oracle.com/javase/7/docs/api/java/nio/Buffer.html#clear%28%29

+0

什么其他的人ByteBuffer的?因此,在读取/写入缓冲区之前进行处理()。顺便说一句,我测试它没有data.dispose();行,它完美运行 – user3029101

+1

是的,它在这个用例很好。但想象一下,你想在应用程序中的其他位置再次传输缓冲区。您想从头开始,但缓冲区中的内部位置正指向其他位置。因此调用data.dispose。 – Peter

+0

在做alBufferData()之后还是之前再次使用它? – user3029101