Reducing audio pops when writing into sample data in realtime

I’m wondering if there are any techniques I can use to reduce audio pops when I use Lua to write to the sample buffer while it is playing. I notice that if the changes to the sample data are small and gradual the audio is fine, however if the the value at a given sample position jumps too much there is a noticeable pop. You can replicate the issue by looping a short sample (say around 42 samples long), playing it and then drawing in the sample editor with the pen tool.

Is there a way to avoid the pops with this? I’m getting some interesting results using scripting to write the sample buffer while it is playing however the pops mean that I have to run a lowpass filter on the sound to hide the pops.

Does anyone have any clues?

That is because the Lua interpreter doesn’t really run in a realtime thread while the sample player does this and there is not much to do about it.
You might perhaps be able to do some precalculations (buffering) before you fire the play call but i can’t guarantee that this will work efficient.

However if the pops appear regardless if the sample buffer is being played during the generation or afterwards, it may be something in your algorithm is not completely working right.

I don’t think this issue is to do with the Lua running in the GUI thread, my understanding of that issue is the timing of when Lua commands are executed cannot be guaranteed.

This issue seems to be more about the way the audio engine works and I can replicate the problem when I’m not using Lua scripting at all.

Try this: generate a small single cycle waveform and loop it in the background, then while it is playing use the pen tool to draw in the sample editor. If you do this gently you can hear the sound changing, however if you draw rapidly you can occasionally hear clicks, particularly if you draw across the zero crossing, the effect is more noticeable when using lower notes.

Also if you draw values in the first sample position you hear a very different sound artefact than drawing in the second sample position. Try it you will see what I mean.

I can make it click even when drawing slowly:simply create a sample of 8 frames in size and then draw just the first frame and let it play that loop and then slowly go left or right.
I doubt this problem can be eliminated. Clicking on short samples is a known issue, it has been resolved to a certain short size of samples, but it doesn’t work on samples that only last a few frames in length.
In that regard, if you are also working in that scope of such an amount of frames, it would be most likely you hear clicks and pops when the sample is played live.

Perhaps one of the devs can shed a light on this or perhaps think of something clever to prevent those pops. It looks like this is a specific odd/even bit setting problem. When drawing the even bit frame, i don’t hear pops but when drawing the odd bit frame, the crackling appears when going up or down.

That is interesting, I get the same effect, it seems the smaller the sample the more clicks you get. The tool I’m working on uses samples that are 42 frames long and I get clicking but not as much as on the sample that is 8 frames long. Maybe there is a sample size ‘sweet spot’ that has the least clicking.

Another odd thing I noticed is that the note played also effects the amount of clicking, I get more clicks when I play a D note compared to a C note!

That is most likely because the sample is played at a higher frequency (combined with different interpolation boundaries) which also means more clicks.

Thanks, I tried turning the interpolation off and this seems to eliminate most of the clicks so I guess it must be something to do with that.