{"id":5996,"date":"2023-11-25T15:59:29","date_gmt":"2023-11-25T14:59:29","guid":{"rendered":"https:\/\/www.pschatzmann.ch\/home\/?p=5996"},"modified":"2024-03-21T07:50:38","modified_gmt":"2024-03-21T06:50:38","slug":"arduino-audio-tools-communication-with-serial","status":"publish","type":"post","link":"https:\/\/www.pschatzmann.ch\/home\/2023\/11\/25\/arduino-audio-tools-communication-with-serial\/","title":{"rendered":"Arduino Audio Tools: Audio over Serial"},"content":{"rendered":"<p>So far I have always preferred to send audio using the <strong>networking functionality<\/strong> of the micro-controllers. This is usually <strong>fast and reliable<\/strong>. Many examples can be found in <a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\/tree\/main\/examples\/examples-communication\">my communications examples folder<\/a> using different protocols.<\/p>\n<h2>Using Wires<\/h2>\n<p>But we can also send audio signals over a physical wire. I prefer to use the <strong>Serial protocol<\/strong> because this is well supported across all environments.<\/p>\n<p>Just to proof the case I had a <a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\/blob\/main\/examples\/examples-communication\/serial\/send-receive\/send-receive.ino\">simple demo<\/a> which was sending some some audio via the Serial TX pin and receives them back on the RX pin in order to play it back<\/p>\n<p>Serial Communication gets <strong>unreliable at high bit rates<\/strong> and it can happen that a single byte can get lost. This has the consequence that some nice audio is turning suddenly into <strong>noise<\/strong>! A usual sample rate is 44100 samples per second. If we use stereo with 16 bit we will need a baud rate of >= 1587600 which is well above the reliable range!<\/p>\n<h2>Using 8 bit Samples<\/h2>\n<p>When we use 8 bit samples instead of 16 bits we not only can half the needed baud rate, but we also solve the issue of the lost bytes: If some bytes get lost, this will not be audible. The consequence is only that the channels get switched. In our framework we can use a codec to translate between the 8 and 16 bits. The minimum baud rate for 44100 samples stereo is 793800.<\/p>\n<p>Here is the new <a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\/blob\/main\/examples\/examples-communication\/serial\/send-8bit-receive\/send-8bit-receive.ino\">example<\/a> that uses 8 bits.<\/p>\n<p>This is by far <strong>my preferred solution<\/strong>: It is technically very <strong>simple and efficient<\/strong>!<\/p>\n<h2>Using A Codec &#8211; E.g. ADPCM<\/h2>\n<p>ADPCM is an efficient codec that we can use on micrcontrollers and that provides a compression ratio of 1:4. But here as well, any lost bytes will lead to decoding errors. I noticed in my tests that a baud rate up to 115200 is usually very reliable.<\/p>\n<p>I added some container functionality that can provide next to the <strong>audio segments<\/strong> also <strong>meta data<\/strong> and other information. The audio information is checked with a <strong>checksum<\/strong> and invalid segments are discarded.<\/p>\n<p>Here is the <a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\/blob\/main\/examples\/examples-communication\/serial\/send-adpcm_framed-receive\/send-adpcm_framed-receive.ino\">related example<\/a> that can handle <strong>stereo with 44100 samples \/ second<\/strong>.<\/p>\n<h2>Dependencies<\/h2>\n<ul>\n<li><a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\">arduino-audio-tools<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/pschatzmann\/adpcm\">adpcm<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>So far I have always preferred to send audio using the networking functionality of the micro-controllers. This is usually fast and reliable. Many examples can be found in my communications examples folder using different protocols. Using Wires But we can also send audio signals over a physical wire. I prefer [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5997,"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":[46],"class_list":["post-5996","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino","category-machine-sound","tag-communications"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Arduino Audio Tools: Audio over Serial - 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\/2023\/11\/25\/arduino-audio-tools-communication-with-serial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Arduino Audio Tools: Audio over Serial - Phil Schatzmann\" \/>\n<meta property=\"og:description\" content=\"So far I have always preferred to send audio using the networking functionality of the micro-controllers. This is usually fast and reliable. Many examples can be found in my communications examples folder using different protocols. Using Wires But we can also send audio signals over a physical wire. I prefer [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pschatzmann.ch\/home\/2023\/11\/25\/arduino-audio-tools-communication-with-serial\/\" \/>\n<meta property=\"og:site_name\" content=\"Phil Schatzmann\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-25T14:59:29+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-21T06:50:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/11\/wire.png\" \/>\n\t<meta property=\"og:image:width\" content=\"304\" \/>\n\t<meta property=\"og:image:height\" content=\"166\" \/>\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\\\/2023\\\/11\\\/25\\\/arduino-audio-tools-communication-with-serial\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/11\\\/25\\\/arduino-audio-tools-communication-with-serial\\\/\"},\"author\":{\"name\":\"pschatzmann\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"headline\":\"Arduino Audio Tools: Audio over Serial\",\"datePublished\":\"2023-11-25T14:59:29+00:00\",\"dateModified\":\"2024-03-21T06:50:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/11\\\/25\\\/arduino-audio-tools-communication-with-serial\\\/\"},\"wordCount\":356,\"commentCount\":3,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/11\\\/25\\\/arduino-audio-tools-communication-with-serial\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/wire.png\",\"keywords\":[\"Communications\"],\"articleSection\":[\"Arduino\",\"Machine Sound\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/11\\\/25\\\/arduino-audio-tools-communication-with-serial\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/11\\\/25\\\/arduino-audio-tools-communication-with-serial\\\/\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/11\\\/25\\\/arduino-audio-tools-communication-with-serial\\\/\",\"name\":\"Arduino Audio Tools: Audio over Serial - Phil Schatzmann\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/11\\\/25\\\/arduino-audio-tools-communication-with-serial\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/11\\\/25\\\/arduino-audio-tools-communication-with-serial\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/wire.png\",\"datePublished\":\"2023-11-25T14:59:29+00:00\",\"dateModified\":\"2024-03-21T06:50:38+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/11\\\/25\\\/arduino-audio-tools-communication-with-serial\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/11\\\/25\\\/arduino-audio-tools-communication-with-serial\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/11\\\/25\\\/arduino-audio-tools-communication-with-serial\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/wire.png\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2023\\\/11\\\/wire.png\",\"width\":304,\"height\":166},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/11\\\/25\\\/arduino-audio-tools-communication-with-serial\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Arduino Audio Tools: Audio over Serial\"}]},{\"@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":"Arduino Audio Tools: Audio over Serial - 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\/2023\/11\/25\/arduino-audio-tools-communication-with-serial\/","og_locale":"en_US","og_type":"article","og_title":"Arduino Audio Tools: Audio over Serial - Phil Schatzmann","og_description":"So far I have always preferred to send audio using the networking functionality of the micro-controllers. This is usually fast and reliable. Many examples can be found in my communications examples folder using different protocols. Using Wires But we can also send audio signals over a physical wire. I prefer [&hellip;]","og_url":"https:\/\/www.pschatzmann.ch\/home\/2023\/11\/25\/arduino-audio-tools-communication-with-serial\/","og_site_name":"Phil Schatzmann","article_published_time":"2023-11-25T14:59:29+00:00","article_modified_time":"2024-03-21T06:50:38+00:00","og_image":[{"width":304,"height":166,"url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/11\/wire.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\/2023\/11\/25\/arduino-audio-tools-communication-with-serial\/#article","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/11\/25\/arduino-audio-tools-communication-with-serial\/"},"author":{"name":"pschatzmann","@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"headline":"Arduino Audio Tools: Audio over Serial","datePublished":"2023-11-25T14:59:29+00:00","dateModified":"2024-03-21T06:50:38+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/11\/25\/arduino-audio-tools-communication-with-serial\/"},"wordCount":356,"commentCount":3,"publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/11\/25\/arduino-audio-tools-communication-with-serial\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/11\/wire.png","keywords":["Communications"],"articleSection":["Arduino","Machine Sound"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pschatzmann.ch\/home\/2023\/11\/25\/arduino-audio-tools-communication-with-serial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/11\/25\/arduino-audio-tools-communication-with-serial\/","url":"https:\/\/www.pschatzmann.ch\/home\/2023\/11\/25\/arduino-audio-tools-communication-with-serial\/","name":"Arduino Audio Tools: Audio over Serial - Phil Schatzmann","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/11\/25\/arduino-audio-tools-communication-with-serial\/#primaryimage"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/11\/25\/arduino-audio-tools-communication-with-serial\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/11\/wire.png","datePublished":"2023-11-25T14:59:29+00:00","dateModified":"2024-03-21T06:50:38+00:00","breadcrumb":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/11\/25\/arduino-audio-tools-communication-with-serial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pschatzmann.ch\/home\/2023\/11\/25\/arduino-audio-tools-communication-with-serial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/11\/25\/arduino-audio-tools-communication-with-serial\/#primaryimage","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/11\/wire.png","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/11\/wire.png","width":304,"height":166},{"@type":"BreadcrumbList","@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/11\/25\/arduino-audio-tools-communication-with-serial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pschatzmann.ch\/home\/"},{"@type":"ListItem","position":2,"name":"Arduino Audio Tools: Audio over Serial"}]},{"@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\/5996","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=5996"}],"version-history":[{"count":6,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/5996\/revisions"}],"predecessor-version":[{"id":6003,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/5996\/revisions\/6003"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media\/5997"}],"wp:attachment":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media?parent=5996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/categories?post=5996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/tags?post=5996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}