arduino-audio-tools/README.md

138 lines
8.5 KiB
Markdown
Raw Normal View History

2021-04-28 06:06:15 +00:00
# Arduino Audio Tools
2023-03-15 16:55:10 +00:00
Some basic __header-only C++ classes__ that can be used for __Audio Processing__ provided as __Arduino and cmake C++ Library__:
2021-04-28 06:06:15 +00:00
2024-03-18 10:06:27 +00:00
- We provide different ["Audio Sources" and "Audio Sinks"](https://github.com/pschatzmann/arduino-audio-tools/wiki/Audio-Sources-and-Sinks)
2023-05-01 03:24:24 +00:00
- Support for different [Encoders](https://pschatzmann.github.io/arduino-audio-tools/classaudio__tools_1_1_audio_encoder.html) and [Decoders](https://pschatzmann.github.io/arduino-audio-tools/classaudio__tools_1_1_audio_decoder.html) for MP3, AAC, WAV, FLAC, etc for [EncodedAudioStream](https://pschatzmann.github.io/arduino-audio-tools/classaudio__tools_1_1_encoded_audio_stream.html)
- Different [Sound Generators](https://pschatzmann.github.io/arduino-audio-tools/group__generator.html) (e.g. to generate a sine tone) for [GeneratedSoundStream](https://pschatzmann.github.io/arduino-audio-tools/classaudio__tools_1_1_generated_sound_stream.html)
- Support for [Sound Effects](https://pschatzmann.github.io/arduino-audio-tools/classaudio__tools_1_1_audio_effect_stream.html) with different [Effect Implementations](https://pschatzmann.github.io/arduino-audio-tools/classaudio__tools_1_1_audio_effect.html) (e.g. Boost, Distortion, Echo, Reverb...) for [AudioEffectStream](https://pschatzmann.github.io/arduino-audio-tools/classaudio__tools_1_1_audio_effect_stream_t.html)
- Different [Converters](https://pschatzmann.github.io/arduino-audio-tools/classaudio__tools_1_1_base_converter.html) for [ConverterStream](https://pschatzmann.github.io/arduino-audio-tools/classaudio__tools_1_1_converter_stream.html)
- Different [Filters](https://pschatzmann.github.io/arduino-audio-tools/classaudio__tools_1_1_filter.html) for [FilteredStream](https://pschatzmann.github.io/arduino-audio-tools/classaudio__tools_1_1_filtered_stream.html)
2023-02-12 10:04:06 +00:00
- [Musical Notes](https://pschatzmann.github.io/arduino-audio-tools/classaudio__tools_1_1_musical_notes.html) (with frequencies of notes)
2024-03-18 10:06:27 +00:00
- Different [Buffer Implementations](https://pschatzmann.github.io/arduino-audio-tools/classaudio__tools_1_1_base_buffer.html) for [QueueStream](https://pschatzmann.github.io/arduino-audio-tools/classaudio__tools_1_1_queue_stream.html)
2023-05-01 03:24:24 +00:00
- A [Repeating Timer](https://pschatzmann.github.io/arduino-audio-tools/classaudio__tools_1_1_timer_alarm_repeating.html) (e.g. for sampling audio data using exact times) for [TimerCallbackAudioStream](https://pschatzmann.github.io/arduino-audio-tools/classaudio__tools_1_1_timer_callback_audio_stream.html)
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
2024-03-18 20:22:33 +00:00
This functionality provides the glue which makes different audio processing components and [libraries](https://github.com/pschatzmann/arduino-audio-tools/wiki/Optional-Libraries) work together.
2024-03-18 09:54:13 +00:00
We also provide [plenty of examples](https://github.com/pschatzmann/arduino-audio-tools/wiki/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__.
2024-04-02 07:02:08 +00:00
We all know the [Arduino Streams](https://www.arduino.cc/reference/en/language/functions/communication/stream): 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”](https://github.com/pschatzmann/arduino-audio-tools/wiki/Audio-Sources-and-Sinks).
2024-03-18 09:54:13 +00:00
### Example
2022-01-28 21:41:26 +00:00
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:
2023-02-13 15:28:39 +00:00
```C++
2021-05-05 17:17:13 +00:00
#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);
2024-03-18 09:54:13 +00:00
music.begin();
2021-05-05 17:17:13 +00:00
}
void loop(){
2022-12-10 08:49:50 +00:00
copier.copy();
2021-05-05 17:17:13 +00:00
}
```
2023-05-01 02:35:51 +00:00
Each stream has it's own [configuration object](https://pschatzmann.github.io/arduino-audio-tools/structaudio__tools_1_1_audio_info.html) that should be passed to the begin method. The defaultConfig() method is providing a default proposal which will usually "just work". Please consult
2023-02-12 10:04:06 +00:00
the [class documentation](https://pschatzmann.github.io/arduino-audio-tools/modules.html) 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.
2022-12-10 08:49:50 +00:00
I suggest you continue to read the more [detailed introduction](https://github.com/pschatzmann/arduino-audio-tools/wiki/Introduction).
2021-06-27 20:23:31 +00:00
2022-09-16 20:27:53 +00:00
Further examples can be found in the [Wiki](https://github.com/pschatzmann/arduino-audio-tools/wiki/Examples).
2022-12-10 08:49:50 +00:00
Dependent on the example you might need to install some [addional libaries](https://github.com/pschatzmann/arduino-audio-tools/wiki/Optional-Libraries)
2022-09-16 20:27:53 +00:00
### AudioPlayer
2023-02-12 10:04:06 +00:00
The library also provides a versatile [AudioPlayer](https://pschatzmann.github.io/arduino-audio-tools/classaudio__tools_1_1_audio_player.html). Further information can be found in the [Wiki](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
2023-02-13 15:29:26 +00:00
```C++
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:
2023-02-13 15:29:26 +00:00
```C++
2021-06-22 14:01:46 +00:00
AudioLogger::instance().begin(Serial, AudioLogger::Debug);
```
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
2022-11-20 18:39:16 +00:00
## Documentation
2021-04-28 06:11:01 +00:00
2023-02-04 13:12:05 +00:00
Please use this before you raise any issue or start a discussion!
2024-01-31 15:53:35 +00:00
- Read the [Tutorial & Documentation in the Wiki](https://github.com/pschatzmann/arduino-audio-tools/wiki)
- Have a look at the [Examples](https://github.com/pschatzmann/arduino-audio-tools/wiki/Examples)
2023-02-12 10:04:06 +00:00
- Check the [Class Documentation by Topic](https://pschatzmann.github.io/arduino-audio-tools/modules.html).
- Find your class in [All Classes Alphabetically](https://pschatzmann.github.io/arduino-audio-tools/namespaceaudio__tools.html)
2021-08-03 16:39:54 +00:00
- 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
2023-08-17 07:46:39 +00:00
## Support
I spent a lot of time to provide a comprehensive and complete documentation.
So please read the documentation first and check the issues and discussions before posting any new ones on Github.
Open issues only for bugs and if it is not a bug, use a discussion: Provide enough information about
- the selected scenario/sketch
- what exactly you are trying to do
- your hardware
2023-08-29 23:26:18 +00:00
- your software version (from the Boards Manager) and library versions
2023-08-17 07:46:39 +00:00
- what exactly your problem is
to enable others to understand and reproduce your issue.
Finally, __don't__ send me any e-mails or post questions on my personal website!
2023-08-17 07:46:39 +00:00
2023-09-07 08:25:37 +00:00
Please note that discussions and issues which have already been answered before or where the answer can be found in the documentation may get deleted w/o reply.
2021-04-28 06:11:01 +00:00
2022-11-20 18:39:16 +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
2023-05-19 23:32:41 +00:00
git clone https://github.com/pschatzmann/arduino-audio-tools.git
2021-07-24 19:31:11 +00:00
```
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.
2024-02-12 07:54:01 +00:00
If you want to use the library on other patforms, you can find [further information in the Wiki](https://github.com/pschatzmann/arduino-audio-tools/wiki).
2022-11-20 18:39:16 +00:00
## Sponsor Me
This software is totally free, but you can make me happy by rewarding me with a treat
2022-11-21 08:19:12 +00:00
- [Buy me a coffee](https://www.buymeacoffee.com/philschatzh)
2022-11-20 18:39:16 +00:00
- [Paypal me](https://paypal.me/pschatzmann?country.x=CH&locale.x=en_US)