Skip to content

Using the Framework w o Arduino

Phil Schatzmann edited this page Dec 28, 2024 · 37 revisions

We support the use of this framework w/o the Arduino API. So you can use it e.g.

  • with a STM32 Cube IDE for STM32 programs
  • Espressif IDF
  • use it with Jupyter in the xeus-cling kernel

Overview

Just compile your program after adding this library e.g. with the help of cmake and make sure that the preprocessor variable ARDUINO is not defined!

The linker will notifiy you about any missing methods that you need to implement: They are declared in AudioLibs/NoArduino.h. Most likely you just need to provide:

  • delay() - pause in milliseconds
  • HardwareSerial:: write(const uint8_t *buffer, size_t size) - for the output of the logger
  • millis() - milliseconds since start

Jupyter

We provide quite a few sound effects and it is a challenge to test them all. In order to make my life a little bit easier I decided to make my framework usable in Jupyterlab.

xeus-cling is a Jupyter kernel for C++ based on the C++ interpreter cling and the native implementation of the Jupyter protocol xeus. So we can use the AudioTools directly in Jupyterlab with Xeus/Cling!

Further info can be found here

IDF

You can use the basic functionality of this framework in IDF. I was testing this in PlatformIO:

Example sketch main.cpp:

#include "AudioTools.h"

uint16_t sample_rate=44100;
uint8_t channels = 2;                                      // The stream will have 2 channels 
SineWaveGenerator<int16_t> sineWave(32000);                // subclass of SoundGenerator with max amplitude of 32000
GeneratedSoundStream<int16_t> sound(sineWave);             // Stream generated from sine wave
I2SStream out; 
StreamCopy copier(out, sound);                             // copies sound into i2s

// Arduino Setup
void setup(void) {  
  // start I2S
  auto config = out.defaultConfig(TX_MODE);
  config.sample_rate = sample_rate; 
  config.channels = channels;
  config.bits_per_sample = 16;
  out.begin(config);

  // Setup sine wave
  sineWave.begin(channels, sample_rate, N_B4);
}

// Arduino loop - copy sound to out 
void loop() {
  copier.copy();
}


extern "C" void app_main() {
    setup();
    while(true) loop();
}

platformio.ini

[env:esp32dev]
platform = espressif32
board = esp32dev
framework = espidf
build_unflags = -Werror=all

In the Platfomio.ini file we just make sure that we do not treat warnings as errors!

CMakeLists.txt

# This file was automatically generated for projects
# without default 'CMakeLists.txt' file.

FILE(GLOB_RECURSE app_sources ${CMAKE_SOURCE_DIR}/src/*.*)
idf_component_register(SRCS ${app_sources})

# add arduino-audio-tools
add_compile_definitions(-DESP32_CMAKE )

  • Make sure that you check out this project to the components directory or define the location of the library with include_directories
  • use -DESP32_CMAKE (which adds a costom implementation of the used Arduino functionality)
  • make sure that all necessary pins and constants are defined e.g. with add_compile_definitions

You can configure IDF by opening a PlatformIO terminal and execute pio run -t menuconfig

Clone this wiki locally