Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 9 of 9

Thread: Crackling when Processor usage reaches 35%

  1. #1

    Crackling when Processor usage reaches 35%

    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 by thedreiskre; 12-18-2020 at 10:53 PM.

  2. #2
    Senior Member
    Join Date
    Nov 2012
    You're going to have to post some code which demonstrates the problem, including the "modified versions of the Waveform object".


  3. #3
    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.
    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.

  4. #4
    Senior Member
    Join Date
    Nov 2012
    Does it crackle if you use the original waveform object?


  5. #5
    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 by thedreiskre; 12-19-2020 at 12:09 PM.

  6. #6
    Senior Member
    Join Date
    Jul 2020
    Quote Originally Posted by thedreiskre View Post
    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?

  7. #7
    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.
    Last edited by thedreiskre; 12-19-2020 at 01:58 PM.

  8. #8
    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?

  9. #9
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts