{ "cells": [ { "cell_type": "markdown", "id": "4947d692-812c-4ab1-958e-ac078226707d", "metadata": {}, "source": [ "## Using the Arduino Audio Tools in Xeus Jupyterlab\n", "\n", "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__. \n", "\n", "__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!\n", "\n", "As a precondition I expect that you have [Xeus/Cling](https://xeus-cling.readthedocs.io/en/latest/installation.html) already installed!\n", "\n", "So, first we need to provide the path to the source code. We can use the one that we have installed\n", "for Arduino" ] }, { "cell_type": "code", "execution_count": 1, "id": "ad51983a-9850-4087-910b-5aaf804b2a1d", "metadata": {}, "outputs": [], "source": [ "#pragma cling add_include_path(\"/home/pschatzmann/Arduino/libraries/arduino-audio-tools/src\")" ] }, { "cell_type": "markdown", "id": "6dec0d25-47be-454e-b323-cce0eefa47f1", "metadata": {}, "source": [ "Next we can include the application. We also add AudioLibs/Jupyter.h which provides the API for Jupyter" ] }, { "cell_type": "code", "execution_count": 2, "id": "2718c3e1-a7f2-4ea2-a649-2e045165f418", "metadata": {}, "outputs": [], "source": [ "#include \"AudioTools.h\"\n", "#include \"AudioTools/AudioLibs/Jupyter.h\"" ] }, { "cell_type": "markdown", "id": "55c292df-9cfb-4e74-9b4f-f625bb2f8d38", "metadata": {}, "source": [ "## Audio API\n", "Now we are ready to define the audio. Nothing special here:" ] }, { "cell_type": "code", "execution_count": 3, "id": "42fb7892-a018-4db1-98b1-0ed52cc2d1e3", "metadata": {}, "outputs": [], "source": [ "int frequency = 800;\n", "AudioInfo info(44100, 2, 16);\n", "SineWaveGenerator sineWave(32000); \n", "sineWave.begin(info, frequency);\n", "GeneratedSoundStream sound(sineWave); // Stream generated from sine wave\n" ] }, { "cell_type": "markdown", "id": "6a843236-31a6-4d6c-8f8b-81922ad90d7c", "metadata": {}, "source": [ "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." ] }, { "cell_type": "code", "execution_count": 4, "id": "f589d58e-1c76-498e-a25d-c9f23c3c55fe", "metadata": {}, "outputs": [], "source": [ "JupyterAudio audio(\"test1.wav\", sound, 600, 1024);" ] }, { "cell_type": "markdown", "id": "f004d04c-e257-43b4-a6f7-bc49104f2028", "metadata": {}, "source": [ "Outputting the audio object is generating a Web Audio Player" ] }, { "cell_type": "code", "execution_count": 5, "id": "f8d797e4-66e5-4f38-ac6d-35b52ada5c90", "metadata": {}, "outputs": [ { "data": { "text/html": [ "