arduino-audio-tools/README.md

168 lines
15 KiB
Markdown
Raw Normal View History

2021-04-28 06:06:15 +00:00
# Arduino Audio Tools
2021-05-05 17:17:13 +00:00
Some basic __header-only C++ classes__ that can be used for __Audio Processing__ provided as __Arduino Library__:
2021-04-28 06:06:15 +00:00
2021-11-14 09:40:11 +00:00
- We provide different "Audio Sources" and "Audio Sinks" (see next section)
2022-05-15 16:50:13 +00:00
- Support for different [Encoders](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_audio_encoder.html) and [Decoders](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_audio_decoder.html) for MP3, AAC, WAV, FLAC, etc
2021-11-14 09:19:57 +00:00
- Different [Sound Generators](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_sound_generator.html) (e.g. to generate a sine tone)
- Support for [Sound Effects](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_audio_effects.html) with different [Effect Implementations](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_audio_effect.html) (e.g. Boost, Distortion, Echo, Reverb...)
2021-11-14 09:40:11 +00:00
- Different [Buffer Implementations](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_base_buffer.html)
2022-02-05 10:37:35 +00:00
- Different [Converters](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_base_converter.html) and [Filters](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_filter.html)
2021-11-14 09:40:11 +00:00
- [Musical Notes](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_musical_notes.html) (with frequencies of notes)
- A [Repeating Timer](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_timer_alarm_repeating_def.html) (e.g. for sampling audio data using exact times)
2021-08-03 16:39:54 +00:00
- Desktop Integration: Building of Arduino Audio Sketches to be run on [Linux, Windows and OS/X](https://github.com/pschatzmann/arduino-audio-tools/wiki/Running-an-Audio-Sketch-on-the-Desktop)
2021-04-28 06:06:15 +00:00
2021-04-29 20:50:28 +00:00
This functionality provides the glue which makes different audio processing components and libraries work together.
2021-06-22 14:12:01 +00:00
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](https://pschatzmann.github.io/arduino-audio-tools/html/class_stream.html): 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”.
2021-05-01 11:54:12 +00:00
2021-05-05 17:17:13 +00:00
As “Audio Sources” we will have e.g.:
2021-05-01 11:54:12 +00:00
2021-06-17 04:02:31 +00:00
- Digital Microphones [I2SStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_i2_s_stream.html)
2022-05-15 16:50:13 +00:00
- Analog Microphones [AnalogAudioStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_analog_audio_stream.html)
2021-10-09 12:09:11 +00:00
- Files on the Internet [URLStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_u_r_l_stream.html)
2021-11-27 17:56:59 +00:00
- Streaming Internet Radios - [ICYStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_i_c_y_stream.html)
2021-05-05 18:03:26 +00:00
- Generated Sound [GeneratedSoundStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_generated_sound_stream.html)
- Mobile Phone A2DP Bluetooth [A2DPStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_a2_d_p_stream.html)
- Binary Data in Flash Memory [MemoryStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_memory_stream.html)
2021-10-11 20:55:29 +00:00
- Audio generated by STK Framwork - [STKStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_s_t_k_stream.html)
2021-08-03 16:39:54 +00:00
- Desktop Integration - [PortAudioStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_port_audio_stream.html)
2021-11-14 09:40:11 +00:00
- A Timer based Source - [TimerCallbackAudioStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_timer_callback_audio_stream.html)
2021-12-14 22:36:36 +00:00
- ESP32 AudioKit - [AudioKitStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_audio_kit_stream.html)
2022-04-20 17:36:47 +00:00
- Input using FIR, IIR Filters - [FilteredStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_filtered_stream.html)
2022-04-08 09:32:23 +00:00
- Tensorflow Lite - [TfLiteAudioStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_tf_lite_audio_stream.html)
2022-06-27 11:25:22 +00:00
- Converting Streams - [VolumeStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_volume_stream.html), [ResampleStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_resample_stream.html), [FormatConverterStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_format_converter_stream.html), [NumberFormatConverterStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_number_format_converter_stream.html), [ChannelFormatConverterStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_channel_format_converter_stream.html), [ConvertedStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_converted_stream.html)
- Communication - [ESPNowStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_e_s_p_now_stream.html), [UDPStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_u_d_p_stream.html)
2021-05-07 19:48:13 +00:00
- Any other Arduino Classes implementing Streams: SD, Ethernet etc
2021-04-28 06:06:15 +00:00
2021-05-05 17:17:13 +00:00
As “Audio Sinks” we will have e.g:
2021-04-28 06:06:15 +00:00
2021-05-05 18:03:26 +00:00
- external DAC [I2SStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_i2_s_stream.html)
2022-04-20 17:36:47 +00:00
- Analog output e.g. to an Amplifier [AnalogAudioStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_analog_audio_stream.html)
- Output using PWM [PWMAudioStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_p_w_m_audio_stream_base.html)
- Output to SPDIF/TOSLINK - [SPDIFStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_s_p_d_i_f_stream.html)
2021-05-05 18:03:26 +00:00
- Bluetooth Speakers [A2DPStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_a2_d_p_stream.html)
- Serial to display the data as CSV [CsvStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_csv_stream.html)
2022-05-05 20:20:52 +00:00
- Serial to display the data as hex dump - [HexDumpStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_hex_dump_stream.html)
2021-08-05 08:15:48 +00:00
- Encoding and Decoding of Audio [EncodedAudioStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_encoded_audio_stream.html)
2021-08-03 16:39:54 +00:00
- Desktop Integration - [PortAudioStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_port_audio_stream.html)
2021-09-03 09:32:23 +00:00
- ID3 Metadata for MP3 - [MetaDataID3](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_meta_data_i_d3.html)
2021-11-14 09:40:11 +00:00
- A Timer based Sink - [TimerCallbackAudioStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_timer_callback_audio_stream.html)
2021-12-14 22:36:36 +00:00
- ESP32 AudioKit - [AudioKitStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_audio_kit_stream.html)
2022-08-23 14:13:46 +00:00
- VS1053 Codec Module - [VS1053Stream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_v_s1053_stream.html)
2021-11-14 09:40:11 +00:00
- Callback integration e.g. with ESP8266Audio [AudioOutputWithCallback](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_audio_output_with_callback.html)
2022-04-20 17:36:47 +00:00
- Output using FIR, IRR Filters - [FilteredStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_filtered_stream.html)
- Determine the Volume - [VolumePrint](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_volume_print.html)
- Split the Output to different Destinations - [MultiOutput](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_multi_output.html)
- 3 Band Equilizer - [Equilizer3Bands](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_equilizer3_bands.html)
2022-04-20 17:23:37 +00:00
- FFT - [AudioRealFFT](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_audio_real_f_f_t.html) and [AudioKissFFT](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_audio_kiss_f_f_t.html)
2022-04-20 17:36:47 +00:00
- Tensorflow Lite - [TfLiteAudioStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_tf_lite_audio_stream.html)
2022-06-27 11:25:22 +00:00
- Converting Streams - [VolumeStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_volume_stream.html), [ResampleStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_resample_stream.html), [FormatConverterStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_format_converter_stream.html), [NumberFormatConverterStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_number_format_converter_stream.html), [ChannelFormatConverterStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_channel_format_converter_stream.html), [ConvertedStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_converted_stream.html)
- Communication - [ESPNowStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_e_s_p_now_stream.html), [UDPStream](https://pschatzmann.github.io/arduino-audio-tools/html/classaudio__tools_1_1_u_d_p_stream.html)
2021-05-07 19:48:13 +00:00
- Any other Arduino Classes implementing Streams: SD, Ethernet etc
2021-05-05 17:17:13 +00:00
2022-01-28 21:41:26 +00:00
### Examples
2021-05-05 17:17:13 +00:00
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
2021-08-03 19:08:46 +00:00
StreamCopy copier(i2s, music); // copies sound into i2s
2021-05-05 17:17:13 +00:00
void setup(){
Serial.begin(115200);
2022-01-28 21:41:26 +00:00
auto config = i2s.defaultConfig(TX_MODE);
2021-05-05 17:17:13 +00:00
config.sample_rate = sample_rate;
config.channels = channels;
config.bits_per_sample = 16;
i2s.begin(config);
}
void loop(){
2021-08-03 19:08:46 +00:00
if (!copier.copy()){
2021-05-05 17:17:13 +00:00
i2s.end();
stop();
}
}
```
2022-01-28 21:41:26 +00:00
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.
2021-06-27 20:23:31 +00:00
2021-10-19 18:44:06 +00:00
Further examples can be found in the [Wiki](https://github.com/pschatzmann/arduino-audio-tools/wiki/Examples). The library also provides a versatile [AudioPlayer](https://github.com/pschatzmann/arduino-audio-tools/wiki/The-Audio-Player-Class).
2021-10-09 12:09:11 +00:00
2021-12-14 22:36:36 +00:00
2021-07-24 19:31:11 +00:00
### Logging
2021-06-22 14:01:46 +00:00
2021-06-22 14:06:26 +00:00
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:
2021-06-22 14:01:46 +00:00
```
#define USE_AUDIO_LOGGING false
2021-06-22 14:06:26 +00:00
#define LOG_LEVEL AudioLogger::Warning
#define LOG_STREAM Serial
2021-06-22 14:01:46 +00:00
```
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);
```
2021-07-24 19:31:11 +00:00
### Optional Libraries
2021-05-05 17:17:13 +00:00
Dependent on the example you might need to install some of the following libraries:
- [ESP32-A2DP Library](https://github.com/pschatzmann/ESP32-A2DP) to support A2DP Bluetooth Audio
2022-05-08 09:06:05 +00:00
- [Many Codec Libraries](https://github.com/pschatzmann/arduino-audio-tools/wiki/Encoding-and-Decoding-of-Audio) which are described in the Wiki
2022-05-15 16:50:13 +00:00
- [arduino-audiokit](https://github.com/pschatzmann/arduino-audiokit) Support for the __ESP32 AudioKit__ and decoder chips (ES8388, A1S, etc)
2022-08-23 14:13:46 +00:00
- [arduino-vs1053](https://github.com/pschatzmann/arduino-vs1053) Support for the VS1053 audio module
2021-12-18 17:22:59 +00:00
- [arduino-midi](https://github.com/pschatzmann/arduino-midi) A simple __MIDI__ message parser and generator
2022-06-22 16:05:10 +00:00
- [SAM](https://github.com/pschatzmann/arduino-SAM) A Text to Speech Engine
- [TTS](https://github.com/pschatzmann/TTS) A Text to Speech Engine
- [flite](https://github.com/pschatzmann/arduino-flite) A Text to Speech Engine
2022-02-16 15:48:43 +00:00
- [simple-tts](https://github.com/pschatzmann/arduino-simple-tts) A Simple TTS engine which is based on prerecorded audio (Talking Clock, Talking Numbers)
2021-10-11 20:48:36 +00:00
- [arduino-stk](https://github.com/pschatzmann/Arduino-STK) Synthesis ToolKit in C++ (STK)
2022-02-11 10:09:19 +00:00
- [Maximilian](https://github.com/pschatzmann/Maximilian) cross-platform and multi-target audio synthesis and signal processing library
2021-10-09 12:09:11 +00:00
- [Mozzi](https://github.com/pschatzmann/Mozzi) A sound synthesis library for Arduino
2022-05-04 14:47:48 +00:00
- [rp2040-i2s](https://github.com/pschatzmann/rp2040-i2s) I2S library for RP2040 (mbed)
2022-04-08 09:36:58 +00:00
- [Tensorflow Lite](https://github.com/pschatzmann/tflite-micro-arduino-examples) Machine Learning for Arduino
2022-04-19 15:11:00 +00:00
- [KissFFT](https://github.com/pschatzmann/kissfft) Fast Fourier Transform FFT Library
2022-05-04 14:47:48 +00:00
- [esp32-fft](https://github.com/pschatzmann/esp32-fft) Another FFT library (not only for the ESP32)
2022-05-07 14:03:36 +00:00
- [rp2040-i2s](https://github.com/pschatzmann/rp2040-i2s) I2S for MBED RP2040
2022-05-15 16:50:13 +00:00
- [SdFat Library](https://github.com/greiman/SdFat) to read and write files supporting SD cards with FAT16/FAT32 and exFAT
- [SD Library](https://www.arduino.cc/en/reference/SD) to read and write files supporting SD cards with FAT16 and FAT32
2021-04-28 16:15:42 +00:00
2021-10-19 18:44:06 +00:00
After installing a library, you might need to activate it's usage in the ```AudioConfig.h``` file!
2021-04-28 16:15:42 +00:00
2022-03-30 20:38:29 +00:00
## Show and Tell
2022-03-30 21:29:45 +00:00
Get some inspiration [from projects that were using this library](https://github.com/pschatzmann/arduino-audio-tools/discussions/categories/show-and-tell) or share your projects with the community.
2022-03-30 20:38:29 +00:00
2021-07-24 19:31:11 +00:00
### Documentation
2021-04-28 06:11:01 +00:00
2022-04-22 19:54:27 +00:00
- Here is the generated [Class Documentation](https://pschatzmann.github.io/arduino-audio-tools/html/namespaceaudio__tools.html).
2021-08-03 16:39:54 +00:00
- Please also check out the [Information in the Wiki](https://github.com/pschatzmann/arduino-audio-tools/wiki)
- You also might find further information in [one of my Blogs](https://www.pschatzmann.ch/home/category/machine-sound/)
2021-04-28 06:11:01 +00:00
2021-10-19 18:44:06 +00:00
### Installation in Arduino
2021-07-24 19:31:11 +00:00
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
2021-04-29 09:52:46 +00:00
2021-07-24 19:31:11 +00:00
```
cd ~/Documents/Arduino/libraries
git clone pschatzmann/arduino-audio-tools.git
```
2021-10-19 18:44:06 +00:00
2022-01-29 09:52:25 +00:00
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.
2022-06-22 16:05:10 +00:00
If you want to use the library in PlatformIO, you can find a [detailed description in the Wiki](https://github.com/pschatzmann/arduino-audio-tools/wiki/Working-with-PlatformIO).