openal-soft
openal-soft copied to clipboard
Using alGetSourcei to detect processed buffers, there is always 0
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!
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).
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).
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?
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!!!
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.