Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- stb_vorbis_get_samples_short_interleaved(id, channels, pcm)
- //bufferID was generated using alGenBuffer();
- public boolean bufferData(int bufferID) {
- int samplePos = 0;
- //BUFFER_SIZE is 4096
- while (samplePos < BUFFER_SIZE) {
- //pcm is a ShortBuffer with capacity BUFFER_SIZE
- pcm.position(samplePos);
- //This causes an access violation and I have no idea why...
- int samplesPerChannel = stb_vorbis_get_samples_short_interleaved(id, channels, pcm);
- if (samplesPerChannel == 0) {
- break;
- }
- samplePos += samplesPerChannel * channels;
- }
- //Returns false if there is no data to put into the buffer
- if (samplePos == 0) {
- return false;
- }
- pcm.position(0);
- int currentBuffer = bufferID;
- //Format is AL_FORMAT_STEREO16, sampleRate is 44100
- alBufferData(currentBuffer, format, pcm, sampleRate);
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement