Code Monkey home page Code Monkey logo

Comments (3)

sensorium avatar sensorium commented on July 23, 2024

Hi qwester,
the clicking sound is a result of audio output buffer under-runs as the processor fails to keep up with the amount of processing required for your sketch. I know, it doesn't seem like much, 3 oscillators and a filter... One way to optimise the sketch a bit is to run the LFO at control rate and interpolate it with a Line object in updateAudio(). At the moment I'm testing this with my development version of Mozzi which is a bit heavier on the processor than the current release - on my version, this doesn't quite remove the clicking completely, but it might on the release version:

#include <MozziGuts.h>
#include <Oscil.h>
#include <tables/SIN512_int8.h>
#include <StateVariable.h>
#include <Line.h>

Oscil <SIN512_NUM_CELLS, AUDIO_RATE> sig1(SIN512_DATA);
Oscil <SIN512_NUM_CELLS, AUDIO_RATE> sig2(SIN512_DATA);
Oscil <SIN512_NUM_CELLS, CONTROL_RATE> fmVib(SIN512_DATA);
StateVariable <BANDPASS> svFilter;

Line <long> interpVibrato;

// the number of audio steps the line has to take to reach the next control value
const unsigned int AUDIO_STEPS_PER_CONTROL = AUDIO_RATE / CONTROL_RATE;

void setup(){
  startMozzi();

  fmVib.setFreq(10);
  sig1.setFreq(880);
  sig2.setFreq(440);

  svFilter.setResonance(100);
  svFilter.setCentreFreq(1500);
}


void updateControl(){
  long vibrato  = 300L * fmVib.next();
  interpVibrato.set(vibrato, AUDIO_STEPS_PER_CONTROL);
}


int updateAudio(){
  char s2 = sig2.next();
  char unfiltered = sig1.phMod(interpVibrato.next());
  int filtered = svFilter.next(unfiltered);
  return filtered;
}


void loop(){
  audioHook();
}

You also might get slightly better mileage with the LowPassFilter object.
Or you can donate to support a version of Mozzi running on the Due or Teensy 3, both with faster cpu frequencies, via the "pledgie" buttons on the Mozzi home page: http://sensorium.github.io/Mozzi/

from mozzi.

qwester1 avatar qwester1 commented on July 23, 2024

It is good workaround to use Line interpolation. But I found better solution for this annoying clicking. Not sure is it bug or just a performance optimization but in StateVariable.h variable f has type Q1n15. It is not enough to fit (411775*centre_freq)>>14 (for centre_freq>2600) thus you shift it to 15 bits (as I understand).. It is compensated when you shift only 15 bits for low and band variables in next() function.
I just changed following code in StateVariable.h and now looks that clicking sound disappear:

//f = (Q1n15)((Q16n16_2PI_centre_freq)>>(AUDIO_RATE_AS_LSHIFT+1))
f = (Q0n32)((Q16n16_2PI_centre_freq)>>(AUDIO_RATE_AS_LSHIFT));

//band += (((long)high * f)>>15)
band += (((long)high * f)>>16)

//low += (((long)band * f)>>15);
low += (((long)band * f)>>16);

I'm very inspired by this library and spent one week of my free time to fix that. :)
Suppose it may help you

from mozzi.

sensorium avatar sensorium commented on July 23, 2024

Thanks a lot for your time tracking down this problem, I appreciate it and so will others who use or continue to develop the library.

>>16, on a byte boundary, is much faster than >>15

And your effort also highlights that the frequency calculation is extremely inaccurate. I don't have a proper fix for that yet, but at least the speed issue will be addressed in the next release.

Thanks again,
Tim

from mozzi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.