Complex Output Produce Crackly Sound.

59 views
Skip to first unread message

sergio sicari

unread,
Feb 14, 2024, 11:31:11 AMFeb 14
to Mozzi-users
Hi
I'm trying to complete a sequencer synth with some controls but I have a troubles. AudioOutput play a crackly sound.
updateAudio function should be like this:

AudioOutput_t updateAudio() {
  long modulation = aSmoothIntensity.next(fm_intensity) * aModulator.next();
  int output;
  output = (int)current_vol * lpf.next(oscil.phMod(modulation)) >> 6;
  return output * gate;
}

lpf is low pass filter instance and worked fine before adding modulation; before modulation it was:

AudioOutput_t updateAudio() {
  int output;
  output = (int)current_vol * lpf.next(oscil.next()) >> 6;
  return output * gate;
}

Also now, in first snippet, If I try to remove filter part works fine; I mean follow works fine too (obviously with filter disabled):

AudioOutput_t updateAudio() {
  long modulation = aSmoothIntensity.next(fm_intensity) * aModulator.next();
  int output;
  output = (int)current_vol * oscil.phMod(modulation) >> 6;
  return output * gate;
}

Anyone can help me to solve my problem please?
Any suggestions?

Thank you in advance.



tomco...@live.fr

unread,
Feb 14, 2024, 4:49:10 PMFeb 14
to Mozzi-users
Hi!
What platform are you using? AVR being 8bitters, the behavior of types, and of certain Mozzi class will be different compared to 32bitters like the RP2040 for instance.

What is the type aSmoothIntensity is working on? Aka, what is fm_intensity? Where I am getting at is that it might be that updateAudio is a bit too heavy and cannot be run fast enough to keep the AudioRate even though it does not seem like it at first glance.

Another possible culprit could be the filter. FM generates quite weird harmonics which can badly interact with the filter if the resonance is too high. What are your filter parameters (resonance, and cutoff)?

Also, you can let Mozzi do the correct end shift if you know how many bits you have in what you return by using MonoOutput::fromNBit(N, output*gate); (this should not change anything, but that make things portable to other platforms if needed).

Best,
Tom

Andrew Row

unread,
Feb 14, 2024, 8:56:57 PMFeb 14
to Mozzi-users
Hi,  

if you're using Arduino Nano/uno etc, I would say it is likely that Tom is probably correct that updateAudio() is too heavy.  audio crackling (for me) is often caused by buffer under-run when I'm doing too much in updateAudio(). 

I would recommend calculating modulation in updateControl().  this can be done at CONTROL_RATE=256Hz or even 128 without being noticeably steppy, which saves a LOT of clock cycles vs calculating it at AUDIO_RATE.

Cheers,
Andrew

Andrew Row

unread,
Feb 14, 2024, 9:03:49 PMFeb 14
to Mozzi-users
also if gate is = 0 or 1, consider using an if statement instead of multiplication.  this may not have much effect if the AVR runtime optimises multiplications by 1 or 0, i'm not sure.


eg

if(gate == 1)
{
  return (audio code);
}
else
{
  return 0;
}

however, if you want to add an amplitude envelope instead of a gate, you can replace gate with gain, and calculate gain in updateControl() and do the multiplication in updateAudio().

Reply all
Reply to author
Forward
0 new messages