{"id":3068,"date":"2021-05-03T18:17:58","date_gmt":"2021-05-03T16:17:58","guid":{"rendered":"https:\/\/www.pschatzmann.ch\/home\/?p=3068"},"modified":"2023-02-28T06:21:46","modified_gmt":"2023-02-28T05:21:46","slug":"stream-support-for-arduino-audio-tools","status":"publish","type":"post","link":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/03\/stream-support-for-arduino-audio-tools\/","title":{"rendered":"Stream support for my &#8220;Arduino Audio Tools&#8221; Library"},"content":{"rendered":"<p>Im my last couple of Blogs, I have demonstrated how we can use the low level API of my <a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\">Arduino Audio Tools<\/a> library. Currently I am busy working on a high level API using <strong>Arduino <a href=\"https:\/\/www.arduino.cc\/reference\/en\/language\/functions\/communication\/stream\/\">Streams<\/a><\/strong>.<\/p>\n<p>I did not commit my changes yet but I want to take the opportunity to share how the whole thing is supposed to work: We all know the Arduino Streams. We use them to write out print messages and sometimes we use them to read the output from Serial devices.<\/p>\n<p>The same thing applies to my &#8220;Audio Streams&#8221;: You can read audio data from &#8220;Audio Sources&#8221; and you write them to &#8220;Audio Sinks&#8221;.<\/p>\n<p>As <strong>&#8220;Audio Sources&#8221;<\/strong> we will have e.g.:<\/p>\n<ul>\n<li>Analog Microphones &#8211; AnalogStream<\/li>\n<li>Digital Microphonse &#8211; I2SStream<\/li>\n<li>Files on the Internet &#8211; UrlStream<\/li>\n<li>Generated Sound &#8211; GeneratedSoundStream<\/li>\n<li>Mobile Phone A2DP Bluetooth &#8211; A2DPStream <\/li>\n<li>Binary Data in Flash Memory &#8211; MemoryStream<\/li>\n<li>SD Files<\/li>\n<\/ul>\n<p>As <strong>&#8220;Audio Sinks&#8221;<\/strong> we will have e.g:<\/p>\n<ul>\n<li>external DAC &#8211; I2SStream<\/li>\n<li>an Amplifier &#8211; AnalogStream<\/li>\n<li>Bluetooth Speakers &#8211; A2DPStream<\/li>\n<li>Serial to display the data as CSV &#8211; CsvStream.<\/li>\n<li>SD Files<\/li>\n<\/ul>\n<p>Well &#8211; when we have an input stream from where we can read the audio data and an output stream to where we can write the data, we just need to copy from one to the other. You could program this yourself but I provide the <strong>StreamCopy<\/strong> class for this purpose.<\/p>\n<p>Here is finally an simple example that displays some Audio Data from the internet as CSV on Serial:<\/p>\n<pre><code>#include \"WiFi.h\"\n#include \"AudioTools.h\"\n\nusing namespace audio_tools;  \n\nUrlStream music;  \/\/ Music Stream\nint channels = 2; \/\/ The stream has 2 channels \nCsvStream&lt;int16_t&gt; printer(Serial, channels);  \/\/ ASCII stream \nStreamCopy copier(printer, music);    \/\/ copies music into printer\n\n\/\/ Arduino Setup\nvoid setup(void) {  \n  \/\/ Open Serial \n  Serial.begin(115200);\n\n  \/\/ connect to WIFI\n  WiFi.begin(\"network name\", \"password\");\n  while (WiFi.status() != WL_CONNECTED){\n    Serial.print(\".\");\n    delay(500); \n  }\n\n  \/\/ open music stream - it contains 2 channels of int16_t data\n  music.begin(\"https:\/\/pschatzmann.github.io\/Resources\/audio\/audio.raw\");\n}\n\n\n\/\/ Arduino loop - repeated processing \nvoid loop() {\n  copier.copy();\n}\n\n<\/code><\/pre>\n<p>The result in the <strong>Arduino Plotter<\/strong>:<br \/>\n<img decoding=\"async\" src=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/05\/serial-plotter-01-300x145.png\" alt=\"\" width=\"100%\" height=\"145\" class=\"alignnone size-medium wp-image-3069\" srcset=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/05\/serial-plotter-01-300x145.png 300w, https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/05\/serial-plotter-01-768x371.png 768w, https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/05\/serial-plotter-01.png 1155w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>I think this looks pretty cool! &#8211; I just need to spend some more time with testing before I will finally commit&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Im my last couple of Blogs, I have demonstrated how we can use the low level API of my Arduino Audio Tools library. Currently I am busy working on a high level API using Arduino Streams. I did not commit my changes yet but I want to take the opportunity [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3069,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_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-3068","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.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Stream support for my &quot;Arduino Audio Tools&quot; 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\/2021\/05\/03\/stream-support-for-arduino-audio-tools\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Stream support for my &quot;Arduino Audio Tools&quot; Library - Phil Schatzmann\" \/>\n<meta property=\"og:description\" content=\"Im my last couple of Blogs, I have demonstrated how we can use the low level API of my Arduino Audio Tools library. Currently I am busy working on a high level API using Arduino Streams. I did not commit my changes yet but I want to take the opportunity [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/03\/stream-support-for-arduino-audio-tools\/\" \/>\n<meta property=\"og:site_name\" content=\"Phil Schatzmann\" \/>\n<meta property=\"article:published_time\" content=\"2021-05-03T16:17:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-02-28T05:21:46+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/05\/serial-plotter-01.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1155\" \/>\n\t<meta property=\"og:image:height\" content=\"558\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\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=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/03\\\/stream-support-for-arduino-audio-tools\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/03\\\/stream-support-for-arduino-audio-tools\\\/\"},\"author\":{\"name\":\"pschatzmann\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"headline\":\"Stream support for my &#8220;Arduino Audio Tools&#8221; Library\",\"datePublished\":\"2021-05-03T16:17:58+00:00\",\"dateModified\":\"2023-02-28T05:21:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/03\\\/stream-support-for-arduino-audio-tools\\\/\"},\"wordCount\":291,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/03\\\/stream-support-for-arduino-audio-tools\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/serial-plotter-01.png\",\"articleSection\":[\"Arduino\",\"Machine Sound\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/03\\\/stream-support-for-arduino-audio-tools\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/03\\\/stream-support-for-arduino-audio-tools\\\/\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/03\\\/stream-support-for-arduino-audio-tools\\\/\",\"name\":\"Stream support for my \\\"Arduino Audio Tools\\\" Library - Phil Schatzmann\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/03\\\/stream-support-for-arduino-audio-tools\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/03\\\/stream-support-for-arduino-audio-tools\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/serial-plotter-01.png\",\"datePublished\":\"2021-05-03T16:17:58+00:00\",\"dateModified\":\"2023-02-28T05:21:46+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/03\\\/stream-support-for-arduino-audio-tools\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/03\\\/stream-support-for-arduino-audio-tools\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/03\\\/stream-support-for-arduino-audio-tools\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/serial-plotter-01.png\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/05\\\/serial-plotter-01.png\",\"width\":1155,\"height\":558},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/05\\\/03\\\/stream-support-for-arduino-audio-tools\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Stream support for my &#8220;Arduino Audio Tools&#8221; 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":"Stream support for my \"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\/2021\/05\/03\/stream-support-for-arduino-audio-tools\/","og_locale":"en_US","og_type":"article","og_title":"Stream support for my \"Arduino Audio Tools\" Library - Phil Schatzmann","og_description":"Im my last couple of Blogs, I have demonstrated how we can use the low level API of my Arduino Audio Tools library. Currently I am busy working on a high level API using Arduino Streams. I did not commit my changes yet but I want to take the opportunity [&hellip;]","og_url":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/03\/stream-support-for-arduino-audio-tools\/","og_site_name":"Phil Schatzmann","article_published_time":"2021-05-03T16:17:58+00:00","article_modified_time":"2023-02-28T05:21:46+00:00","og_image":[{"width":1155,"height":558,"url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/05\/serial-plotter-01.png","type":"image\/png"}],"author":"pschatzmann","twitter_card":"summary_large_image","twitter_misc":{"Written by":"pschatzmann","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/03\/stream-support-for-arduino-audio-tools\/#article","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/03\/stream-support-for-arduino-audio-tools\/"},"author":{"name":"pschatzmann","@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"headline":"Stream support for my &#8220;Arduino Audio Tools&#8221; Library","datePublished":"2021-05-03T16:17:58+00:00","dateModified":"2023-02-28T05:21:46+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/03\/stream-support-for-arduino-audio-tools\/"},"wordCount":291,"commentCount":2,"publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/03\/stream-support-for-arduino-audio-tools\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/05\/serial-plotter-01.png","articleSection":["Arduino","Machine Sound"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pschatzmann.ch\/home\/2021\/05\/03\/stream-support-for-arduino-audio-tools\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/03\/stream-support-for-arduino-audio-tools\/","url":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/03\/stream-support-for-arduino-audio-tools\/","name":"Stream support for my \"Arduino Audio Tools\" Library - Phil Schatzmann","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/03\/stream-support-for-arduino-audio-tools\/#primaryimage"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/03\/stream-support-for-arduino-audio-tools\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/05\/serial-plotter-01.png","datePublished":"2021-05-03T16:17:58+00:00","dateModified":"2023-02-28T05:21:46+00:00","breadcrumb":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/03\/stream-support-for-arduino-audio-tools\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pschatzmann.ch\/home\/2021\/05\/03\/stream-support-for-arduino-audio-tools\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/03\/stream-support-for-arduino-audio-tools\/#primaryimage","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/05\/serial-plotter-01.png","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/05\/serial-plotter-01.png","width":1155,"height":558},{"@type":"BreadcrumbList","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/05\/03\/stream-support-for-arduino-audio-tools\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pschatzmann.ch\/home\/"},{"@type":"ListItem","position":2,"name":"Stream support for my &#8220;Arduino Audio Tools&#8221; 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\/3068","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=3068"}],"version-history":[{"count":20,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/3068\/revisions"}],"predecessor-version":[{"id":5460,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/3068\/revisions\/5460"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media\/3069"}],"wp:attachment":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media?parent=3068"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/categories?post=3068"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/tags?post=3068"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}