{"id":6119,"date":"2024-03-06T09:13:53","date_gmt":"2024-03-06T08:13:53","guid":{"rendered":"https:\/\/www.pschatzmann.ch\/home\/?p=6119"},"modified":"2025-06-12T15:01:14","modified_gmt":"2025-06-12T13:01:14","slug":"audiotools-esp32-and-psram-revisited","status":"publish","type":"post","link":"https:\/\/www.pschatzmann.ch\/home\/2024\/03\/06\/audiotools-esp32-and-psram-revisited\/","title":{"rendered":"AudioTools, ESP32 and PSRAM revisited"},"content":{"rendered":"<h3>Arrays<\/h3>\n<p>The best way to allocate an Array of data in the <a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\">AudioTools<\/a> is by using a <a href=\"https:\/\/pschatzmann.github.io\/arduino-audio-tools\/classaudio__tools_1_1_vector.html\">Vector<\/a>. E.g. <code>Vector&lt;int16_t&gt; vector{100000};<\/code> is allocating a vector of 100&#8217;000 2 byte signed integers.<\/p>\n<h3>RAM and PSRAM<\/h3>\n<p>The ESP32 has a few hundred kilobytes of internal RAM, residing on the same die as the rest of the chip components. It can be insufficient for audio, so it has the ability to use up to 4 MB of external <strong>PSRAM (Psuedostatic RAM)<\/strong> memory.<\/p>\n<p>To use this you need to <strong>activate<\/strong> PSRAM in the <strong>Arduino Tools menu<\/strong>. There is one small complication: it is <strong>not available yet when global variables are defined<\/strong>! The best way around this is to make sure that the allocation is done in the <strong>Arduino setup<\/strong>.<\/p>\n<h3>Allocators in AudioTools<\/h3>\n<p>An Allocator defines how memory is allocated: You can define the <strong>Allocator<\/strong> in the constructor of the Vector and if nothing is defined, we automatically use the <strong>DefaultAllocator<\/strong> which is using PSRAM if possible and if this fails it resorts back to regular RAM.<\/p>\n<p>The following allocator objects have been predefined:<\/p>\n<ul>\n<li>DefaultAllocator (use PSRAM and RAM)<\/li>\n<li>DefaultAllocatorPSRAM (only use PSRAM)<\/li>\n<li>DefaultAllocatorRAM (only use RAM)<\/li>\n<\/ul>\n<p>and you can create your own by implementing an subclass of <a href=\"https:\/\/pschatzmann.github.io\/arduino-audio-tools\/classaudio__tools_1_1_allocator.html\">Allocator<\/a>.<\/p>\n<h3>Examples<\/h3>\n<p>Here are a couple of examples:<\/p>\n<pre><code>#include \"AudioTools.h\"\n\nVector&lt;int16_t&gt; vectorPSRAM{0}; \/\/ same as vectorPSRAM{0, DefaultAllocator};\nVector&lt;int16_t&gt; vectorRAM{10000}; \/\/ Allocation in RAM because PSRAM fails.\nVector&lt;int16_t&gt; vectorRAM1{10000, DefaultAllocatorRAM}; \/\/ allocation in RAM\nVector&lt;int16_t&gt; vectorRAM2{0, DefaultAllocatorRAM}; \/\/ allocation in RAM\n\nvoid setup() {\n  vectorPSRAM.resize(10000); \/\/ allocate data in PSRAM \n  vectorRAM2.resize(10000); \/\/ allocate data in RAM\n}\n<\/code><\/pre>\n<h3>Configuration<\/h3>\n<p>Currently this feature is not automatically activated; You will need to uncomment the \/\/#define USE_ALLOCATOR true line in AudioConfig.h<\/p>\n<h3>Final Thoughts<\/h3>\n<p>Since I am using the Vector class to allocate memory in all my other audio classes, PSRAM is automatically used, if activated and the resize() method is a flixible way to adjust the size to dynamic requirements.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Arrays The best way to allocate an Array of data in the AudioTools is by using a Vector. E.g. Vector&lt;int16_t&gt; vector{100000}; is allocating a vector of 100&#8217;000 2 byte signed integers. RAM and PSRAM The ESP32 has a few hundred kilobytes of internal RAM, residing on the same die as [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6120,"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":[60],"class_list":["post-6119","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino","category-machine-sound","tag-psram"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>AudioTools, ESP32 and PSRAM revisited - 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\/2024\/03\/06\/audiotools-esp32-and-psram-revisited\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"AudioTools, ESP32 and PSRAM revisited - Phil Schatzmann\" \/>\n<meta property=\"og:description\" content=\"Arrays The best way to allocate an Array of data in the AudioTools is by using a Vector. E.g. Vector&lt;int16_t&gt; vector{100000}; is allocating a vector of 100&#8217;000 2 byte signed integers. RAM and PSRAM The ESP32 has a few hundred kilobytes of internal RAM, residing on the same die as [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pschatzmann.ch\/home\/2024\/03\/06\/audiotools-esp32-and-psram-revisited\/\" \/>\n<meta property=\"og:site_name\" content=\"Phil Schatzmann\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-06T08:13:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-12T13:01:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2024\/03\/array.png\" \/>\n\t<meta property=\"og:image:width\" content=\"200\" \/>\n\t<meta property=\"og:image:height\" content=\"200\" \/>\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\\\/2024\\\/03\\\/06\\\/audiotools-esp32-and-psram-revisited\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/03\\\/06\\\/audiotools-esp32-and-psram-revisited\\\/\"},\"author\":{\"name\":\"pschatzmann\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"headline\":\"AudioTools, ESP32 and PSRAM revisited\",\"datePublished\":\"2024-03-06T08:13:53+00:00\",\"dateModified\":\"2025-06-12T13:01:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/03\\\/06\\\/audiotools-esp32-and-psram-revisited\\\/\"},\"wordCount\":273,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/03\\\/06\\\/audiotools-esp32-and-psram-revisited\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2024\\\/03\\\/array.png\",\"keywords\":[\"PSRAM\"],\"articleSection\":[\"Arduino\",\"Machine Sound\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/03\\\/06\\\/audiotools-esp32-and-psram-revisited\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/03\\\/06\\\/audiotools-esp32-and-psram-revisited\\\/\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/03\\\/06\\\/audiotools-esp32-and-psram-revisited\\\/\",\"name\":\"AudioTools, ESP32 and PSRAM revisited - Phil Schatzmann\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/03\\\/06\\\/audiotools-esp32-and-psram-revisited\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/03\\\/06\\\/audiotools-esp32-and-psram-revisited\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2024\\\/03\\\/array.png\",\"datePublished\":\"2024-03-06T08:13:53+00:00\",\"dateModified\":\"2025-06-12T13:01:14+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/03\\\/06\\\/audiotools-esp32-and-psram-revisited\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/03\\\/06\\\/audiotools-esp32-and-psram-revisited\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/03\\\/06\\\/audiotools-esp32-and-psram-revisited\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2024\\\/03\\\/array.png\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2024\\\/03\\\/array.png\",\"width\":200,\"height\":200},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2024\\\/03\\\/06\\\/audiotools-esp32-and-psram-revisited\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"AudioTools, ESP32 and PSRAM revisited\"}]},{\"@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":"AudioTools, ESP32 and PSRAM revisited - 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\/2024\/03\/06\/audiotools-esp32-and-psram-revisited\/","og_locale":"en_US","og_type":"article","og_title":"AudioTools, ESP32 and PSRAM revisited - Phil Schatzmann","og_description":"Arrays The best way to allocate an Array of data in the AudioTools is by using a Vector. E.g. Vector&lt;int16_t&gt; vector{100000}; is allocating a vector of 100&#8217;000 2 byte signed integers. RAM and PSRAM The ESP32 has a few hundred kilobytes of internal RAM, residing on the same die as [&hellip;]","og_url":"https:\/\/www.pschatzmann.ch\/home\/2024\/03\/06\/audiotools-esp32-and-psram-revisited\/","og_site_name":"Phil Schatzmann","article_published_time":"2024-03-06T08:13:53+00:00","article_modified_time":"2025-06-12T13:01:14+00:00","og_image":[{"width":200,"height":200,"url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2024\/03\/array.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\/2024\/03\/06\/audiotools-esp32-and-psram-revisited\/#article","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2024\/03\/06\/audiotools-esp32-and-psram-revisited\/"},"author":{"name":"pschatzmann","@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"headline":"AudioTools, ESP32 and PSRAM revisited","datePublished":"2024-03-06T08:13:53+00:00","dateModified":"2025-06-12T13:01:14+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2024\/03\/06\/audiotools-esp32-and-psram-revisited\/"},"wordCount":273,"commentCount":0,"publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2024\/03\/06\/audiotools-esp32-and-psram-revisited\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2024\/03\/array.png","keywords":["PSRAM"],"articleSection":["Arduino","Machine Sound"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pschatzmann.ch\/home\/2024\/03\/06\/audiotools-esp32-and-psram-revisited\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pschatzmann.ch\/home\/2024\/03\/06\/audiotools-esp32-and-psram-revisited\/","url":"https:\/\/www.pschatzmann.ch\/home\/2024\/03\/06\/audiotools-esp32-and-psram-revisited\/","name":"AudioTools, ESP32 and PSRAM revisited - Phil Schatzmann","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2024\/03\/06\/audiotools-esp32-and-psram-revisited\/#primaryimage"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2024\/03\/06\/audiotools-esp32-and-psram-revisited\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2024\/03\/array.png","datePublished":"2024-03-06T08:13:53+00:00","dateModified":"2025-06-12T13:01:14+00:00","breadcrumb":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2024\/03\/06\/audiotools-esp32-and-psram-revisited\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pschatzmann.ch\/home\/2024\/03\/06\/audiotools-esp32-and-psram-revisited\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/home\/2024\/03\/06\/audiotools-esp32-and-psram-revisited\/#primaryimage","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2024\/03\/array.png","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2024\/03\/array.png","width":200,"height":200},{"@type":"BreadcrumbList","@id":"https:\/\/www.pschatzmann.ch\/home\/2024\/03\/06\/audiotools-esp32-and-psram-revisited\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pschatzmann.ch\/home\/"},{"@type":"ListItem","position":2,"name":"AudioTools, ESP32 and PSRAM revisited"}]},{"@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\/6119","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=6119"}],"version-history":[{"count":20,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/6119\/revisions"}],"predecessor-version":[{"id":6154,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/6119\/revisions\/6154"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media\/6120"}],"wp:attachment":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media?parent=6119"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/categories?post=6119"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/tags?post=6119"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}