BSoundPlayer class freezes the app when filling the buffer

Hi everyone, I have a question about generating sound with the BSoundPlayer class in C++.

I’m currently trying to develop a Nintendo NES emulator, and I’ve seen that this is perhaps the best if not the only option for generating waveforms from parameters.

The problem is that if I want the sound to be clear, I need to give it a decent buffer size, and this causes the application to freeze when I fill it inside the callback function. For now, I’m only filling the buffer with samples of a sine wave. The number of samples is equal to the buffer size.

Does anyone know if I might be filling it incorrectly or if there’s an optimal solution to this problem?

Thanks in advance :wink:

1 Like

Why?

Without seeing the code…

The example in the BeBook works fine for me, without blocking anything.

One thing that is important, is the speed of the system, the audio is played back on.

If it’s a very, very slow system, you will get chopping sound or worse.

-But if the audio-system is made correctly, then it will never be able to behave that way.

Unfortunately, I am not the right guy to answer your question; I’ll leave this to those who knows more about the Haiku implementation. I’m pretty sure, though, that this issue would not be “impossible” to fix.

Sorry for this off-topic noise…

Example: If you’re generating samples in a Chrome-based browser, you will get chopping. The solution is to set priority to highest, but still that only ruins the audio less; the problems in the browsers do not go away completely Making larger buffers also helps, but it’s not the right solution - the problem here is inside the browsers, they’re not making real-time operations the highest priority.

Regarding the “how” the buffer is filled…

Do you have a “single full sine” from the beginning of the buffer to the end, and then repeating this ?

-Or do you fill in the buffer data continously ?

The first thing to try, is to have a buffer, which is only a single full sine wave (stretched to fill the entire buffer); if this chops, then there’s something weird going on.

Remember: The larger buffer you have, the more delayed the sound will be.