Archive 17/01/2023.

Audio artifacts on low frequency sounds

Bananaft

Hello. I’m playing with spooky ambient sounds and having some annoying issues.

To demonstrate it I made a demo, it’s script only, so you can launch it with any Urho 1.7 binary:

And here is the video of it alongside with spectrogram visualizer:

Fist issue is the fact that sound gain and panning are changing very abruptly. You can see these “steps” on spectrogram. If you pause the video, you can see, that those steps are 0.1 seconds wide.

I found this thread: Sound Issues: Crash and Flickering

Where @cadaver wrote:

Well, dammit. Worst case on good-spec PC, not cool. If anyone going to try my demo, can you please tell, if it is any different for you?

The second issue are the clicks you can hear when changing gain or panning on certain sounds. I assume, it’s a same problem, but even worse.

I tried smoothing the changes out. But first, to smooth out 10 fps problem you have to change parameters very slowly, so much it makes 3d panning useless. Second, on very low volumes changes have to be even slower. First few steps from 0 to something is always very distinct. Third, it does not fix the clicking.

I will be thankful for any advice. Is there any way to fix or work around this problems? Is there a way to force SDL chunk size? Or maybe change parameters gradually inside the chunk? What is your experience with audio system in Urho and what do you think of it?

kostik1337

Have you tried changing sound buffer length?

Bananaft

Thank you for the tip. I changed default value in Engine.cpp from 100 to 20. Is there any trade offs or possible side-effects?

Now panning is much better. But clicks are still there. There are no audible clicks only on noise
https://youtu.be/VtUkvgMJjbc

I tested various clean tones and they all have clicks. Clicks happen on low frequency sounds and clean tones because of sudden changes in amplitude. This will happen on any buffer length, even 1ms.

Here is a recorded waveform. Two clicks on the edges of chunk.
image

kostik1337

Well, until you are just playing sound without any processing, I believe it’s OK. You’ll have problems if you’ll do some on-the-fly complex processing like FFT or convolution because 20 samples cannot contain enough information about whole signal.
UPD: it’s not 20 samples but 20 ms, which means it’s 882 samples, that’s for sure enough for effects of any kind.

That’s absolutely right, and you can’t fix these clicks by just changing buffer size. I don’t know the right way to fix it, but you need to make amplitude and panning change not immediately but smoothly. Maybe you’ll need to rewrite SoundSource3D, I’m not sure.

Bananaft

Tried to go below 20ms. 9ms is the minimum before sound breaks. At lower values it is actually much better. Clicks turns into quiet crackle, but it is still petty clearly a bad thing. I was afraid, that buffer size have to be greater than or equal to frametime, but it appears, that it is not the case. Why Audio.cpp has hard coded minimum value of 20ms then? Is it illegal to go below 20? what could happen?

Yeah, for each sample inside the chunk. I wonder, how much more CPU it will require?

Modanung

Actually I would expect the SoundListener to require modification. Maybe some transform interpolation?
I dunno :balloon: