Advertisement
Guest User

Untitled

a guest
May 27th, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. stb_vorbis_get_samples_short_interleaved(id, channels, pcm)
  2.  
  3. //bufferID was generated using alGenBuffer();
  4. public boolean bufferData(int bufferID) {
  5. int samplePos = 0;
  6. //BUFFER_SIZE is 4096
  7. while (samplePos < BUFFER_SIZE) {
  8. //pcm is a ShortBuffer with capacity BUFFER_SIZE
  9. pcm.position(samplePos);
  10. //This causes an access violation and I have no idea why...
  11. int samplesPerChannel = stb_vorbis_get_samples_short_interleaved(id, channels, pcm);
  12. if (samplesPerChannel == 0) {
  13. break;
  14. }
  15. samplePos += samplesPerChannel * channels;
  16. }
  17.  
  18. //Returns false if there is no data to put into the buffer
  19. if (samplePos == 0) {
  20. return false;
  21. }
  22. pcm.position(0);
  23. int currentBuffer = bufferID;
  24. //Format is AL_FORMAT_STEREO16, sampleRate is 44100
  25. alBufferData(currentBuffer, format, pcm, sampleRate);
  26. return true;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement