Arduino Audio Tools
Some basic header-only C++ classes that can be used for Audio Processing provided as Arduino Library:
- We provide different "Audio Sources" and "Audio Sinks" (see next section)
- Support for different Encoders and Decoders for MP3, AAC, WAV, FLAC, etc
- Different Sound Generators (e.g. to generate a sine tone)
- Support for Sound Effects with different Effect Implementations (e.g. Boost, Distortion, Echo, Reverb...)
- Different Buffer Implementations
- Different Converters and Filters
- Musical Notes (with frequencies of notes)
- A Repeating Timer (e.g. for sampling audio data using exact times)
- Desktop Integration: Building of Arduino Audio Sketches to be run on Linux, Windows and OS/X
This functionality provides the glue which makes different audio processing components and libraries work together.
We also provide plenty of examples that demonstrate how to implement the different scenarios. The design philosophy is based on the Arduino conventions: we use the begin()
and end()
methods to start and stop the processing and we propagate the use of Streams. We all know the Arduino Streams: We usually use them to write out print messages and sometimes we use them to read the output from Serial devices. The same thing applies to “Audio Streams”: You can read audio data from “Audio Sources” and you write them to “Audio Sinks”.
As “Audio Sources” we will have e.g.:
- Digital Microphones – I2SStream
- Analog Microphones – AnalogAudioStream
- Files on the Internet – URLStream
- Streaming Internet Radios - ICYStream
- Generated Sound – GeneratedSoundStream
- Mobile Phone A2DP Bluetooth – A2DPStream
- Binary Data in Flash Memory – MemoryStream
- Audio generated by STK Framwork - STKStream
- Desktop Integration - PortAudioStream
- A Timer based Source - TimerCallbackAudioStream
- ESP32 AudioKit - AudioKitStream
- Input using FIR, IIR Filters - FilteredStream
- Tensorflow Lite - TfLiteAudioStream
- Converting Streams - VolumeStream, ResampleStream, FormatConverterStream, NumberFormatConverterStream, ChannelFormatConverterStream, ConvertedStream
- Communication - ESPNowStream, UDPStream
- Any other Arduino Classes implementing Streams: SD, Ethernet etc
As “Audio Sinks” we will have e.g:
- external DAC – I2SStream
- Analog output e.g. to an Amplifier – AnalogAudioStream
- Output using PWM – PWMAudioStream
- Output to SPDIF/TOSLINK - SPDIFStream
- Bluetooth Speakers – A2DPStream
- Serial to display the data as CSV – CsvStream
- Serial to display the data as hex dump - HexDumpStream
- Encoding and Decoding of Audio EncodedAudioStream
- Desktop Integration - PortAudioStream
- ID3 Metadata for MP3 - MetaDataID3
- A Timer based Sink - TimerCallbackAudioStream
- ESP32 AudioKit - AudioKitStream
- VS1053 Codec Module - VS1053Stream
- Callback integration e.g. with ESP8266Audio AudioOutputWithCallback
- Output using FIR, IRR Filters - FilteredStream
- Determine the Volume - VolumePrint
- Split the Output to different Destinations - MultiOutput
- 3 Band Equilizer - Equilizer3Bands
- FFT - AudioRealFFT and AudioKissFFT
- Tensorflow Lite - TfLiteAudioStream
- Converting Streams - VolumeStream, ResampleStream, FormatConverterStream, NumberFormatConverterStream, ChannelFormatConverterStream, ConvertedStream
- Communication - ESPNowStream, UDPStream
- Multiuser-Webserver for PCM Output - AudioWAVServerEx
- Any other Arduino Classes implementing Streams: SD, Ethernet etc
Examples
Here is an simple example which streams a file from the Flash Memory and writes it to I2S:
#include "AudioTools.h"
#include "StarWars30.h"
uint8_t channels = 2;
uint16_t sample_rate = 22050;
MemoryStream music(StarWars30_raw, StarWars30_raw_len);
I2SStream i2s; // Output to I2S
StreamCopy copier(i2s, music); // copies sound into i2s
void setup(){
Serial.begin(115200);
auto config = i2s.defaultConfig(TX_MODE);
config.sample_rate = sample_rate;
config.channels = channels;
config.bits_per_sample = 16;
i2s.begin(config);
}
void loop(){
if (!copier.copy()){
i2s.end();
stop();
}
}
Each stream has it's own configuration object that should be passed to the begin method. The defaultConfig() method is providing a default proposal which will usually "just work". Please consult the class documentation for the available configuration parameters. You can also easily adapt any provided examples: If you e.g. replace the I2SStream with the AnalogAudioStream class, you will get analog instead of digital output.
Further examples can be found in the Wiki.
AudioPlayer
The library also provides a versatile AudioPlayer. Further information can be found in the Wiki
Logging
The application uses a built in logger (see AudioLogger.h and AudioConfig.h). You can e.g. deactivate the logging by changing USE_AUDIO_LOGGING to false in the AudioConfig.h:
#define USE_AUDIO_LOGGING false
#define LOG_LEVEL AudioLogger::Warning
#define LOG_STREAM Serial
Per default we use the log level warning and the logging output is going to Serial. You can also change this in your sketch by calling AudioLogger begin with the output stream and the log level e.g:
AudioLogger::instance().begin(Serial, AudioLogger::Debug);
Optional Libraries
Dependent on the example you might need to install some of the following libraries:
- Many Codec Libraries which are described in the Wiki
- ESP32-A2DP Library to support A2DP Bluetooth Audio
- arduino-midi A simple MIDI message parser and generator
- Audio Boards
- arduino-audiokit Support for the ESP32 AudioKit and decoder chips (ES8388, A1S, etc)
- arduino-vs1053 Support for VS1053 audio modules
- I2S Libraries
- rp2040-i2s I2S library for MBED RP2040
- stm32f411-i2s I2S library for the stm32f411
- Audio DSP Libraries
- arduino-stk Synthesis ToolKit in C++ (STK)
- Maximilian cross-platform and multi-target audio synthesis and signal processing library
- Mozzi A sound synthesis library for Arduino
- Fast Fourier Transform
- Text To Speech
- SAM A Text to Speech Engine
- TTS A Text to Speech Engine
- flite A Text to Speech Engine
- simple-tts A Simple TTS engine using prerecorded audio (e.g. to implement Talking Clock, Talking Numbers)
- espeak-ng eSpeak NG is an open source speech synthesizer that supports more than hundred languages.
- Infrastructure
- SdFat Library to read and write files supporting SD cards with FAT16/FAT32 and exFAT
- freertos-addons elegant C++ API for FreeRTOS
- TinyHttp a http server that also supports audio for multiple users
- Machine Learning
- Tensorflow Lite Machine Learning for Arduino
Please note that this list does not show the supported libraries that are already part of the Arduino implementation: e.g. SD Library, Cmsis, Espressif DSP Library etc.
Show and Tell
Get some inspiration from projects that were using this library or share your projects with the community.
Documentation
- Here is the generated Class Documentation.
- Please also check out the Information in the Wiki
- You also might find further information in one of my Blogs
Installation in Arduino
You can download the library as zip and call include Library -> zip library. Or you can git clone this project into the Arduino libraries folder e.g. with
cd ~/Documents/Arduino/libraries
git clone pschatzmann/arduino-audio-tools.git
I recommend to use git because you can easily update to the latest version just by executing the git pull
command in the project folder.
If you want to use the library in PlatformIO, you can find a detailed description in the Wiki.
Sponsor Me
This software is totally free, but you can make me happy by rewarding me with a treat