Mozzi + MCP4921 example stutters -> error compiling with newest mozzi version

171 views
Skip to first unread message

Tarcisio León Drusin

unread,
May 31, 2021, 9:06:27 PM5/31/21
to Mozzi-users
Hi! I have been using mozzi for quite some time (it's incredible!) and wanted to "upgrade" from 2 pin PWM to a MCP4921.
I'm using an Arduino UNO with 1.8.12 IDE, I did some tests and tried the FMSynth_MCP4921 example, but it constantly stutters as if the Uno's overwhelmed.
Tried a simple sinewave and that works fine apparently.

Previously I was using Arduino IDE 1.0.5 r2 and I know it works fasterbut the newest mozzi version (with MCP4921 support) doesn't work in that IDE, don't know why, independently of the sketch, it throws some errors after compilation.

Also, I'm I going to accomplish anything replacing 2 pin PWM with a MCP4921 DAC? Is it gonna reduce anti-aliasing noise for example??

Thanks!!! :)

Compilation error from 1.0.5 r2 IDE:
In file included from C:\Program Files\Arduino-1.0.5-r2 (mozzi)\libraries\Mozzi/Oscil.h:24,
                 from Sinewave.ino:20:
C:\Program Files\Arduino-1.0.5-r2 (mozzi)\libraries\Mozzi/mozzi_pgmspace.h: In function 'T mozzi_pgm_read_wrapper(const T*)':
C:\Program Files\Arduino-1.0.5-r2 (mozzi)\libraries\Mozzi/mozzi_pgmspace.h:22: error: there are no arguments to 'static_assert' that depend on a template parameter, so a declaration of 'static_assert' must be available
C:\Program Files\Arduino-1.0.5-r2 (mozzi)\libraries\Mozzi/mozzi_pgmspace.h:22: error: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
C:\Program Files\Arduino-1.0.5-r2 (mozzi)\libraries\Mozzi/mozzi_pgmspace.h: In function 'T mozzi_pgm_read_wrapper(const T*) [with T = double]':
C:\Program Files\Arduino-1.0.5-r2 (mozzi)\libraries\Mozzi/mozzi_pgmspace.h:35: error: 'static_assert' was not declared in this scope
C:\Program Files\Arduino-1.0.5-r2 (mozzi)\libraries\Mozzi/mozzi_pgmspace.h:38: error: expected primary-expression before '{' token
C:\Program Files\Arduino-1.0.5-r2 (mozzi)\libraries\Mozzi/mozzi_pgmspace.h:38: error: expected ';' before '{' token
C:\Program Files\Arduino-1.0.5-r2 (mozzi)\libraries\Mozzi/mozzi_pgmspace.h:38: error: expected `;' before '}' token
C:\Program Files\Arduino-1.0.5-r2 (mozzi)\libraries\Mozzi/mozzi_pgmspace.h:38: error: expected primary-expression before '.' token
C:\Program Files\Arduino-1.0.5-r2 (mozzi)\libraries\Mozzi/mozzi_pgmspace.h: In function 'T mozzi_pgm_read_wrapper(const T*) [with T = uint64_t]':
C:\Program Files\Arduino-1.0.5-r2 (mozzi)\libraries\Mozzi/mozzi_pgmspace.h:38:   instantiated from here
C:\Program Files\Arduino-1.0.5-r2 (mozzi)\libraries\Mozzi/mozzi_pgmspace.h:22: error: 'static_assert' was not declared in this scope
C:\Program Files\Arduino-1.0.5-r2 (mozzi)\libraries\Mozzi/mozzi_pgmspace.h: In function 'T mozzi_pgm_read_wrapper(const T*) [with T = signed char]':
C:\Program Files\Arduino-1.0.5-r2 (mozzi)\libraries\Mozzi/mozzi_pgmspace.h:48:   instantiated from 'T FLASH_OR_RAM_READ(T*) [with T = const signed char]'
C:\Program Files\Arduino-1.0.5-r2 (mozzi)\libraries\Mozzi/Oscil.h:308:   instantiated from 'int8_t Oscil<NUM_TABLE_CELLS, UPDATE_RATE>::readTable() [with unsigned int NUM_TABLE_CELLS = 2048u, unsigned int UPDATE_RATE = 32768u]'
C:\Program Files\Arduino-1.0.5-r2 (mozzi)\libraries\Mozzi/Oscil.h:93:   instantiated from 'int8_t Oscil<NUM_TABLE_CELLS, UPDATE_RATE>::next() [with unsigned int NUM_TABLE_CELLS = 2048u, unsigned int UPDATE_RATE = 32768u]'
Sinewave.ino:42:   instantiated from here
C:\Program Files\Arduino-1.0.5-r2 (mozzi)\libraries\Mozzi/mozzi_pgmspace.h:22: error: 'static_assert' was not declared in this scope

tomco...@live.fr

unread,
Jun 1, 2021, 3:01:55 PM6/1/21
to Mozzi-users
Hi!
First things first, I think this is normal that you get a compilation error with 1.0.5: the latest changes of Mozzi made it incompatible with it I think. I think a good way to have the FM sketch working on the Uno would be to change the compilation option from -Os (optimized for the size) to -O2 or -O3 (https://www.elektormagazine.com/labs/arduino-compiler-optimizations-for-faster-smaller-code). Otherwise you might need to move to a simpler synthesis process (FM is fairly heavy!) or to a more powerful chip! The external_audio_output feature adds a small overhead when used, the FM sketch being "at the edge" on an Uno with standard output that is not surprising that it has problem to keep up…

> Also, I'm I going to accomplish anything replacing 2 pin PWM with a MCP4921 DAC? Is it gonna reduce anti-aliasing noise for example??
That is a very good question. I personally 2 pin PWM only once, and never did any sound comparison. The advantages of using a DAC are:
  - an analog output (and not PWM) so if you want something clean you'll need to filter less
  - the possibility to have more bits: I made a synth using a MCP4922 DAC and using the same technique as the dual PWM, so merging the two outputs, got a theoritical output of 24 bits depth! In reality, only between 16/18 bits were getting outside of the noise but that is way more than dual PWM. Lately I also did some tests with PT8211 16bits dual audio DAC which, when properly connected and stabilized gives very good results in term of audio quality.
 - the possibility to separate a bit more the digital parts and the analogic parts of the electronic and to be a bit less influenced by the digital noise.

That said, it won't do anything against aliasing unfortunately: the aliasing effect is coming from the sampling frequency of your signal which will be the same.
However, there are a few standard ways to deal with aliasing (not all of them are applicable to Mozzi):
 - increase the sample frequency
 - use less "harsh" wavetables or lower-frequencies
 - use band-limited wavetables: there is actually a Pull-request for a dynamic way to change between wavetables in order to remove the aliasing (https://github.com/sensorium/Mozzi/pull/124)

Hope that helps!
Tom

Tarcisio León Drusin

unread,
Jun 1, 2021, 3:20:27 PM6/1/21
to Mozzi-users
Ohhhh ok I see, have in mind changing the part in the github where it says: "If you still need more speed, Arduino 1.0.5 produces slightly faster code."

I was right now doing some test comparing 1 pin PWM vs the MPC4921 DAC and aliasing is the same, or at least for what I can hear (no technical analysis made)
But the aventajes you list seems useful as I was getting some, very little but sometimes hearable, noise in the 10-15Hz by using 2 pin PWM in a whole synth in the same pcb, that might help.

Do you think I can move to the ESP8266 to get more sample frequency and less alias?

Thank you so much for taking the time to such a complete answer, you are truly great <3

Tarcisio León Drusin

unread,
Jun 1, 2021, 6:19:56 PM6/1/21
to Mozzi-users
Just wanted to add that did some tests regarding speed optimization with IDE 1.8.12 as you sugested, and there was no way to make the FMSynth_MCP4921_mono_12bits sound without stuttering.
So I guess MCP4921 and Arduino UNO is not for complex programs
Reply all
Reply to author
Forward
0 new messages