openal-soft icon indicating copy to clipboard operation
openal-soft copied to clipboard

Using alGetSourcei to detect processed buffers, there is always 0

Open foyego opened this issue 3 years ago • 5 comments

First of all, I created 3 buffers and filled each with 2048 bytes of PCM data, and then attached them to the source for playback. I used alGetSourcei to detect that the state of the source was always in playback state(AL_PLAYING), but the numbers of processed buffers by (alGetSourcei(m_nSourceId, AL_BUFFERS_PROCESSED, &m_nProcessedNum);) was always 0, so I could not hear the sound. I'd appreciate it if you could help me!

foyego avatar Jul 08 '22 06:07 foyego

If the source is staying in an AL_PLAYING state and not reporting any processed buffers, that sounds like you have the source set to loop. If the source is looping, no buffers will become processed since they'll be waiting to play again when the source loops. AL_LOOPING needs to be set to false (the default).

Also, 2048 bytes per buffer with 3 buffers is quite short. Assuming 16-bit stereo 44/48khz, that's about 11ms worth of audio per buffer and about 33ms total, which would have a real risk of an underrun. For streaming a buffer queue, I'd recommend at least 100ms of total buffered audio, so at least 9 buffers with 11ms of audio per buffer (or 4 buffers with 25ms of audio per buffer).

kcat avatar Jul 08 '22 07:07 kcat

Thank you for your reply! Yes, I have already set the source in a loop and the al_loop is false. I use a QT socket that continuously receives 2048 bytes of PCM data to play back (the samplerate 16K); One Buffer has 64 ms frame length data, and the three buffers have 192ms frame length. What i want is that whenever a buffer finishes playing I use [alSourceQueueBuffers] to unload it and fill it with new 2048 bytes(alBufferData) and attach it to the source(alSourceQueueBuffers).

foyego avatar Jul 08 '22 07:07 foyego

Yes, I have already set the source in a loop and the al_loop is false.

Do you mean the source is set to looping or not? If the source is set to loop, AL_BUFFERS_PROCESSED will always report 0. The source's AL_LOOPING property must be AL_FALSE to do what you want.

Is your code available to see anywhere?

kcat avatar Jul 10 '22 02:07 kcat

I think...I changed my code to evade this. However, such a phenomenon is so amazing that I may not use the right method. Thank you for your reply!!!

foyego avatar Jul 10 '22 06:07 foyego

I'm trying to diagnose a similar thing myself. I generate 8 buffers, alSourcePlay is called, my thread sits there for a second waiting but no audio comes out and buffers processed always reports 0. When I query for the state, it is AL_STOPPED.

Have tried increasing the buffer size, using 16 buffers instead, etc.

A clean test program certainly works, though, so I know it's my own fault. I just don't know what the full program is doing differently to the test. Something to do with multithreading, is my best guess.

hakanai avatar Apr 03 '24 05:04 hakanai