{"id":125,"date":"2025-05-29T22:33:35","date_gmt":"2025-05-29T20:33:35","guid":{"rendered":"https:\/\/pixion.be\/?p=125"},"modified":"2025-09-27T18:23:15","modified_gmt":"2025-09-27T16:23:15","slug":"pixions-audio-output","status":"publish","type":"post","link":"https:\/\/pixion.be\/index.php\/2025\/05\/29\/pixions-audio-output\/","title":{"rendered":"Pixion\u2019s Audio Output"},"content":{"rendered":"\n<p>Hello Pixioneers!<\/p>\n\n\n\n<p>Today, let\u2019s dive into the fascinating realm of sound: a world full of vibrations, codecs, and frequencies! I\u2019ll be honest with you: I have almost no knowledge about \u201caudio stuff.\u201d My experience? Extracting a few .wav files from CDs and .ogg files from game folders, converting them into .mp3 via a free online tool while clicking random settings without really knowing what I was doing.<\/p>\n\n\n\n<p>I\u2019ve always used the built-in speakers on my TV or monitor. I\u2019ve never owned any kind of fancy, alien, hi-tech, multi-channel amplifier box. In short: I come from far away in terms of audio expertise. That\u2019s also why, back in my earlier architecture post, I wasn\u2019t sure at all what direction I wanted to take on this front.<\/p>\n\n\n\n<p>So\u2026 let\u2019s embark on this auditory journey together.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">1. File Format<\/h3>\n\n\n\n<p>Before anything plays, we need to decide what we\u2019re playing. That means choosing a file format.<\/p>\n\n\n\n<p>From what I\u2019ve read, audio files generally fall into three main categories:<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table class=\"has-fixed-layout\"><thead><tr><th class=\"has-text-align-center\" data-align=\"center\">Type<\/th><th class=\"has-text-align-center\" data-align=\"center\">Quality Impact<\/th><th class=\"has-text-align-center\" data-align=\"center\">Size Impact<\/th><th class=\"has-text-align-center\" data-align=\"center\">Examples<\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\">Uncompressed<\/td><td class=\"has-text-align-center\" data-align=\"center\">Highest quality (if recorded properly)<\/td><td class=\"has-text-align-center\" data-align=\"center\">Heavy<\/td><td class=\"has-text-align-center\" data-align=\"center\"><code>.<\/code>wav, .aiff, .pcm, .raw<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Lossless compression<\/td><td class=\"has-text-align-center\" data-align=\"center\">No quality loss<\/td><td class=\"has-text-align-center\" data-align=\"center\">Lighter<\/td><td class=\"has-text-align-center\" data-align=\"center\">.flac, .ape, .wv, .m4a (can be lossless or lossy, depending on codec)<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Lossy compression<\/td><td class=\"has-text-align-center\" data-align=\"center\">Quality reduced (though often imperceptibly)<\/td><td class=\"has-text-align-center\" data-align=\"center\">Lightest<\/td><td class=\"has-text-align-center\" data-align=\"center\">.mp3, .aac, .ogg, .opus<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>Nowadays, flash memory is cheap and SD cards with lots of space are everywhere. So I\u2019m not too concerned about file size. For simplicity, I\u2019ve decided to go with .wav files. They\u2019re easy to read, widely supported, and don\u2019t require any decompression algorithm. That\u2019s perfect for the microcontroller.<\/p>\n\n\n\n<p>Of course, if I ever want to tinker with decoders later (and I probably will ^^), I\u2019ll still be able to explore formats like .mp3 or .ogg. But to get things running, .wav is a good first step.<\/p>\n\n\n\n<p>Just a quick technical note: a .wav file begins with a 44-byte header that contains info like the format, sample rate, and number of channels. After that comes the raw sound data itself. We\u2019ll get into the details of how that works when we look at the embedded software side of things.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Audio generation<\/strong><\/h3>\n\n\n\n<p>Now that we know what we want to play, let\u2019s shift our focus to how we\u2019re going to make that sound a reality \u2014 and not just data sitting on an SD card.<\/p>\n\n\n\n<p>Each sample in a .wav file is a digital representation of an audio waveform&#8217;s amplitude at a given point in time. So, in theory, we just need to convert these values into voltages, send them to a speaker, and voil\u00e0 &#8230; sound!<\/p>\n\n\n\n<p>Right? &#8230; Right?<\/p>\n\n\n\n<p>Well\u2026 not quite. As usual, reality is a bit more complicated. Let\u2019s keep going on our exploratory audio quest.<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">From Digital to Audible<\/h6>\n\n\n\n<p>We\u2019ve seen how the audio data is stored and how we can get it into the microcontroller\u2019s memory. But digital data can\u2019t move air on its own. To be heard, it needs to be transformed into physical vibrations, in other words, a sound wave.<\/p>\n\n\n\n<p>Traditionally, this meant using a Digital-to-Analog Converter (DAC) to generate an analog signal, and sending that out through connectors like 3.5 mm jacks, RCA, XLR, or DIN. The audio device on the other end (a speaker, headphones, etc.) would do the rest.<\/p>\n\n\n\n<p>But today, many modern audio devices (TVs, speakers, wireless earbuds, etc.) already include their own DACs. When that\u2019s the case, it can be more efficient to send the audio as a digital signal, reducing noise and preserving quality over long cables. Common connectors for digital audio include USB, Toslink (optical), and sometimes even RCA or XLR.<\/p>\n\n\n\n<p>And of course, we can also send sound wirelessly via Bluetooth, Wi-Fi, and other radio-based protocols.<\/p>\n\n\n\n<p>For now, I\u2019m keeping things simple. Pixion will start with analog output via a 3.5mm stereo jack. I don\u2019t have exotic gear, and I\u2019m not aiming for audiophile-grade performance as I just want to make sound happen cleanly. That said, I\u2019ll likely leave room for an extension board, so I can add digital or wireless output later on, if the need or curiosity arises.<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">Audio Amplification<\/h6>\n\n\n\n<p>The output of a DAC, especially one built into a microcontroller, isn\u2019t strong enough to drive a speaker or even most headphones directly. We need to amplify it.<\/p>\n\n\n\n<p>As I started learning about amplifiers, I discovered that there are multiple types, categorized into different \u201cclasses\u201d, each with its own trade-offs in terms of efficiency, quality, and complexity. Here\u2019s a simplified overview of what I found:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Class<\/th><th>Operation<\/th><th>Efficiency<\/th><th>Audio Quality<\/th><th>Strengths<\/th><th>Weaknesses<\/th><\/tr><\/thead><tbody><tr><td><strong>A<\/strong><\/td><td>Always conducting<\/td><td>~25\u201330%<\/td><td>Excellent<\/td><td>Ultra low distortion<\/td><td>Hot, inefficient<\/td><\/tr><tr><td><strong>B<\/strong><\/td><td>Push-pull halves<\/td><td>~50\u201360%<\/td><td>Moderate<\/td><td>Simple<\/td><td>Crossover distortion<\/td><\/tr><tr><td><strong>AB<\/strong><\/td><td>Overlapping push-pull<\/td><td>~50\u201370%<\/td><td>Very good<\/td><td>Good balance<\/td><td>Still gets warm<\/td><\/tr><tr><td><strong>D<\/strong><\/td><td>PWM switching<\/td><td>&gt;90%<\/td><td>Good \u2192 Very Good<\/td><td>Efficient, compact<\/td><td>Needs filtering<\/td><\/tr><tr><td><strong>G<\/strong><\/td><td>Multiple power rails<\/td><td>~60\u201375%<\/td><td>Very good<\/td><td>Improved efficiency<\/td><td>Complex design<\/td><\/tr><tr><td><strong>H<\/strong><\/td><td>Variable power supply<\/td><td>~70\u201380%<\/td><td>Very good<\/td><td>Dynamic power scaling<\/td><td>Complex design<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>I\u2019m sure there are more out there (such as class-T, etc.), but these are the most common I came across.<\/p>\n\n\n\n<p>At first, I thought about designing my own amplifier. It sounded fun on paper but let\u2019s be honest: this project is already ambitious, and audio isn\u2019t the part that excites me the most. So I\u2019ve decided to use an off-the-shelf amplifier for now.<\/p>\n\n\n\n<p>That said, I still want the option to experiment with custom amps in the future. To keep things flexible, I\u2019ll add a connector to the board so I can plug in my own amplifier module later on.<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">Matching Power and Impedance<\/h6>\n\n\n\n<p>Choosing an amplifier is only half the story: we also need to know what kind of load it\u2019s going to drive. In audio, that mostly means knowing its impedance.<\/p>\n\n\n\n<p>From what I\u2019ve found, headphone impedance can range from 8 to 600 ohms, though most commonly it\u2019s 16 or 32 ohms. Loudspeakers usually fall between 4 and 8 ohms, sometimes up to 16 ohms for specific designs.<\/p>\n\n\n\n<h6 class=\"wp-block-heading\">The Chosen One<\/h6>\n\n\n\n<p>So what amplifier did I choose?<\/p>\n\n\n\n<p>After all that research, I\u2019ve selected the MAX98357A. It\u2019s a compact Class D amplifier that outputs up to 3W into a 4\u20138 ohm speaker, with an efficiency of around 92%. It only offers mono output, so if we ever want stereo, we\u2019ll need to use two of them.<\/p>\n\n\n\n<p>It\u2019s compatible with 3.3V logic, which makes it a great match for modern microcontrollers. Even better, it takes digital audio in via I\u00b2S, a protocol designed specifically for high-quality audio transfer. That means I won\u2019t need a separate DAC, and I\u00b2S will also help keep noise down on the PCB.<\/p>\n\n\n\n<p>Also\u2026 I just wanted to experiment with I\u00b2S. \ud83d\ude42<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">Wrapping Up<\/h3>\n\n\n\n<p>Phew. That was a lot. I\u2019ll admit this article is a bit less structured than usual. The audio world is a deep, winding place, and I\u2019m still finding my bearings. But we\u2019ve covered the essentials to go from .wav file to real-world sound, and that\u2019s a big step forward.<\/p>\n\n\n\n<p>In the next post, we\u2019ll tackle the controller so we can finally interact with our little Pixion. Until then, keep exploring.<\/p>\n\n\n\n<p class=\"has-text-align-right\">Pix&#8217;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello Pixioneers! Today, let\u2019s dive into the fascinating realm of sound: a world full of vibrations, codecs, and frequencies! I\u2019ll be honest with you: I have almost no knowledge about \u201caudio stuff.\u201d My experience? Extracting a few .wav files from CDs and .ogg files from game folders, converting them into .mp3 via a free online&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"footnotes":""},"categories":[24],"tags":[26,3,4,10,11,9,7],"class_list":["post-125","post","type-post","status-publish","format-standard","hentry","category-architecture","tag-audio","tag-diy","tag-electronics","tag-hardware","tag-hobbyist","tag-learning-journey","tag-pixion"],"_links":{"self":[{"href":"https:\/\/pixion.be\/index.php\/wp-json\/wp\/v2\/posts\/125","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/pixion.be\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/pixion.be\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/pixion.be\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/pixion.be\/index.php\/wp-json\/wp\/v2\/comments?post=125"}],"version-history":[{"count":15,"href":"https:\/\/pixion.be\/index.php\/wp-json\/wp\/v2\/posts\/125\/revisions"}],"predecessor-version":[{"id":149,"href":"https:\/\/pixion.be\/index.php\/wp-json\/wp\/v2\/posts\/125\/revisions\/149"}],"wp:attachment":[{"href":"https:\/\/pixion.be\/index.php\/wp-json\/wp\/v2\/media?parent=125"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/pixion.be\/index.php\/wp-json\/wp\/v2\/categories?post=125"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/pixion.be\/index.php\/wp-json\/wp\/v2\/tags?post=125"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}