{"id":4586,"date":"2022-04-09T19:48:00","date_gmt":"2022-04-09T17:48:00","guid":{"rendered":"https:\/\/www.pschatzmann.ch\/home\/?p=4586"},"modified":"2022-04-09T19:53:38","modified_gmt":"2022-04-09T17:53:38","slug":"mixing-audio-with-the-arduino-audio-tools-library","status":"publish","type":"post","link":"https:\/\/www.pschatzmann.ch\/home\/2022\/04\/09\/mixing-audio-with-the-arduino-audio-tools-library\/","title":{"rendered":"Mixing Audio with the Arduino Audio Tools Library"},"content":{"rendered":"<p>I added some basic simple audio mixing functionality to my <a href=\"github.com\/pschatzmann\/arduino-audio-tools\">Arduino Audio Tools Library<\/a> where we can <strong>mix multiple input audio streams<\/strong> together.<\/p>\n<h2>Example Sketch<\/h2>\n<p>We just need to <strong>define a <a href=\"https:\/\/pschatzmann.github.io\/arduino-audio-tools\/html\/classaudio__tools_1_1_mixer.html\">Mixer<\/a><\/strong> and then <strong>add<\/strong> the different input streams that need to be mixed. Optionally we could define a weight parameter to the add method, which we did not do in the example below:<\/p>\n<pre><code>#include \"AudioTools.h\"\n#include \"AudioLibs\/AudioKit.h\"\n\nuint16_t sample_rate=32000;\nuint8_t channels = 2;                                       \nSineWaveGenerator&lt;int16_t&gt; sineWave1(32000);                \nSineWaveGenerator&lt;int16_t&gt; sineWave2(32000);                \nGeneratedSoundStream&lt;int16_t&gt; sound1(sineWave1); \nGeneratedSoundStream&lt;int16_t&gt; sound2(sineWave2);            \nMixer&lt;int16_t&gt; mixer;\nAudioKitStream out; \nStreamCopy copier(out, mixer);  \/\/ copies sound to i2s\n\n\/\/ Arduino Setup\nvoid setup(void) {  \n  \/\/ Open Serial \n  Serial.begin(115200);\n  AudioLogger::instance().begin(Serial, AudioLogger::Info);\n\n  \/\/ Define streams to be mixed together\n  mixer.add(sound1);\n  mixer.add(sound2);\n\n  \/\/ start I2S\n  Serial.println(\"starting I2S...\");\n  auto config = out.defaultConfig(TX_MODE);\n  config.sample_rate = sample_rate; \n  config.channels = channels;\n  config.bits_per_sample = 16;\n  out.begin(config);\n\n  \/\/ Setup sine wave\n  sineWave1.begin(channels, sample_rate, N_B4);\n  sineWave2.begin(channels, sample_rate, N_E4);\n  Serial.println(\"started...\");\n}\n\n\/\/ Arduino loop - copy sound to out \nvoid loop() {\n  copier.copy();\n}\n<\/code><\/pre>\n<p>The implementation of the Mixer class was pretty easy. We just need to sum all samples*weight  from all streams and divide by the total weight. Of cause this only works if all streams have consistent audio information (sample rate, channels, bits_per_sample) !<br \/>\nThe (potentially updated) example can also be found on <a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\/blob\/main\/examples\/examples-audiokit\/streams-generator_mixer-audiokit\/streams-generator_mixer-audiokit.ino\">Github<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I added some basic simple audio mixing functionality to my Arduino Audio Tools Library where we can mix multiple input audio streams together. Example Sketch We just need to define a Mixer and then add the different input streams that need to be mixed. Optionally we could define a weight [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":4587,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[20,22],"tags":[],"class_list":["post-4586","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino","category-machine-sound"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Mixing Audio with the Arduino Audio Tools Library - Phil Schatzmann<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pschatzmann.ch\/home\/2022\/04\/09\/mixing-audio-with-the-arduino-audio-tools-library\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Mixing Audio with the Arduino Audio Tools Library - Phil Schatzmann\" \/>\n<meta property=\"og:description\" content=\"I added some basic simple audio mixing functionality to my Arduino Audio Tools Library where we can mix multiple input audio streams together. Example Sketch We just need to define a Mixer and then add the different input streams that need to be mixed. Optionally we could define a weight [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pschatzmann.ch\/home\/2022\/04\/09\/mixing-audio-with-the-arduino-audio-tools-library\/\" \/>\n<meta property=\"og:site_name\" content=\"Phil Schatzmann\" \/>\n<meta property=\"article:published_time\" content=\"2022-04-09T17:48:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-04-09T17:53:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/04\/mixer-1.jpeg\" \/>\n\t<meta property=\"og:image:width\" content=\"275\" \/>\n\t<meta property=\"og:image:height\" content=\"183\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"pschatzmann\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"pschatzmann\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/04\\\/09\\\/mixing-audio-with-the-arduino-audio-tools-library\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/04\\\/09\\\/mixing-audio-with-the-arduino-audio-tools-library\\\/\"},\"author\":{\"name\":\"pschatzmann\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"headline\":\"Mixing Audio with the Arduino Audio Tools Library\",\"datePublished\":\"2022-04-09T17:48:00+00:00\",\"dateModified\":\"2022-04-09T17:53:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/04\\\/09\\\/mixing-audio-with-the-arduino-audio-tools-library\\\/\"},\"wordCount\":126,\"commentCount\":9,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/04\\\/09\\\/mixing-audio-with-the-arduino-audio-tools-library\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/mixer-1.jpeg\",\"articleSection\":[\"Arduino\",\"Machine Sound\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/04\\\/09\\\/mixing-audio-with-the-arduino-audio-tools-library\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/04\\\/09\\\/mixing-audio-with-the-arduino-audio-tools-library\\\/\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/04\\\/09\\\/mixing-audio-with-the-arduino-audio-tools-library\\\/\",\"name\":\"Mixing Audio with the Arduino Audio Tools Library - Phil Schatzmann\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/04\\\/09\\\/mixing-audio-with-the-arduino-audio-tools-library\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/04\\\/09\\\/mixing-audio-with-the-arduino-audio-tools-library\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/mixer-1.jpeg\",\"datePublished\":\"2022-04-09T17:48:00+00:00\",\"dateModified\":\"2022-04-09T17:53:38+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/04\\\/09\\\/mixing-audio-with-the-arduino-audio-tools-library\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/04\\\/09\\\/mixing-audio-with-the-arduino-audio-tools-library\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/04\\\/09\\\/mixing-audio-with-the-arduino-audio-tools-library\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/mixer-1.jpeg\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/04\\\/mixer-1.jpeg\",\"width\":275,\"height\":183},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/04\\\/09\\\/mixing-audio-with-the-arduino-audio-tools-library\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Mixing Audio with the Arduino Audio Tools Library\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\",\"name\":\"Phil Schatzmann Consulting\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\",\"name\":\"pschatzmann\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"width\":305,\"height\":305,\"caption\":\"pschatzmann\"},\"logo\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Mixing Audio with the Arduino Audio Tools Library - Phil Schatzmann","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pschatzmann.ch\/home\/2022\/04\/09\/mixing-audio-with-the-arduino-audio-tools-library\/","og_locale":"en_US","og_type":"article","og_title":"Mixing Audio with the Arduino Audio Tools Library - Phil Schatzmann","og_description":"I added some basic simple audio mixing functionality to my Arduino Audio Tools Library where we can mix multiple input audio streams together. Example Sketch We just need to define a Mixer and then add the different input streams that need to be mixed. Optionally we could define a weight [&hellip;]","og_url":"https:\/\/www.pschatzmann.ch\/home\/2022\/04\/09\/mixing-audio-with-the-arduino-audio-tools-library\/","og_site_name":"Phil Schatzmann","article_published_time":"2022-04-09T17:48:00+00:00","article_modified_time":"2022-04-09T17:53:38+00:00","og_image":[{"width":275,"height":183,"url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/04\/mixer-1.jpeg","type":"image\/jpeg"}],"author":"pschatzmann","twitter_card":"summary_large_image","twitter_misc":{"Written by":"pschatzmann","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/04\/09\/mixing-audio-with-the-arduino-audio-tools-library\/#article","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/04\/09\/mixing-audio-with-the-arduino-audio-tools-library\/"},"author":{"name":"pschatzmann","@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"headline":"Mixing Audio with the Arduino Audio Tools Library","datePublished":"2022-04-09T17:48:00+00:00","dateModified":"2022-04-09T17:53:38+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/04\/09\/mixing-audio-with-the-arduino-audio-tools-library\/"},"wordCount":126,"commentCount":9,"publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/04\/09\/mixing-audio-with-the-arduino-audio-tools-library\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/04\/mixer-1.jpeg","articleSection":["Arduino","Machine Sound"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pschatzmann.ch\/home\/2022\/04\/09\/mixing-audio-with-the-arduino-audio-tools-library\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/04\/09\/mixing-audio-with-the-arduino-audio-tools-library\/","url":"https:\/\/www.pschatzmann.ch\/home\/2022\/04\/09\/mixing-audio-with-the-arduino-audio-tools-library\/","name":"Mixing Audio with the Arduino Audio Tools Library - Phil Schatzmann","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/04\/09\/mixing-audio-with-the-arduino-audio-tools-library\/#primaryimage"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/04\/09\/mixing-audio-with-the-arduino-audio-tools-library\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/04\/mixer-1.jpeg","datePublished":"2022-04-09T17:48:00+00:00","dateModified":"2022-04-09T17:53:38+00:00","breadcrumb":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/04\/09\/mixing-audio-with-the-arduino-audio-tools-library\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pschatzmann.ch\/home\/2022\/04\/09\/mixing-audio-with-the-arduino-audio-tools-library\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/04\/09\/mixing-audio-with-the-arduino-audio-tools-library\/#primaryimage","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/04\/mixer-1.jpeg","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/04\/mixer-1.jpeg","width":275,"height":183},{"@type":"BreadcrumbList","@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/04\/09\/mixing-audio-with-the-arduino-audio-tools-library\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pschatzmann.ch\/home\/"},{"@type":"ListItem","position":2,"name":"Mixing Audio with the Arduino Audio Tools Library"}]},{"@type":"WebSite","@id":"https:\/\/www.pschatzmann.ch\/home\/#website","url":"https:\/\/www.pschatzmann.ch\/home\/","name":"Phil Schatzmann Consulting","description":"","publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pschatzmann.ch\/home\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1","name":"pschatzmann","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","width":305,"height":305,"caption":"pschatzmann"},"logo":{"@id":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png"}}]}},"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/4586","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/comments?post=4586"}],"version-history":[{"count":7,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/4586\/revisions"}],"predecessor-version":[{"id":4594,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/4586\/revisions\/4594"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media\/4587"}],"wp:attachment":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media?parent=4586"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/categories?post=4586"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/tags?post=4586"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}