{"id":5681,"date":"2023-05-21T06:48:27","date_gmt":"2023-05-21T04:48:27","guid":{"rendered":"https:\/\/www.pschatzmann.ch\/home\/?p=5681"},"modified":"2025-04-10T18:52:30","modified_gmt":"2025-04-10T16:52:30","slug":"adpcm-and-wav-files","status":"publish","type":"post","link":"https:\/\/www.pschatzmann.ch\/home\/2023\/05\/21\/adpcm-and-wav-files\/","title":{"rendered":"ADPCM and WAV Files"},"content":{"rendered":"<p>At the very beginning of my <a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\">Arduino AudioTools<\/a> project, I was providing a codec for WAV files. It was just handling PCM audio, so it just needed to read or write the header and then could just copy the audio data.<\/p>\n<p>In my <a href=\"https:\/\/www.pschatzmann.ch\/home\/2023\/05\/10\/fast-audio-codecs-for-microcontrollers\/\">last blog<\/a>, I was writing that the ADPCM codec is perfectly suited for encoding and decoding audio on microcontrollers. So the next natural step is to provide a <strong>proper ADPCM support for WAV files<\/strong> and that&#8217;s what I have implemented this week.<\/p>\n<h2>Arduino Sketch<\/h2>\n<p>Here is a test sketch that encodes and decodes a sine test signal using the Microsoft ADPCM WAV format.<\/p>\n<pre><code>#include \"AudioTools.h\"\n#include \"AudioTools\/AudioCodecs\/CodecWAV.h\" \n#include \"AudioTools\/AudioCodecs\/CodecADPCM.h\"\n\nAudioInfo info(16000, 2, 16);\nSineWaveGenerator&lt;int16_t&gt; sineWave( 32000);  \nGeneratedSoundStream&lt;int16_t&gt; sound( sineWave); \nCsvStream&lt;int16_t&gt; out(Serial);\nADPCMDecoder adpcm_decoder(AV_CODEC_ID_ADPCM_IMA_WAV); \nADPCMEncoder adpcm_encoder(AV_CODEC_ID_ADPCM_IMA_WAV);  \nWAVDecoder wav_decoder(adpcm_decoder, AudioFormat::ADPCM);\nWAVEncoder wav_encoder(adpcm_encoder, AudioFormat::ADPCM)\nEncodedAudioStream decoder(&amp;out, &amp;wav_decoder); \nEncodedAudioStream encoder(&amp;decoder, &amp;wav_encoder); \nStreamCopy copier(encoder, sound);     \n\nvoid setup() {\n  Serial.begin(115200);\n  AudioLogger::instance().begin(Serial, AudioLogger::Warning);\n\n  \/\/ start Output\n  auto cfgi = out.defaultConfig(TX_MODE);\n  cfgi.copyFrom(info);\n  out.begin(cfgi);\n\n  \/\/ Setup sine wave\n  auto cfgs = sineWave.defaultConfig();\n  cfgs.copyFrom(info);\n  sineWave.begin(info, N_B4);\n\n  \/\/ start decoder\n  decoder.begin(info);\n\n  \/\/ start encoder\n  encoder.begin(info);\n}\n\nvoid loop() { \n  copier.copy();\n}\n<\/code><\/pre>\n<p>When we create the <a href=\"https:\/\/pschatzmann.github.io\/arduino-audio-tools\/classaudio__tools_1_1_w_a_v_encoder.html\">WAVEncoder<\/a> we just need to give it an encoder and the corresponding WAV format as arguments. The same applies for the <a href=\"https:\/\/pschatzmann.github.io\/arduino-audio-tools\/classaudio__tools_1_1_w_a_v_decoder.html\">WAVDecoder<\/a>.<\/p>\n<h2>Summary<\/h2>\n<p>Now, we can easily provide compressed audio with the help of WAV files.<\/p>\n<h2>Dependencies<\/h2>\n<p>Do not forget to install the following 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\/adpcm\">ADPCM<\/a> <\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>At the very beginning of my Arduino AudioTools project, I was providing a codec for WAV files. It was just handling PCM audio, so it just needed to read or write the header and then could just copy the audio data. In my last blog, I was writing that the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":5682,"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,44],"class_list":["post-5681","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-arduino","category-machine-sound","tag-codecs","tag-uno"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>ADPCM and WAV Files - 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\/05\/21\/adpcm-and-wav-files\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"ADPCM and WAV Files - Phil Schatzmann\" \/>\n<meta property=\"og:description\" content=\"At the very beginning of my Arduino AudioTools project, I was providing a codec for WAV files. It was just handling PCM audio, so it just needed to read or write the header and then could just copy the audio data. In my last blog, I was writing that the [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pschatzmann.ch\/home\/2023\/05\/21\/adpcm-and-wav-files\/\" \/>\n<meta property=\"og:site_name\" content=\"Phil Schatzmann\" \/>\n<meta property=\"article:published_time\" content=\"2023-05-21T04:48:27+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-04-10T16:52:30+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/05\/wav.png\" \/>\n\t<meta property=\"og:image:width\" content=\"512\" \/>\n\t<meta property=\"og:image:height\" content=\"512\" \/>\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\\\/2023\\\/05\\\/21\\\/adpcm-and-wav-files\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/05\\\/21\\\/adpcm-and-wav-files\\\/\"},\"author\":{\"name\":\"pschatzmann\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"headline\":\"ADPCM and WAV Files\",\"datePublished\":\"2023-05-21T04:48:27+00:00\",\"dateModified\":\"2025-04-10T16:52:30+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/05\\\/21\\\/adpcm-and-wav-files\\\/\"},\"wordCount\":163,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/05\\\/21\\\/adpcm-and-wav-files\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/wav.png\",\"keywords\":[\"Codecs\",\"UNO\"],\"articleSection\":[\"Arduino\",\"Machine Sound\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/05\\\/21\\\/adpcm-and-wav-files\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/05\\\/21\\\/adpcm-and-wav-files\\\/\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/05\\\/21\\\/adpcm-and-wav-files\\\/\",\"name\":\"ADPCM and WAV Files - Phil Schatzmann\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/05\\\/21\\\/adpcm-and-wav-files\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/05\\\/21\\\/adpcm-and-wav-files\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/wav.png\",\"datePublished\":\"2023-05-21T04:48:27+00:00\",\"dateModified\":\"2025-04-10T16:52:30+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/05\\\/21\\\/adpcm-and-wav-files\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/05\\\/21\\\/adpcm-and-wav-files\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/05\\\/21\\\/adpcm-and-wav-files\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/wav.png\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2023\\\/05\\\/wav.png\",\"width\":512,\"height\":512},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2023\\\/05\\\/21\\\/adpcm-and-wav-files\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"ADPCM and WAV Files\"}]},{\"@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":"ADPCM and WAV Files - 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\/05\/21\/adpcm-and-wav-files\/","og_locale":"en_US","og_type":"article","og_title":"ADPCM and WAV Files - Phil Schatzmann","og_description":"At the very beginning of my Arduino AudioTools project, I was providing a codec for WAV files. It was just handling PCM audio, so it just needed to read or write the header and then could just copy the audio data. In my last blog, I was writing that the [&hellip;]","og_url":"https:\/\/www.pschatzmann.ch\/home\/2023\/05\/21\/adpcm-and-wav-files\/","og_site_name":"Phil Schatzmann","article_published_time":"2023-05-21T04:48:27+00:00","article_modified_time":"2025-04-10T16:52:30+00:00","og_image":[{"width":512,"height":512,"url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/05\/wav.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\/2023\/05\/21\/adpcm-and-wav-files\/#article","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/05\/21\/adpcm-and-wav-files\/"},"author":{"name":"pschatzmann","@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"headline":"ADPCM and WAV Files","datePublished":"2023-05-21T04:48:27+00:00","dateModified":"2025-04-10T16:52:30+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/05\/21\/adpcm-and-wav-files\/"},"wordCount":163,"commentCount":0,"publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/05\/21\/adpcm-and-wav-files\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/05\/wav.png","keywords":["Codecs","UNO"],"articleSection":["Arduino","Machine Sound"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pschatzmann.ch\/home\/2023\/05\/21\/adpcm-and-wav-files\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/05\/21\/adpcm-and-wav-files\/","url":"https:\/\/www.pschatzmann.ch\/home\/2023\/05\/21\/adpcm-and-wav-files\/","name":"ADPCM and WAV Files - Phil Schatzmann","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/05\/21\/adpcm-and-wav-files\/#primaryimage"},"image":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/05\/21\/adpcm-and-wav-files\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/05\/wav.png","datePublished":"2023-05-21T04:48:27+00:00","dateModified":"2025-04-10T16:52:30+00:00","breadcrumb":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/05\/21\/adpcm-and-wav-files\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pschatzmann.ch\/home\/2023\/05\/21\/adpcm-and-wav-files\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/05\/21\/adpcm-and-wav-files\/#primaryimage","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/05\/wav.png","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2023\/05\/wav.png","width":512,"height":512},{"@type":"BreadcrumbList","@id":"https:\/\/www.pschatzmann.ch\/home\/2023\/05\/21\/adpcm-and-wav-files\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pschatzmann.ch\/home\/"},{"@type":"ListItem","position":2,"name":"ADPCM and WAV Files"}]},{"@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\/5681","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=5681"}],"version-history":[{"count":3,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/5681\/revisions"}],"predecessor-version":[{"id":6684,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/5681\/revisions\/6684"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media\/5682"}],"wp:attachment":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media?parent=5681"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/categories?post=5681"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/tags?post=5681"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}