Comments (3)
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.
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.
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)
- Compilation errors when including both WaveFolder.h and ResonantFilter.h HOT 3
- Unable to compile for Atmega328PB with Arduino IDE HOT 3
- Sample example not working on UNO R4 HOT 11
- Arduino Nano 33 IoT tested and works with the output on DAC0, which is also called A0 HOT 2
- Output frequency 0.25% off on AVRs HOT 1
- RFC: Mozzi 2.0 part 1: Single compilation unit HOT 7
- RFC: Mozzi 2.0 part 2 - Configuration restructuring HOT 7
- Improving fixMath HOT 5
- Please Change Mozzi's License HOT 10
- Using Mozzi and I2C library for LCD HOT 14
- RFC: Mozzi 2.0 part 3 - Miscellanious
- UNO R4 port broken HOT 2
- Compatability/Compilation Issues w/ Nano 33 BLE Sense HOT 5
- Apparent frequency drops when amplitude increased beyond 8 bits on AVR HOT 3
- mozzi_rand cannot go full range HOT 7
- AVR PWM range is not actually 0-488 ("8.5 bit"), but effectively 0-400 HOT 6
- Minor / infrastructure: Avoid duplicate workflow runs on pushes to PRs HOT 1
- I2S dac with a nano. HOT 12
- VS10XX as DAC HOT 38
- RFC: Analog input scaling - what's the best approach HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mozzi.