{"id":6598,"date":"2025-02-26T10:23:48","date_gmt":"2025-02-26T09:23:48","guid":{"rendered":"https:\/\/www.pschatzmann.ch\/home\/?p=6598"},"modified":"2025-03-04T17:15:19","modified_gmt":"2025-03-04T16:15:19","slug":"audiotools-using-multiple-decoders","status":"publish","type":"post","link":"https:\/\/www.pschatzmann.ch\/home\/2025\/02\/26\/audiotools-using-multiple-decoders\/","title":{"rendered":"AudioTools: Using Multiple Decoders"},"content":{"rendered":"<p>In all my demo sketches so far, I have used just <strong>one decoder only<\/strong>, but what if we want to play <strong>multiple audio file types<\/strong> ?<\/p>\n<p>To support this scenario, I decided to provide the <a href=\"https:\/\/pschatzmann.github.io\/arduino-audio-tools\/classaudio__tools_1_1_multi_decoder.html\">MultiDecoder<\/a> class, that lets you register your <strong>codecs<\/strong> with the corresponding <strong>mime type<\/strong>.<\/p>\n<p>This class works together with my <a href=\"https:\/\/pschatzmann.github.io\/arduino-audio-tools\/classaudio__tools_1_1_mime_detector.html\">MimeDetector<\/a> which detects the file type based on the first couple of bytes.<\/p>\n<p>Here is an example sketch that can <strong>play aac, mp3 and wav<\/strong> files from the SD drive:<\/p>\n<pre><code><br \/>#include \"AudioTools.h\"\n#include \"AudioTools\/AudioLibs\/AudioBoardStream.h\"\n#include \"AudioTools\/AudioLibs\/AudioSourceSD.h\" \/\/ or AudioSourceIdxSD.h\n#include \"AudioTools\/AudioCodecs\/CodecMP3Helix.h\"\n#include \"AudioTools\/AudioCodecs\/CodecAACHelix.h\"\n\nconst char *startFilePath=\"\/multi\";\nconst char* ext=\"\";\nAudioSourceSD source(startFilePath, ext, SS);\nI2SStream i2s;\nMultiDecoder multi;\nMP3DecoderHelix mp3;\nAACDecoderHelix aac;\nWAVDecoder wav;\nAudioPlayer player(source, i2s, multi);\n\nvoid setup() {\n  Serial.begin(115200);\n  AudioToolsLogger.begin(Serial, AudioToolsLogLevel::Info);\n\n  \/\/ optionally define you custom pins for the SD drive\n  \/\/ SPI.begin(PIN_AUDIO_KIT_SD_CARD_CLK, PIN_AUDIO_KIT_SD_CARD_MISO, PIN_AUDIO_KIT_SD_CARD_MOSI, PIN_AUDIO_KIT_SD_CARD_CS);\n\n  \/\/ register supported codecs with their mime type\n  multi.addDecoder(mp3, \"audio\/mpeg\");\n  multi.addDecoder(aac, \"audio\/aac\");\n  multi.addDecoder(wav, \"audio\/vnd.wave\");\n\n  \/\/ setup output\n  auto cfg = i2s.defaultConfig(TX_MODE);\n  \/\/ sd_active is setting up SPI with the right SD pins by calling \n  i2s.begin(cfg);\n\n  \/\/ setup player\n  player.setVolume(0.7);\n  player.begin();\n\n}\n\nvoid loop() {\n  player.copy();\n}\n<\/code><\/pre>\n<h3>Dependencies<\/h3>\n<p>You need to install the following Arduino libraries:<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\">Arduino AudioTools<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/pschatzmann\/arduino-libhelix\">libhelix<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>In all my demo sketches so far, I have used just one decoder only, but what if we want to play multiple audio file types ? To support this scenario, I decided to provide the MultiDecoder class, that lets you register your codecs with the corresponding mime type. This class [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","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-6598","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.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>AudioTools: Using Multiple Decoders - 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\/2025\/02\/26\/audiotools-using-multiple-decoders\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"AudioTools: Using Multiple Decoders - Phil Schatzmann\" \/>\n<meta property=\"og:description\" content=\"In all my demo sketches so far, I have used just one decoder only, but what if we want to play multiple audio file types ? To support this scenario, I decided to provide the MultiDecoder class, that lets you register your codecs with the corresponding mime type. This class [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pschatzmann.ch\/home\/2025\/02\/26\/audiotools-using-multiple-decoders\/\" \/>\n<meta property=\"og:site_name\" content=\"Phil Schatzmann\" \/>\n<meta property=\"article:published_time\" content=\"2025-02-26T09:23:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-03-04T16:15:19+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=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2025\\\/02\\\/26\\\/audiotools-using-multiple-decoders\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2025\\\/02\\\/26\\\/audiotools-using-multiple-decoders\\\/\"},\"author\":{\"name\":\"pschatzmann\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"headline\":\"AudioTools: Using Multiple Decoders\",\"datePublished\":\"2025-02-26T09:23:48+00:00\",\"dateModified\":\"2025-03-04T16:15:19+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2025\\\/02\\\/26\\\/audiotools-using-multiple-decoders\\\/\"},\"wordCount\":99,\"commentCount\":4,\"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\\\/2025\\\/02\\\/26\\\/audiotools-using-multiple-decoders\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2025\\\/02\\\/26\\\/audiotools-using-multiple-decoders\\\/\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2025\\\/02\\\/26\\\/audiotools-using-multiple-decoders\\\/\",\"name\":\"AudioTools: Using Multiple Decoders - Phil Schatzmann\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\"},\"datePublished\":\"2025-02-26T09:23:48+00:00\",\"dateModified\":\"2025-03-04T16:15:19+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2025\\\/02\\\/26\\\/audiotools-using-multiple-decoders\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2025\\\/02\\\/26\\\/audiotools-using-multiple-decoders\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2025\\\/02\\\/26\\\/audiotools-using-multiple-decoders\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"AudioTools: Using Multiple Decoders\"}]},{\"@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: Using Multiple Decoders - 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\/2025\/02\/26\/audiotools-using-multiple-decoders\/","og_locale":"en_US","og_type":"article","og_title":"AudioTools: Using Multiple Decoders - Phil Schatzmann","og_description":"In all my demo sketches so far, I have used just one decoder only, but what if we want to play multiple audio file types ? To support this scenario, I decided to provide the MultiDecoder class, that lets you register your codecs with the corresponding mime type. This class [&hellip;]","og_url":"https:\/\/www.pschatzmann.ch\/home\/2025\/02\/26\/audiotools-using-multiple-decoders\/","og_site_name":"Phil Schatzmann","article_published_time":"2025-02-26T09:23:48+00:00","article_modified_time":"2025-03-04T16:15:19+00:00","author":"pschatzmann","twitter_card":"summary_large_image","twitter_misc":{"Written by":"pschatzmann","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pschatzmann.ch\/home\/2025\/02\/26\/audiotools-using-multiple-decoders\/#article","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2025\/02\/26\/audiotools-using-multiple-decoders\/"},"author":{"name":"pschatzmann","@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"headline":"AudioTools: Using Multiple Decoders","datePublished":"2025-02-26T09:23:48+00:00","dateModified":"2025-03-04T16:15:19+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2025\/02\/26\/audiotools-using-multiple-decoders\/"},"wordCount":99,"commentCount":4,"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\/2025\/02\/26\/audiotools-using-multiple-decoders\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pschatzmann.ch\/home\/2025\/02\/26\/audiotools-using-multiple-decoders\/","url":"https:\/\/www.pschatzmann.ch\/home\/2025\/02\/26\/audiotools-using-multiple-decoders\/","name":"AudioTools: Using Multiple Decoders - Phil Schatzmann","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#website"},"datePublished":"2025-02-26T09:23:48+00:00","dateModified":"2025-03-04T16:15:19+00:00","breadcrumb":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2025\/02\/26\/audiotools-using-multiple-decoders\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pschatzmann.ch\/home\/2025\/02\/26\/audiotools-using-multiple-decoders\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.pschatzmann.ch\/home\/2025\/02\/26\/audiotools-using-multiple-decoders\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pschatzmann.ch\/home\/"},{"@type":"ListItem","position":2,"name":"AudioTools: Using Multiple Decoders"}]},{"@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\/6598","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=6598"}],"version-history":[{"count":7,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/6598\/revisions"}],"predecessor-version":[{"id":6605,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/6598\/revisions\/6605"}],"wp:attachment":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media?parent=6598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/categories?post=6598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/tags?post=6598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}