Java - LWJGL - OpenAL - Understanding some code

438 views Asked by At

Hell coders , I am currently studying OpenAL with LWJGL and I can not understand what these lines of code do(the comments represent what I think they are doing , may you please tell me the right things? I have read the Javadocs and did not understood a thing . I googled and googled.)

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.

Please help me become a better programmer . Regards ~ Teo

1

There are 1 answers

3
Peter On

As you can see here : https://github.com/LWJGL/lwjgl/blob/master/src/java/org/lwjgl/util/WaveData.java data.dispose() clears the ByteBuffer which doesn't discard data but reset read/write position (see http://docs.oracle.com/javase/7/docs/api/java/nio/Buffer.html#clear%28%29)