The software of the Noise Nugget is written in Ada. The Ada programming language is all about functional safety, that is, detect when the software is not doing what is supposed to do (bugs!). With Ada you know quickly and exactly what is going wrong instead of scratching you head for hours on a buffer overflow or uninitialized driver. This means less time spent debugging. And since I don't necessary have a lot time available to develop this software, every minutes counts.
The most important aspect of the software is to generate audio samples and send them to the DAC.
A sample is a 16bit signed integer that indicates the value of the audio signal at a given point in time.
The DAC is configured at 44_100 samples per seconds (CD quality). If the software fails to deliver the samples at the appropriate speed, the audio will glitch (loud pops and clicks). So this is a true real-time requirement of the system.
The samples are not sent one by one but in buffers of 512 samples * 2 bytes per samples * 2 channels (stereo), so 2048 bytes. Buffer B is filled while buffer A is transmitted, and vise versa (flip flop buffers). Samples coming from the audio input are received in a similar way. The transfer of the buffers is done via DMA so the CPU is not used during that operation, which means more time to generate the samples.
To ensure the real-time requirement, I use the Ada Ravenscar run-time. You can see it as a Real-Time Operating System (RTOS) integrated in the Ada programming language. I wrote a blog post about it if you want to see what it looks like: https://blog.adacore.com/theres-a-mini-rtos-in-my-language
There are two tasks in the system:
- The audio task, it has the highest priority because it is responsible for filling the audio buffers. This means that this task will be executed whenever there are audio buffers to fill.
- The other task is handling USB request in a polling loop. In the future this could be moved to and interrupt handler.
In terms of dependency, the drivers come from the Ada_Drivers_Library, a project I stared a couple years ago to encourage the use of Ada on micro-controllers. The audio synth is based on ada-synth-lib by Raphael Amiard.