BirdNet-goMikrofon/Arduino-audio-tools-main/arduino-audio-tools-main/jupyter/Jupyter.ipynb

263 lines
2.1 MiB
Text
Raw Permalink Normal View History

2026-09-26 01:20:55 +02:00
{
"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<int16_t> sineWave(32000); \n",
"sineWave.begin(info, frequency);\n",
"GeneratedSoundStream<int16_t> 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": [
"<audio controls src='data:audio/wav;base64,UklGRhwA/39XQVZFZm10IBAAAAABAAIARKwAABCxAgAEABAAZGF0YSQA/38AAAAANw43Dj8cPxzqKeopCTcJN3FDcUP5TvlOe1l7WdRi1GLkauRqkXGRccV2xXZuem56gXyBfPZ89nzLe8t7BnkGea50rnTTbtNuh2eHZ+Re5F4FVQVVDEoMSh0+HT5fMV8x/iP+IyQWJBYCCAIIxfnF+Z3rneu43bjdRdBF0HHDccNlt2W3S6xLrEeiR6J7mXuZA5IDkvmL+Ytwh3CHd4R3hBmDGYNag1qDOYU5hbCIsIizjbONMpQylBicGJxJpUmlp6+nrxG7Ebtfx1/HatRq1AXiBeIF8AXwOf45/nIMcgyDGoMaOyg7KG41bjXwQfBBlk2WTTtYO1i6Ybph9Wn1adBw0HA0djR2D3oPelV8VXz+fP58B3wHfHV5dXlOdU51o2+jb4RohGgKYApgUVZRVnlLeUunP6c/ATMBM7ElsSXkF+QXyAnICY37jftf7V/tb99v3+vR69EBx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omCicCFwIWUg5SDBoMGgxaEFoTChsKGAosCi8WQxZD7l/uXiaCJoFWqVao+tT61H8EfwdHN0c0q2yrb/ej96Bz3HPdYBVgFhBOEE24hbiHpLukuyTvJO+JH4kcMUwxTIl0iXQNmA2aRbZFtsnOyc1R4VHhme2Z73XzdfLZ8tnzxevF6k3eTd6hyqHJAbEBscGRwZFJbUlsGUQZRrEWsRWo5ajlqLGos1h7WHtwQ3BCqAqoCcPRw9FvmW+ac
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"audio"
]
},
{
"cell_type": "markdown",
"id": "918279d1-fd4d-43fd-b4b3-436d07b8972f",
"metadata": {},
"source": [
"We can also display the audio as a chart"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "ffb5ae33-399f-4db2-9c55-2141a52da62d",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<style>div.x-svg {width: 102400px; }</style><div class='x-svg'><svg viewBox='0 0 102400 100'> <polyline fill='none' stroke='blue' stroke-width='1' points ='0,60 1,63 2,67 3,70 4,74 5,77 6,80 7,82 8,85 9,87 10,89 11,90 12,91 13,91 14,91 15,91 16,90 17,89 18,88 19,86 20,84 21,81 22,78 23,75 24,72 25,69 26,65 27,62 28,59 29,55 30,52 31,48 32,45 33,42 34,39 35,37 36,34 37,32 38,31 39,30 40,29 41,29 42,29 43,29 44,30 45,31 46,33 47,35 48,37 49,40 50,43 51,46 52,49 53,53 54,56 55,60 56,63 57,66 58,70 59,73 60,76 61,79 62,82 63,85 64,87 65,88 66,90 67,91 68,91 69,91 70,91 71,91 72,90 73,88 74,86 75,84 76,82 77,79 78,76 79,73 80,69 81,66 82,62 83,59 84,56 85,52 86,49 87,45 88,42 89,39 90,37 91,35 92,33 93,31 94,30 95,29 96,29 97,29 98,29 99,30 100,31 101,33 102,35 103,37 104,40 105,42 106,46 107,49 108,52 109,56 110,60 111,62 112,66 113,69 114,73 115,76 116,79 117,82 118,84 119,86 120,88 121,90 122,91 123,91 124,91 125,91 126,91 127,90 128,88 129,87 130,84 131,82 132,79 133,76 134,73 135,70 136,66 137,62 138,60 139,56 140,53 141,49 142,46 143,43 144,40 145,37 146,35 147,33 148,31 149,30 150,29 151,29 152,29 153,29 154,30 155,31 156,32 157,34 158,37 159,39 160,42 161,45 162,48 163,52 164,56 165,59 166,62 167,65 168,69 169,72 170,76 171,79 172,81 173,84 174,86 175,88 176,89 177,91 178,91 179,91 180,91 181,91 182,90 183,88 184,87 185,85 186,82 187,80 188,77 189,73 190,70 191,67 192,63 193,60 194,57 195,53 196,50 197,46 198,43 199,40 200,37 201,35 202,33 203,31 204,30 205,29 206,29 207,29 208,29 209,30 210,31 211,32 212,34 213,36 214,39 215,42 216,45 217,48 218,52 219,55 220,59 221,61 222,65 223,68 224,72 225,75 226,78 227,81 228,84 229,86 230,88 231,89 232,90 233,91 234,91 235,91 236,91 237,90 238,89 239,87 240,85 241,83 242,80 243,77 244,74 245,70 246,67 247,63 248,60 249,57 250,53 251,50 252,47 253,43 254,40 255,38 256,35 257,33 258,32 259,30 260,29 261,29 262,29 263,29 264,29 265,31 266,32 267,34 268,36 269,39 270,41 271,44 272,48 273,51 274,55 275,58 276,61 277,64 278,68 279,72 280,75 281,78 282,81 283,83 284,86 285,88 286,89 287,90 288,91 289,91 290,91 291,91 292,90 293,89 294,87 295,85 296,83 297,80 298,77 299,74 300,71 301,67 302,64 303,60 304,58 305,54 306,50 307,47 308,44 309,41 310,38 311,36 312,33 313,32 314,30 315,29 316,29 317,29 318,29 319,29 320,30 321,32 322,34 323,36 324,38 325,41 326,44 327,47 328,51 329,54 330,58 331,60 332,64 333,68 334,71 335,74 336,78 337,80 338,83 339,85 340,87 341,89 342,90 343,91 344,91 345,91 346,91 347,90 348,89 349,87 350,85 351,83 352,81 353,78 354,75 355,71 356,68 357,64 358,61 359,58 360,54 361,51 362,47 363,44 364,41 365,38 366,36 367,34 368,32 369,30 370,29 371,29 372,29 373,29 374,29 375,30 376,32 377,33 378,35 379,38 380,41 381,44 382,47 383,50 384,54 385,57 386,60 387,64 388,67 389,71 390,74 391,77 392,80 393,83 394,85 395,87 396,89 397,90 398,91 399,91 400,91 401,91 402,90 403,89 404,88 405,86 406,83 407,81 408,78 409,75 410,72 411,68 412,65 413,61 414,58 415,55 416,51 417,48 418,45 419,42 420,39 421,36 422,34 423,32 424,31 425,30 426,29 427,29 428,29 429,29 430,30 431,31 432,33 433,35 434,38 435,40 436,43 437,46 438,50 439,53 440,57 441,60 442,63 443,67 444,70 445,74 446,77 447,80 448,82 449,85 450,87 451,89 452,90 453,91 454,91 455,91 456,91 457,90 458,89 459,88 460,86 461,84 462,81 463,78 464,75 465,72 466,69 467,65 468,62 469,59 470,55 471,52 472,48 473,45 474,42 475,39 476,37 477,34 478,32 479,31 480,30 481,29 482,29 483,29 484,29 485,30 486,31 487,33 488,35 489,37 490,40 491,43 492,46 493,49 494,53 495,56 496,60 497,63 498,66 499,70 500,73 501,76 502,79 503,82 504,85 505,87 506,88 507,90 508,91 509,91 510,91 511,91 512,91 513,90 514,88 515,86 516,84 517,82 518,79 519,76 520,73 521,69 522,66 523,62 524,59 525,56 526,52 527,49 528,45 529,42 530,39 531,37 532,35 533,33 534,31 535,30 536,29 537,29 538,29 539,29 540,30 541,31 542,33 543,35 544,37 545,40 546,42 547,46 548,49 549,52 550,56 551,60 552,62 553,66 554,69 555,73 556,76 557,79 558,82 559,84 560,86 561,88 562,90 563,91 564,91 565,91 566,91 567,91 568,90 569,88 570,87 571,84 572,82 573,79 574,76 575,73 576,70 57
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"audio.chart(0)"
]
},
{
"cell_type": "markdown",
"id": "141d652c-f3f4-4d6b-abc4-c9ba519e4597",
"metadata": {},
"source": [
"## Files\n",
"\n",
"I am also supporting the Arduino SD File API"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "768e9948-acf8-486f-8227-aaa7cd23dad2",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"614444"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"auto file = SD.open(\"test1.wav\", FILE_READ);\n",
"file.size()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "415b514d-b2ff-44dd-8f5f-05becc5f206c",
"metadata": {},
"outputs": [],
"source": [
"file.close();\n",
"SD.remove(\"test1.wav\");"
]
},
{
"cell_type": "markdown",
"id": "40b295e0-7e94-449e-aa5a-794c2a951023",
"metadata": {},
"source": [
"## Using C++\n",
"\n",
"We can use standard C++ to process or output data:"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "9996ea70-d774-4c79-b7d0-945aa9b85037",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"19432\n",
"16414\n",
"13183\n",
"9781\n",
"6253\n",
"2643\n",
"-1000\n",
"-4632\n",
"-8203\n",
"-11667\n"
]
}
],
"source": [
"for (int j=0;j<10;j++){\n",
" std::cout << sineWave.readSample() << endl;\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "710d17a0-137f-4b06-afb3-bd9b4f111108",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "C++17",
"language": "C++17",
"name": "xcpp17"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".cpp",
"mimetype": "text/x-c++src",
"name": "c++",
"version": "17"
},
"widgets": {
"application/vnd.jupyter.widget-state+json": {
"state": {},
"version_major": 2,
"version_minor": 0
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}