-
-
Notifications
You must be signed in to change notification settings - Fork 278
Using the Framework w o Arduino
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
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
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
You can use the basic functionality of this framework in IDF. I was testing this in PlatformIO: Example sketch:
#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();
}
void app_main() {
setup();
while(true) loop();
}
Related CMakeLists.txt: Define the location of the library with include_directories and use -DESP32_CMAKE and make sure that all necessary pins and constants are defined e.g. with add_compile_definitions:
# 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
include_directories("/Users/pschatzmann/Dev/Arduino/libraries/arduino-audio-tools/src")
add_compile_definitions(-DESP32_CMAKE -DUSE_I2S -DPIN_I2S_WS=1 -DPIN_I2S_BCK=2 -DPIN_I2S_DATA_IN=3 -DPIN_I2S_DATA_OUT=4 -DI2S_USE_APLL=false -DI2S_AUTO_CLEAR=true)
You can configure IDF by opening a PlatformIO terminal and execute pio run -t menuconfig