{"id":5172,"date":"2022-11-25T10:26:55","date_gmt":"2022-11-25T09:26:55","guid":{"rendered":"https:\/\/www.pschatzmann.ch\/home\/?p=5172"},"modified":"2022-11-25T16:06:50","modified_gmt":"2022-11-25T15:06:50","slug":"arduino-audio-tools-multicore-processing","status":"publish","type":"post","link":"https:\/\/www.pschatzmann.ch\/home\/2022\/11\/25\/arduino-audio-tools-multicore-processing\/","title":{"rendered":"Arduino Audio Tools &#8211; Multicore Processing"},"content":{"rendered":"<p>So far I never needed to use any of the <strong>ESP32 multicore functionality<\/strong> because all the examples are very simple and everything is fitting on a single core. However if you write some more complex scenarios which are e.g. updating a screen, process user input w\/o impacting the audio, you should consider to use <strong>multiple tasks<\/strong>. Then you need to use a <strong>save<\/strong> way to communicate data <strong>between the tasks<\/strong>.<\/p>\n<p>In this case I <strong>strongly recommend<\/strong> to use the <a href=\"https:\/\/github.com\/pschatzmann\/arduino-freertos-addons\">arduino-freertos-addons<\/a> which provides all the functionality you need in an elegant way: Just read the Readme of the project.<\/p>\n<p>Unfortunately a FreeRTOS <strong>StreamBuffer<\/strong> was missing and I also wanted to have a platform independent solution, so I have added some additional functionality to my audio-tools:<\/p>\n<ul>\n<li><a href=\"https:\/\/pschatzmann.github.io\/arduino-audio-tools\/html\/classaudio__tools_1_1_synchronized_buffer_r_t_o_s.html\">SynchronizedBufferRTOS<\/a>: a FreeRTOS StreamBuffer implementation using the BaseBuffer API<\/li>\n<li><a href=\"https:\/\/pschatzmann.github.io\/arduino-audio-tools\/html\/classaudio__tools_1_1_mutex.html\">Mutex<\/a>: with different implementations per platform.<\/li>\n<li><a href=\"https:\/\/pschatzmann.github.io\/arduino-audio-tools\/html\/classaudio__tools_1_1_lock_guard.html\">LockGuard<\/a>: a RAII class for managing the Mutex<\/li>\n<li><a href=\"https:\/\/pschatzmann.github.io\/arduino-audio-tools\/html\/classaudio__tools_1_1_synchronized_buffer.html\">SynchronizedBuffer<\/a>: which allows you to use any BaseBuffer implementation in a save way<\/li>\n<\/ul>\n<h2>SynchronizedBufferRTOS<\/h2>\n<p>If you use an ESP32, it is much more efficient to use a FreeRTOS StreamBuffer. Just write the data with <strong>writeArray()<\/strong> on one Task and read it back with <strong>readArry()<\/strong> from the other task. It is the same API you would use with any other class which is based on <a href=\"https:\/\/pschatzmann.github.io\/arduino-audio-tools\/html\/classaudio__tools_1_1_base_buffer.html\">BaseBuffer<\/a><\/p>\n<pre><code>#include \"AudioLibs\/SynchronizedBuffer.h\"\n\nSynchronizedBufferRTOS&lt;int16_t&gt; buffer(2048, 512);\n<\/code><\/pre>\n<p>In my test sketch I was measuring a thruput of 36.57-37.93 Mbytes per second.<\/p>\n<h2>SynchronizedBuffer<\/h2>\n<p>Here is an example how to use the SynchronizedBuffer class. Just wrap one of the existing buffer classes. Here is an example of a thread-save  <strong>Double Buffer<\/strong>:<\/p>\n<pre><code>#include \"AudioLibs\/SynchronizedBuffer.h\"\n\naudio_tools::Mutex mutex;\nNBuffer&lt;int16_t&gt; nbuffer(512,2);\nSynchronizedBuffer&lt;int16_t&gt; buffer(nbuffer, mutex);\n<\/code><\/pre>\n<p>In my test sketch this was giving a thuput of only 1.68 Mbytes per second.<\/p>\n<p>Here is a thread-save <strong>RingBuffer<\/strong><\/p>\n<pre><code>#include \"AudioLibs\/SynchronizedBuffer.h\"\n\naudio_tools::Mutex mutex;\nRingBuffer&lt;int16_t&gt; nbuffer(512*4);\nSynchronizedBuffer&lt;int16_t&gt; buffer(nbuffer, mutex);\n<\/code><\/pre>\n<p>and I was measuring 2.35 Mbytes per second.<\/p>\n<h2>Examples<\/h2>\n<ul>\n<li><a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\/blob\/main\/examples\/examples-basic-api\/base-SynchronizedBufferRTOS\/base-SynchronizedBufferRTOS.ino\">SynchronizedBufferRTOS<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\/tree\/main\/examples\/tests\/concurrency\">Tests<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>So far I never needed to use any of the ESP32 multicore functionality because all the examples are very simple and everything is fitting on a single core. However if you write some more complex scenarios which are e.g. updating a screen, process user input w\/o impacting the audio, you [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5104,"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-5172","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>Arduino Audio Tools - Multicore Processing - 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\/11\/25\/arduino-audio-tools-multicore-processing\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Arduino Audio Tools - Multicore Processing - Phil Schatzmann\" \/>\n<meta property=\"og:description\" content=\"So far I never needed to use any of the ESP32 multicore functionality because all the examples are very simple and everything is fitting on a single core. However if you write some more complex scenarios which are e.g. updating a screen, process user input w\/o impacting the audio, you [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pschatzmann.ch\/home\/2022\/11\/25\/arduino-audio-tools-multicore-processing\/\" \/>\n<meta property=\"og:site_name\" content=\"Phil Schatzmann\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-25T09:26:55+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-25T15:06:50+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/11\/freertos.jpeg\" \/>\n\t<meta property=\"og:image:width\" content=\"337\" \/>\n\t<meta property=\"og:image:height\" content=\"149\" \/>\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=\"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\\\/2022\\\/11\\\/25\\\/arduino-audio-tools-multicore-processing\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/11\\\/25\\\/arduino-audio-tools-multicore-processing\\\/\"},\"author\":{\"name\":\"pschatzmann\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"headline\":\"Arduino Audio Tools &#8211; Multicore Processing\",\"datePublished\":\"2022-11-25T09:26:55+00:00\",\"dateModified\":\"2022-11-25T15:06:50+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/11\\\/25\\\/arduino-audio-tools-multicore-processing\\\/\"},\"wordCount\":291,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/11\\\/25\\\/arduino-audio-tools-multicore-processing\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/11\\\/freertos.jpeg\",\"articleSection\":[\"Arduino\",\"Machine Sound\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/11\\\/25\\\/arduino-audio-tools-multicore-processing\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/11\\\/25\\\/arduino-audio-tools-multicore-processing\\\/\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/11\\\/25\\\/arduino-audio-tools-multicore-processing\\\/\",\"name\":\"Arduino Audio Tools - Multicore Processing - Phil Schatzmann\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/11\\\/25\\\/arduino-audio-tools-multicore-processing\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/11\\\/25\\\/arduino-audio-tools-multicore-processing\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/11\\\/freertos.jpeg\",\"datePublished\":\"2022-11-25T09:26:55+00:00\",\"dateModified\":\"2022-11-25T15:06:50+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/11\\\/25\\\/arduino-audio-tools-multicore-processing\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/11\\\/25\\\/arduino-audio-tools-multicore-processing\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/11\\\/25\\\/arduino-audio-tools-multicore-processing\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/11\\\/freertos.jpeg\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/11\\\/freertos.jpeg\",\"width\":337,\"height\":149},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/11\\\/25\\\/arduino-audio-tools-multicore-processing\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Arduino Audio Tools &#8211; Multicore Processing\"}]},{\"@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 - Multicore Processing - 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\/11\/25\/arduino-audio-tools-multicore-processing\/","og_locale":"en_US","og_type":"article","og_title":"Arduino Audio Tools - Multicore Processing - Phil Schatzmann","og_description":"So far I never needed to use any of the ESP32 multicore functionality because all the examples are very simple and everything is fitting on a single core. However if you write some more complex scenarios which are e.g. updating a screen, process user input w\/o impacting the audio, you [&hellip;]","og_url":"https:\/\/www.pschatzmann.ch\/home\/2022\/11\/25\/arduino-audio-tools-multicore-processing\/","og_site_name":"Phil Schatzmann","article_published_time":"2022-11-25T09:26:55+00:00","article_modified_time":"2022-11-25T15:06:50+00:00","og_image":[{"width":337,"height":149,"url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/11\/freertos.jpeg","type":"image\/jpeg"}],"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\/2022\/11\/25\/arduino-audio-tools-multicore-processing\/#article","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/11\/25\/arduino-audio-tools-multicore-processing\/"},"author":{"name":"pschatzmann","@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"headline":"Arduino Audio Tools &#8211; Multicore Processing","datePublished":"2022-11-25T09:26:55+00:00","dateModified":"2022-11-25T15:06:50+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/11\/25\/arduino-audio-tools-multicore-processing\/"},"wordCount":291,"commentCount":0,"publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/11\/25\/arduino-audio-tools-multicore-processing\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/11\/freertos.jpeg","articleSection":["Arduino","Machine Sound"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pschatzmann.ch\/home\/2022\/11\/25\/arduino-audio-tools-multicore-processing\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/11\/25\/arduino-audio-tools-multicore-processing\/","url":"https:\/\/www.pschatzmann.ch\/home\/2022\/11\/25\/arduino-audio-tools-multicore-processing\/","name":"Arduino Audio Tools - Multicore Processing - Phil Schatzmann","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/11\/25\/arduino-audio-tools-multicore-processing\/#primaryimage"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/11\/25\/arduino-audio-tools-multicore-processing\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/11\/freertos.jpeg","datePublished":"2022-11-25T09:26:55+00:00","dateModified":"2022-11-25T15:06:50+00:00","breadcrumb":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/11\/25\/arduino-audio-tools-multicore-processing\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pschatzmann.ch\/home\/2022\/11\/25\/arduino-audio-tools-multicore-processing\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/11\/25\/arduino-audio-tools-multicore-processing\/#primaryimage","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/11\/freertos.jpeg","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/11\/freertos.jpeg","width":337,"height":149},{"@type":"BreadcrumbList","@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/11\/25\/arduino-audio-tools-multicore-processing\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pschatzmann.ch\/home\/"},{"@type":"ListItem","position":2,"name":"Arduino Audio Tools &#8211; Multicore Processing"}]},{"@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\/5172","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=5172"}],"version-history":[{"count":3,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/5172\/revisions"}],"predecessor-version":[{"id":5175,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/5172\/revisions\/5175"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media\/5104"}],"wp:attachment":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media?parent=5172"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/categories?post=5172"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/tags?post=5172"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}