embedded programming (week08)

Group Assignment

  • Compare the performance and development workflows for different microcontroller families

Link to Fab Academy 2020 assessment page


As I want to make music instrumental device in my final project, I tried to see the sound libraries that can be embedded in microcontroller families. What I tried are:

  • Mozzi on Arduino UNO
  • Sonic Pi on Raspberry Pi

Mozzi

Mozzi is an audio synthesis Arduino library that can make complex audio sounds by microcontroller pin.

Install Mozzi

At first, I tried to use downloadable version from the website. However, it did not work well especially in case of using EventDelay() method (Note that Mozzi needs to use this module instead of delay() method in Arduino library.)

As a solution for above, a development version of Mozzi library on Github worked fine.

Development

There are some key tips for developing codebase using Mozzi.

  • Header files for the sound library (MozziGuts.h, Osci.h, tables/sin2048_int8.h)
  • Pre-defined functions
    • void updateControl(): This is required for control the logic
    • void updateAudio(): This is required for updating Audio code
  • audioHook() needs to be called void loop(). According to Mozzi document, "This is where the sound actually gets synthesized, running as fast as possible to fill the output buffer which gets steadily emptied at Mozzi’s audio rate. For this reason, it’s usually best to avoid placing any other code in loop()."

This is a code that I make for ringing sin wave sound. Input value from potentiometer is added to sine frequency that can make higher tone.

Sinewave_potentiometer.ino
Connection

Pre-defined pin of 9 in Arduino UNO is used to audio out.

Sine wave audio controlled by potentiometer

Sonic Pi

Sojic Pi is a code-based music creation and perfomance tool that supports multiple operating system including Raspberry Pi.

Sojic Pi is originally created by University of Cambridge Computer Lasboratory and developed as an open source project released under MIT License.

Installation

Via Raspbian package manager, we can keep Sonic Pi up-to-date.

$ sudo apt-get update
$ sudo apt-get install sonic-pi

Development

This is a code that I tried to do live coding. Based on this code for ringing basic arpeggio pattern in C Major scale, Sonic Pi can make sound sequence pattern that can be tweaked on live coding.

w08g_Sonic-Pi_trial


Live coding on Sonic-Pi