Crackling when Processor usage reaches 35%

Status
Not open for further replies.

thedreiskre

Active member
I am working on a project with many audio objects, in situations where they are all active and the CPU usage rises significantly - the audio starts to crackle and pop.
I have found that when the processor usage is below ~35% (using AudioProcessorUsageMax ) there is no crackling and the audio is very clean. However when processor usage
increases above this there is a significant amount of crackling. I have found that the 'crackling' does not come from the usb audio out, but rather from individual objects.
I am using modified versions of the Waveform object and they seem to be the most notable affected, as some will noticeably crackle while others remain unaffected.
The maximum memory usage is 228 blocks.
Any help in solving this problem would be much appreciated.
 
Last edited:
You're going to have to post some code which demonstrates the problem, including the "modified versions of the Waveform object".

Pete
 
https://pastebin.com/AFwSNX0m
This is the modified part of waveform object. It adds pulse width modulation and 'oscillator sync' to the arbitrary waveform.
There are some added variables in the header for this as well.

https://pastebin.com/tZhdcH4n
These are the other audio objects in use.

The rest of the code is pretty reliant on external hardware so I dont think it would be worth attaching as to replicate it would need
lots of hardware. I can record an audio file if it would be helpful.
 
No it doesn't crackle when using the original waveform object. Though I suspect this is because the modified one is more CPU heavy. I tested removing my edits to the waveform object and adding a pointless (but CPUintensive) calculation to it. The same crackling occurred then. I also tested by increasing cpu load using other effects and this also caused the crackling sound. If this is a problem of processor usage - is there a way to use a higher percentage of cpu time without the audio starting to crackle? also, could this be to do with the fact that i am using usb audio?
 
Last edited:
https://pastebin.com/AFwSNX0m
This is the modified part of waveform object. It adds pulse width modulation and 'oscillator sync' to the arbitrary waveform.
There are some added variables in the header for this as well.
Need to see all the changes, not just the highlights. Is there a git branch for this? The declaration of
the variable ph64 is crucial to understanding this code.

BTW you should move the switch outside the loop, duplicating the loop, its probably breaking a whole
host of compiler optimizations that the original code benefitted from - conditionals are less amenable
to optimization. The multiplication may also be a problem as you are avoiding using the multiply_32x32_rshift32
primitive and might be calling out-of-line for a generic 64 bit multiply?
 
Thanks for the suggestions mark, I have moved the switch outside of the loop as you suggested as well as slightly optimizing the oscillator sync. The crackling is still noticeable if I play a lot of notes as well as using 'oscillator sync' on more than 1 waveform. I just ran a test where i didnt use pulse width modulation or oscillator sync, and instead just did some useless (but cpu intensive calculations), i got the cpu usage up to 77% and got some serious crackling sound coming from it.
I have just made a branch for this on github. https://github.com/LawrenceBradshaw/Audio
 
Last edited:
I overclocked my teensy 4 up to 816Mhz, This reduced the CPU load below 35%. So even use my all of my modifications, there was no crackling. Could having code in the loop() be perhaps causing this by interrupting the audio library?
 
SOLVED !!
The problem (which I still dont entirely understand) was to do with using output i2s and output usb at the same time.
As per the instruction "At least one non-USB input or output object must be present for the entire library to update properly." I had added an output i2s object to my sketch.
When I removed this an replaced it with an input i2s - The crackling stopped. The most probable cause is that the audio board currently attached to my teensy 4 is broken, so
perhaps the teensy trying to communicate with it via i2s was causing some kind of issue.
 
Status
Not open for further replies.
Back
Top