2013-12-19 31 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