[Lazarus] Update sound shop my next tutoring project

Marc Weustink marc at dommelstein.nl
Thu May 16 22:34:05 CEST 2019


AW:
I will take you advice and write the samples out to a PCM wave file then examine them in audacity. Regarding the underflow, I always wipe the buffer with zeros before I play a note and the popping occurs sometimes when only one note is playing. That is when there is the least amount of processing, but you might be onto something. I am using the smallest buffer size of 512 samples and the threading system might not invoke my audio callback in time to fill the buffer before the sound should be playing. I will try to increase the buffer size which should relieve the race condition, but increasing the buffer size also increases the resolution where notes can be played making them less accurate.

MW:
512 samples, thats about 10 msec @48k, thats pretty short.
At work I work with streaming voice and we try to keep atleast 30ms of audio in the soundbuffers. And this is lowlevel winapi. I don’t know the overhead on Linux (it’s one of my todos)

AW:
And right now I just tested the buffer size and simplifying the computation of Left and Right samples. This greatly reduced the popping, so I am thinking the problem is related to my callback is taking too long to compute. That or SDL and Linux are not scheduling the audio callback as aggressively as they should. I will test on Windows with a lower end CPU (a different machine) and see if the problem presents itself there as well.

MW:
Maybe ofload the sample calculation in another thread. So you only have to feed the samples at the time ther are needed, while in the mean time you can continue to generate them

AW:
If the problem lays in my computation taking too long, perhaps I will try compiling with different optimization levels or simplifying my audio callback. I am using doubles with division and multiplication (and the Sin function with some waveforms) quite a bit during my callback. Perhaps FPC generates less than ideal instructions to perform math on the double type.


Marc
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20190516/00ab26b8/attachment.html>


More information about the lazarus mailing list