arduino-audio-tools/README.md
Phil Schatzmann d3f97d1cfe readme
2021-11-14 10:25:25 +01:00

8.9 KiB
Raw Blame History

Arduino Audio Tools

Some basic header-only C++ classes that can be used for Audio Processing provided as Arduino Library:

  • a simple I2S class (to read and write to the internal I2S)
  • a simple ADC class (to read analog data with the help of I2S)
  • a simple PWM class (to write audio data with the help of PWM)
  • Additional Stream implementations: MemoryStream, URLStream, I2SStream, A2DPStream, PrintStream etc
  • Support for different Encoders and Decoders for AAC, MP3 and WAV
  • Different Converters
  • Musical Notes (with frequencies of notes)
  • 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
  • A repeating timer (e.g. for sampling audio data using exact times)
  • The AudioOutputWithCallback class to provides callback integration e.g. with ESP8266Audio
  • 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.:

As “Audio Sinks” we will have e.g:

Here is an simple example which streams a file from the Flash Memory and writes it to I2S:

#include "AudioTools.h"
#include "StarWars30.h"

using namespace audio_tools;  

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);

    I2SConfig 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();
    }
}

Examples

Further examples can be found in the Wiki. The library also provides a versatile AudioPlayer.

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:

After installing a library, you might need to activate it's usage in the AudioConfig.h file!

Documentation

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

If you want to use the library in PlatformIO, you can find a detailed description in the Wiki.