sensorium / Mozzi

sound synthesis library for Arduino

Home Page:https://sensorium.github.io/Mozzi/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problems with compiler optimization options / Mozzi example sketches not working

ChrisVeigl opened this issue · comments

hi,

when trying Mozzi with an Arduino UNO (ATmega328), I found that many examples did not work as intended,
even 01.Basics->Control_Gain didn't actually change the gain of the sinewave!

After adding a Serial.print (gain) in the audio loop it worked,
which indicated that the gcc/g++ compiler incorrectly strips away the variable access during optimization (without the print call).

Strange enough, a volatile declaration of gain did not help, but when i changed the overall optimization options in the platform.txt file to O1, all example files worked correctly!

did somebody experience that problem ?
(i am using Arduino IDE 1.8.13 - current version 1.8.15 does not seem to be different in this regard).

here the line in platform.txt which i had to modify (Os was changed to O1):

compiler.cpp.flags=-c -g -O1 {compiler.warning_flags} -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto

(note that O2 and O3 did not work either, and O0 produced huge code size which prevented larger sketches from working)

Hi Chris,
thanks for the report. An extra ")" had found its way into the Control_Gain example, which stopped it compiling here. That's now fixed in the repo, and the sketch works for me.
I tried a few examples, but didn't come across any others that were broken. Do let me know which ones aren't working, if you notice more problems.
I'll try to find time to look at the optimisation issues.

thank you for the reply - and for fixing the example code :-)

there must be some other reason though, because on my end i could compile everything without problems, but many sketches did not work as expected (unless i change the compiler options to -O1, which unfortunalty can only be accomplished in the Arduino "IDE" by changing the platform.txt file, thereby influencing also the optimization settings for other sketches ...)

I tried on different machines, same problem.
But I did not test different Arduino IDE versions... so maybe related to that...

Which version do you use ?

version 1.8.13 at the moment

I am using the same version...
strange enough !

attached you find the hex file compiled with -Os (standard, not working for me in various sketches / scenarios) and a version compiled with -O1 (works for me).

hexfiles.zip

if this is not relevant for other people
we can close the issue ...