Bug when sending audio data to arduino

Home Forums Products NS1nanosynth Bug when sending audio data to arduino

This topic contains 6 replies, has 3 voices, and was last updated by  Niklas 3 years, 2 months ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
  • #3724


    I was trying to use the Mozzi library to add a reverb effect to the nanosynth and ran into an issue…

    In order to feed live analog audio data into Mozzi you have to set USE_AUDIO_INPUT to true in mozzi_config.h. If I do this the Nanosynth hangs after about 10s, even when using the default sketch.

    I was just wondering whether anyone else had run into this issue, or tried adding audio effects to the nanosynth leonardo board?

    BTW I filed this issue on github here in case anyone is interested: https://github.com/sensorium/Mozzi/issues/32


    Davide Mancini

    Hi there,
    I didn’t explore the audio capabilities much, but I rememebr, just as an hardware test, to have succsesfully used a plain Mozzi sketch (the filter one, IIRC) and it worked.
    When used in a more complex environment Mozzi has few peculiarities connected to his realtime nature (see the i2c problem).
    Some users here employed the mozzi libraries, though, so I’m sure it can be done!



    Thanks for the response Davide. Here’s what I tried:

    – Install Mozzi library version v1.0.3rc6 (from here: http://sensorium.github.io/Mozzi/)
    – Open mozzi_config.h and add: #define USE_AUDIO_INPUT true
    – In Arduino IDE set Board Type to Leonardo (no need for the MIDI firmware)
    – Open the Examples->Mozzi->4.Audio Input->Audio_Input_With_Knob_Filter sketch
    – Upload to nanosynth


    – nano triangle osc to A0 (audio input)
    – nano C1 to arduino A1 (controls filter cutoff)
    – arduino M-> to nano VCA input (audio output)


    I hear brief bursts of distorted noise. Changing C1 and OSC pitch do nothing to the sound output.

    Perhaps something has changed from the version of Mozzi you tested to the most current one. Any ideas on how to debug further?



    Have had the same problem as you Dondurner.

    Have not investigate things futher but I have my suspission that it has something todo with buffering audio streams (See the warnings at compile time).



    Did some quick practical testing today with USE_AUDIO_INPUT true.

    My conclutions (please correct me if I am wrong).

    getAudioInput() gives sound glitches and after like 1 minute atmega32u4 hangs.
    Instead use mozziAnalogRead(A0).

    Use the lowest resolution (AUDIO_MODE STANDARD_PLUS, AUDIO_RATE 16384 in Mozzi/mozzi_config.h) which is standard, otherwise no sound.

    Reverbtank is to much for ns1 with USE_AUDIO_INPUT true, it also gives dynamic memory warnings, atmega32u4 hangs.

    Simple AudioDelayFeedback sketch works.

    #include <MozziGuts.h>
    #include <mozzi_fixmath.h>
    #include <AudioDelayFeedback.h>
    AudioDelayFeedback <128> aDel;
    uint16_t deltime;
    byte del_samps;
    void setup(){
    void updateControl(){
      deltime = 127;
    int updateAudio(){
        int asig = mozziAnalogRead(A0);
        asig = asig - 512;
        return aDel.next(asig, deltime);
    void loop(){


    Thanks for taking a look at this Niklas. I tried your AudioDelayFeedback sketch and it works!!

    So I guess real time audio effects are really pushing the Leonardo to its limit.

    Any tips for making the delay feedback sound better? At the moment it’s very tinny and the pitch of the delay doesn’t seem to change even when the pitch of the input changes.

    Great start though – thanks!



    No problem. Just some pratical testing.

    First question, better sound quality:

    I tried to get better quality. AUDIO_MODE STANDARD_PLUS will give you 8 bit effect.
    You could try to edit Mozzi/mozzi_config.h to use AUDIO_MODE HIFI and higher AUDIO_RATE.
    I tried it but like I wrote I didn’t get any sound then. Did not investigate if arduino hanged or if the problem was in the Mozzi lib.

    Your second question is maybe about longer delay:

    The problem with delay and reverb is that it demands dynamic memory.
    Let us say that you want to have CD quality (44.1 kHz 16 bits) and at least one second delay.
    Then you need one array…

    uint16_t echo[44100];

    … to store the incoming audio.

    And I have done a little experiment with a small scetch, skipped Mozzi lib totally and used the DAC in combination with timer4… and the dynamic memory was not enought in leornardo. I had to put in down to something like 16 kHz, 12 bit for it to work.

    Now look at Mozzi smallest AUDIO_RATE 16384. Then see that a small scetch with USE_AUDIO_INPUT true takes at least 55% of dynamic memory (that is probably for the audiobuffer)!
    And then add a longer delayline on top of that, not a good idea if you ask me.

    Maybe you can hack the Mozzi lib, do something with the audiobuffer or simular.
    There are ways… But it will take allot your time.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.