{"id":5888,"date":"2023-09-12T11:52:45","date_gmt":"2023-09-12T09:52:45","guid":{"rendered":"https:\/\/www.pschatzmann.ch\/home\/?p=5888"},"modified":"2024-03-27T03:32:56","modified_gmt":"2024-03-27T02:32:56","slug":"arduino-audio-tools-faat-aac-decoder","status":"publish","type":"post","link":"https:\/\/www.pschatzmann.ch\/home\/2023\/09\/12\/arduino-audio-tools-faat-aac-decoder\/","title":{"rendered":"Arduino Audio Tools: FAAD AAC Decoder"},"content":{"rendered":"<p>This week I was looking into the <a href=\"https:\/\/github.com\/pschatzmann\/arduino-libfaad\">FAAD AAC Decoder<\/a> and tried to make it work on the ESP32.<\/p>\n<p>I was struggling quite a bit with the memory requirements and I could only make it work with a <strong>stack of 60k<\/strong> and by using <strong>PSRAM<\/strong>. So to fulfill the stack requirement we need to run the decoder in a separate <strong>freertos task<\/strong>.<\/p>\n<h2>The Arduino Sketch<\/h2>\n<p>Here is a working sketch that streams AAC audio from the internet and decodes it using FAAT. I was testing on an <a href=\"https:\/\/github.com\/pschatzmann\/arduino-audiokit\">AudioKit<\/a>, but you are free to replace the AudioKitStream with any other supported output stream (e.g. I2SStream):<\/p>\n<pre><code>#include \"AudioTools.h\"\n#include \"AudioCodecs\/CodecAACFAAD.h\"\n#include \"AudioLibs\/AudioKit.h\"\n#include \"freertos-all.h\"\n#include \"esp_heap_caps.h\"\n\n\nURLStream url(\"ssid\",\"your password\");  \/\/ or replace with ICYStream to get metadata\nAudioKitStream i2s; \/\/ final output of decoded stream\nEncodedAudioStream dec(&amp;i2s, new AACDecoderFAAD()); \/\/ Decoding stream\nStreamCopy copier(dec, url); \/\/ copy url to decoder\nvoid playAAC();\nTask task(\"play\", 60000, 10, playAAC);\n\n\nvoid playAAC(){\n  \/\/ setup i2s\n  auto config = i2s.defaultConfig(TX_MODE);\n  i2s.begin(config);\n\n  \/\/ setup I2S based on sampling rate provided by decoder\n  dec.begin();\n\n  \/\/ aac radio\n  url.begin(\"http:\/\/peacefulpiano.stream.publicradio.org\/peacefulpiano.aac\",\"audio\/aac\");\n  while(true){\n    copier.copy();\n  }\n}\n\nvoid setup(){\n  Serial.begin(115200);\n  AudioLogger::instance().begin(Serial, AudioLogger::Info);  \n\n  \/\/ alloc &gt; 1024 bytes in PSRAM\n  const int limit = 1024;\n  heap_caps_malloc_extmem_enable(limit);\n\n  \/\/ start on core 1\n  task.Start(1);\n}\n\nvoid loop(){\n  delay(1000);\n}\n\n<\/code><\/pre>\n<p>Don&#8217;t forget to activate PSRAM in the Arduino IDE!<\/p>\n<h2>Dependencies<\/h2>\n<p>You need to install the following libraries<\/p>\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\/arduino-libfaad\">arduino-libfaad<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/pschatzmann\/arduino-freertos-addons\">arduino-freertos-addons<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/pschatzmann\/arduino-audiokit\">arduino-audiokit <\/a> (when using an AudioKit)<\/li>\n<\/ul>\n<h2>Conclusions<\/h2>\n<p>It&#8217;s nice to have another option for <a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\/wiki\/Encoding-and-Decoding-of-Audio\">AAC Decoding<\/a>, but in the light of the memory requirements, I rather stick to using <a href=\"https:\/\/github.com\/pschatzmann\/arduino-libhelix\">libhelix<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This week I was looking into the FAAD AAC Decoder and tried to make it work on the ESP32. I was struggling quite a bit with the memory requirements and I could only make it work with a stack of 60k and by using PSRAM. So to fulfill the stack [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"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":[38],"class_list":["post-5888","post","type-post","status-publish","format-standard","hentry","category-arduino","category-machine-sound","tag-codecs"],"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: FAAD AAC Decoder - 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\/09\/12\/arduino-audio-tools-faat-aac-decoder\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Arduino Audio Tools: FAAD AAC Decoder - Phil Schatzmann\" \/>\n<meta property=\"og:description\" content=\"This week I was looking into the FAAD AAC Decoder and tried to make it work on the ESP32. I was struggling quite a bit with the memory requirements and I could only make it work with a stack of 60k and by using PSRAM. So to fulfill the stack [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pschatzmann.ch\/home\/2023\/09\/12\/arduino-audio-tools-faat-aac-decoder\/\" \/>\n<meta property=\"og:site_name\" content=\"Phil Schatzmann\" \/>\n<meta property=\"article:published_time\" content=\"2023-09-12T09:52:45+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-03-27T02:32:56+00:00\" \/>\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\\\/09\\\/12\\\/arduino-audio-tools-faat-aac-decoder\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/09\\\/12\\\/arduino-audio-tools-faat-aac-decoder\\\/\"},\"author\":{\"name\":\"pschatzmann\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"headline\":\"Arduino Audio Tools: FAAD AAC Decoder\",\"datePublished\":\"2023-09-12T09:52:45+00:00\",\"dateModified\":\"2024-03-27T02:32:56+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/09\\\/12\\\/arduino-audio-tools-faat-aac-decoder\\\/\"},\"wordCount\":163,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"keywords\":[\"Codecs\"],\"articleSection\":[\"Arduino\",\"Machine Sound\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/09\\\/12\\\/arduino-audio-tools-faat-aac-decoder\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/09\\\/12\\\/arduino-audio-tools-faat-aac-decoder\\\/\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/09\\\/12\\\/arduino-audio-tools-faat-aac-decoder\\\/\",\"name\":\"Arduino Audio Tools: FAAD AAC Decoder - Phil Schatzmann\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\"},\"datePublished\":\"2023-09-12T09:52:45+00:00\",\"dateModified\":\"2024-03-27T02:32:56+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/09\\\/12\\\/arduino-audio-tools-faat-aac-decoder\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/09\\\/12\\\/arduino-audio-tools-faat-aac-decoder\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/09\\\/12\\\/arduino-audio-tools-faat-aac-decoder\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Arduino Audio Tools: FAAD AAC Decoder\"}]},{\"@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: FAAD AAC Decoder - 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\/09\/12\/arduino-audio-tools-faat-aac-decoder\/","og_locale":"en_US","og_type":"article","og_title":"Arduino Audio Tools: FAAD AAC Decoder - Phil Schatzmann","og_description":"This week I was looking into the FAAD AAC Decoder and tried to make it work on the ESP32. I was struggling quite a bit with the memory requirements and I could only make it work with a stack of 60k and by using PSRAM. So to fulfill the stack [&hellip;]","og_url":"https:\/\/www.pschatzmann.ch\/home\/2023\/09\/12\/arduino-audio-tools-faat-aac-decoder\/","og_site_name":"Phil Schatzmann","article_published_time":"2023-09-12T09:52:45+00:00","article_modified_time":"2024-03-27T02:32:56+00:00","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\/09\/12\/arduino-audio-tools-faat-aac-decoder\/#article","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/09\/12\/arduino-audio-tools-faat-aac-decoder\/"},"author":{"name":"pschatzmann","@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"headline":"Arduino Audio Tools: FAAD AAC Decoder","datePublished":"2023-09-12T09:52:45+00:00","dateModified":"2024-03-27T02:32:56+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/09\/12\/arduino-audio-tools-faat-aac-decoder\/"},"wordCount":163,"commentCount":0,"publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"keywords":["Codecs"],"articleSection":["Arduino","Machine Sound"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pschatzmann.ch\/home\/2023\/09\/12\/arduino-audio-tools-faat-aac-decoder\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/09\/12\/arduino-audio-tools-faat-aac-decoder\/","url":"https:\/\/www.pschatzmann.ch\/home\/2023\/09\/12\/arduino-audio-tools-faat-aac-decoder\/","name":"Arduino Audio Tools: FAAD AAC Decoder - Phil Schatzmann","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#website"},"datePublished":"2023-09-12T09:52:45+00:00","dateModified":"2024-03-27T02:32:56+00:00","breadcrumb":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/09\/12\/arduino-audio-tools-faat-aac-decoder\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pschatzmann.ch\/home\/2023\/09\/12\/arduino-audio-tools-faat-aac-decoder\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/09\/12\/arduino-audio-tools-faat-aac-decoder\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pschatzmann.ch\/home\/"},{"@type":"ListItem","position":2,"name":"Arduino Audio Tools: FAAD AAC Decoder"}]},{"@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\/5888","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=5888"}],"version-history":[{"count":9,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/5888\/revisions"}],"predecessor-version":[{"id":5892,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/5888\/revisions\/5892"}],"wp:attachment":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media?parent=5888"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/categories?post=5888"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/tags?post=5888"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}