In my AudioTools I have quite a few sound effects and it is quite a challange 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!
As a precondition I expect that you have Xeus/Cling already installed!
So, first we need to provide the path to the source code. We can use the one that we have installed for Arduino
#pragma cling add_include_path("/home/pschatzmann/Arduino/libraries/arduino-audio-tools/src")
Next we can include the application. We also add AudioLibs/Jupyter.h which provides the API for Jupyter
#include "AudioTools.h"
#include "AudioTools/AudioLibs/Jupyter.h"
Now we are ready to define the audio. Nothing special here:
int frequency = 800;
AudioInfo info(44100, 2, 16);
SineWaveGenerator<int16_t> sineWave(32000);
sineWave.begin(info, frequency);
GeneratedSoundStream<int16_t> sound(sineWave); // Stream generated from sine wave
In order to output sound in Jupyterlab we create a JupyterAudio object which defines the generated wav file name, the audio source and the number of buffers and buffer size to limit/specify then length of the generated audio.
JupyterAudio audio("test1.wav", sound, 600, 1024);
Outputting the audio object is generating a Web Audio Player
audio
We can also display the audio as a chart
audio.chart(0)
I am also supporting the Arduino SD File API
auto file = SD.open("test1.wav", FILE_READ);
file.size()
614444
file.close();
SD.remove("test1.wav");
We can use standard C++ to process or output data:
for (int j=0;j<10;j++){
std::cout << sineWave.readSample() << endl;
}
19432 16414 13183 9781 6253 2643 -1000 -4632 -8203 -11667