{"id":4925,"date":"2022-09-01T19:22:59","date_gmt":"2022-09-01T17:22:59","guid":{"rendered":"https:\/\/www.pschatzmann.ch\/home\/?p=4925"},"modified":"2022-09-11T22:01:38","modified_gmt":"2022-09-11T20:01:38","slug":"arduino-audio-tools-recording-sound-in-spi-ram","status":"publish","type":"post","link":"https:\/\/www.pschatzmann.ch\/home\/2022\/09\/01\/arduino-audio-tools-recording-sound-in-spi-ram\/","title":{"rendered":"Arduino Audio Tools &#8211; Recording Sound to SPI RAM"},"content":{"rendered":"<p>The AudioKit and some ESP32 Processors have 4MB of <strong>SPI RAM<\/strong>  that we can use e.g. to store recorded audio. I was playing with the idea to build some <strong>looping logic<\/strong>. Therefore I have added an additional <a href=\"https:\/\/pschatzmann.github.io\/arduino-audio-tools\/html\/classaudio__tools_1_1_dynamic_memory_stream.html\">DynamicMemoryStream<\/a> class that can stores the audio data <strong>on the heap<\/strong>. With the help of the <strong>memory manager<\/strong> we can indicate that data chunks that are above a specified limit are stored in SPI RAM!<\/p>\n<h2>Arduino Sketch<\/h2>\n<p>To get started here I have a <strong>simple test sketch<\/strong> that starts to record audio from the microphone when a button is pressed and stops the recording when the button is released. After that it plays the recorded sound in a loop:<\/p>\n<pre><code>#include \"AudioTools.h\"\n#include \"AudioLibs\/AudioKit.h\"\n#include \"AudioLibs\/MemoryManager.h\"\n\nuint16_t sample_rate = 16000;\nuint8_t channels = 1;  \/\/ The stream will have 1 channel\nAudioKitStream kit;\nMemoryManager memory(500); \/\/ Activate SPI RAM for objects &gt; 500 bytes\nDynamicMemoryStream recording(true); \/\/ Audio stored on heap looping endlessly \nStreamCopy copier; \/\/ copies data\n\n\nvoid record_start(bool pinStatus, int pin, void* ref){\n  Serial.println(\"Recording...\");\n  recording.begin(); \/\/ clear data\n  copier.begin(recording, kit); \/\/ from mic to memory \n}\n\nvoid record_end(bool pinStatus, int pin, void* ref){\n  Serial.println(\"Playing...\");\n  copier.begin(kit, recording);  \/\/ from memory to kit\n}\n\nvoid setup(){\n  Serial.begin(115200);\n  AudioLogger::instance().begin(Serial, AudioLogger::Info);  \n\n  \/\/ setup input and output\n  auto cfg = kit.defaultConfig(RXTX_MODE);\n  cfg.sd_active = false; \/\/ we don't need the SD card\n  cfg.sample_rate = sample_rate; \n  cfg.channels = channels;\n  cfg.input_device = AUDIO_HAL_ADC_INPUT_LINE2;\n  kit.begin(cfg);\n  kit.setVolume(1.0);\n\n  \/\/ record when key 1 is pressed\n  kit.audioActions().add(PIN_KEY1, record_start, record_end);\n  Serial.println(\"Press Key 1 to record\");\n\n}\n\nvoid loop(){\n  \/\/ record or play recording\n  copier.copy();  \n\n  \/\/ Process keys\n  kit.processActions();\n}\n<\/code><\/pre>\n<p>The complete <a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\/blob\/main\/examples\/examples-audiokit\/streams-audiokit-ram-audiokit\/streams-audiokit-ram-audiokit.ino\">potentially updated example<\/a> can be found on Github<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The AudioKit and some ESP32 Processors have 4MB of SPI RAM that we can use e.g. to store recorded audio. I was playing with the idea to build some looping logic. Therefore I have added an additional DynamicMemoryStream class that can stores the audio data on the heap. With the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3882,"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-4925","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 - Recording Sound to SPI RAM - 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\/09\/01\/arduino-audio-tools-recording-sound-in-spi-ram\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Arduino Audio Tools - Recording Sound to SPI RAM - Phil Schatzmann\" \/>\n<meta property=\"og:description\" content=\"The AudioKit and some ESP32 Processors have 4MB of SPI RAM that we can use e.g. to store recorded audio. I was playing with the idea to build some looping logic. Therefore I have added an additional DynamicMemoryStream class that can stores the audio data on the heap. With the [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pschatzmann.ch\/home\/2022\/09\/01\/arduino-audio-tools-recording-sound-in-spi-ram\/\" \/>\n<meta property=\"og:site_name\" content=\"Phil Schatzmann\" \/>\n<meta property=\"article:published_time\" content=\"2022-09-01T17:22:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-09-11T20:01:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/12\/audio-toolkit.png\" \/>\n\t<meta property=\"og:image:width\" content=\"800\" \/>\n\t<meta property=\"og:image:height\" content=\"500\" \/>\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\\\/2022\\\/09\\\/01\\\/arduino-audio-tools-recording-sound-in-spi-ram\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/09\\\/01\\\/arduino-audio-tools-recording-sound-in-spi-ram\\\/\"},\"author\":{\"name\":\"pschatzmann\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"headline\":\"Arduino Audio Tools &#8211; Recording Sound to SPI RAM\",\"datePublished\":\"2022-09-01T17:22:59+00:00\",\"dateModified\":\"2022-09-11T20:01:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/09\\\/01\\\/arduino-audio-tools-recording-sound-in-spi-ram\\\/\"},\"wordCount\":136,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/09\\\/01\\\/arduino-audio-tools-recording-sound-in-spi-ram\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/12\\\/audio-toolkit.png\",\"articleSection\":[\"Arduino\",\"Machine Sound\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/09\\\/01\\\/arduino-audio-tools-recording-sound-in-spi-ram\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/09\\\/01\\\/arduino-audio-tools-recording-sound-in-spi-ram\\\/\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/09\\\/01\\\/arduino-audio-tools-recording-sound-in-spi-ram\\\/\",\"name\":\"Arduino Audio Tools - Recording Sound to SPI RAM - Phil Schatzmann\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/09\\\/01\\\/arduino-audio-tools-recording-sound-in-spi-ram\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/09\\\/01\\\/arduino-audio-tools-recording-sound-in-spi-ram\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/12\\\/audio-toolkit.png\",\"datePublished\":\"2022-09-01T17:22:59+00:00\",\"dateModified\":\"2022-09-11T20:01:38+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/09\\\/01\\\/arduino-audio-tools-recording-sound-in-spi-ram\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/09\\\/01\\\/arduino-audio-tools-recording-sound-in-spi-ram\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/09\\\/01\\\/arduino-audio-tools-recording-sound-in-spi-ram\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/12\\\/audio-toolkit.png\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2021\\\/12\\\/audio-toolkit.png\",\"width\":800,\"height\":500},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2022\\\/09\\\/01\\\/arduino-audio-tools-recording-sound-in-spi-ram\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Arduino Audio Tools &#8211; Recording Sound to SPI RAM\"}]},{\"@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 - Recording Sound to SPI RAM - 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\/09\/01\/arduino-audio-tools-recording-sound-in-spi-ram\/","og_locale":"en_US","og_type":"article","og_title":"Arduino Audio Tools - Recording Sound to SPI RAM - Phil Schatzmann","og_description":"The AudioKit and some ESP32 Processors have 4MB of SPI RAM that we can use e.g. to store recorded audio. I was playing with the idea to build some looping logic. Therefore I have added an additional DynamicMemoryStream class that can stores the audio data on the heap. With the [&hellip;]","og_url":"https:\/\/www.pschatzmann.ch\/home\/2022\/09\/01\/arduino-audio-tools-recording-sound-in-spi-ram\/","og_site_name":"Phil Schatzmann","article_published_time":"2022-09-01T17:22:59+00:00","article_modified_time":"2022-09-11T20:01:38+00:00","og_image":[{"width":800,"height":500,"url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/12\/audio-toolkit.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\/2022\/09\/01\/arduino-audio-tools-recording-sound-in-spi-ram\/#article","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/09\/01\/arduino-audio-tools-recording-sound-in-spi-ram\/"},"author":{"name":"pschatzmann","@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"headline":"Arduino Audio Tools &#8211; Recording Sound to SPI RAM","datePublished":"2022-09-01T17:22:59+00:00","dateModified":"2022-09-11T20:01:38+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/09\/01\/arduino-audio-tools-recording-sound-in-spi-ram\/"},"wordCount":136,"commentCount":2,"publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/09\/01\/arduino-audio-tools-recording-sound-in-spi-ram\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/12\/audio-toolkit.png","articleSection":["Arduino","Machine Sound"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pschatzmann.ch\/home\/2022\/09\/01\/arduino-audio-tools-recording-sound-in-spi-ram\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/09\/01\/arduino-audio-tools-recording-sound-in-spi-ram\/","url":"https:\/\/www.pschatzmann.ch\/home\/2022\/09\/01\/arduino-audio-tools-recording-sound-in-spi-ram\/","name":"Arduino Audio Tools - Recording Sound to SPI RAM - Phil Schatzmann","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/09\/01\/arduino-audio-tools-recording-sound-in-spi-ram\/#primaryimage"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/09\/01\/arduino-audio-tools-recording-sound-in-spi-ram\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/12\/audio-toolkit.png","datePublished":"2022-09-01T17:22:59+00:00","dateModified":"2022-09-11T20:01:38+00:00","breadcrumb":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/09\/01\/arduino-audio-tools-recording-sound-in-spi-ram\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pschatzmann.ch\/home\/2022\/09\/01\/arduino-audio-tools-recording-sound-in-spi-ram\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/09\/01\/arduino-audio-tools-recording-sound-in-spi-ram\/#primaryimage","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/12\/audio-toolkit.png","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/12\/audio-toolkit.png","width":800,"height":500},{"@type":"BreadcrumbList","@id":"https:\/\/www.pschatzmann.ch\/home\/2022\/09\/01\/arduino-audio-tools-recording-sound-in-spi-ram\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pschatzmann.ch\/home\/"},{"@type":"ListItem","position":2,"name":"Arduino Audio Tools &#8211; Recording Sound to SPI RAM"}]},{"@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\/4925","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=4925"}],"version-history":[{"count":10,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/4925\/revisions"}],"predecessor-version":[{"id":4962,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/4925\/revisions\/4962"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media\/3882"}],"wp:attachment":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media?parent=4925"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/categories?post=4925"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/tags?post=4925"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}