Skip to content

Running an Audio Sketch on the Desktop

Phil Schatzmann edited this page Apr 20, 2024 · 21 revisions

Sometimes it is just to tedious to deploy and test a sketch on a Microcontroller - specially when you don't have all the wires of your hardware connected or expect to run thru many validation cycles.

This project can also be used to output the sound on Linux, Windows and OS/X.

You just need to provide an Arduino Sketch together with this CMakeLists.txt file. Just replace the example generator.ino with your sketch file in the add_executable line.

Desktop Audio Output

In your sketch you can use the PortAudioStream class which uses PortAudio to input or output audio.

Alternatively you can also use the StdioStream class to input or output data (in Linux or OS/X) together with pipes: e.g. ./generator | aplay -f cd is playing the output of the generator with the help of the aplay command.

You can also use the header only MiniAudioStream.

Build Instructions

The CMakeLists.txt file automatically downloads all dependencies (including the arduino-audio-tools project).

You can build the executable with:

mkdir build
cd build
cmake ..
make

Examples

A full example can be found in the examples-desktop directory: e.g. generator

If you intend to debug, please use cmake -DCMAKE_BUILD_TYPE=Debug .. instead.

Runtime Alternatives

The example above is automatically using the Arduino-Emulator which pretty much makes the full Arduino functionality available on the desktop as well.

If you prefer to have a lean implementation w/o the Arduino functionality you can deactivate the Emulator. Here is a minimum example w/o emulator.

Output Libraries

We support different output libraries:

You can also decide not to use any Audio Library and just output the sound data to Standard Output

PipeWire

I am using PipeWire under Linux: After installing pipewire I recommend to make sure that we have some additional header files:

sudo apt-get install libasound2-dev
sudo apt install libjack-jackd2-dev
Clone this wiki locally