<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Made Indrayana on Medium]]></title>
        <description><![CDATA[Stories by Made Indrayana on Medium]]></description>
        <link>https://medium.com/@made-indrayana?source=rss-363fb115145d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*GGRQDBvRBFas_XUzRgM9ig.png</url>
            <title>Stories by Made Indrayana on Medium</title>
            <link>https://medium.com/@made-indrayana?source=rss-363fb115145d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 06:55:01 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@made-indrayana/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Sample Rate - What Audio Resolution Has to Do with Your Game]]></title>
            <link>https://medium.com/@made-indrayana/sample-rate-what-audio-resolution-has-to-do-with-your-game-d360025c0cc6?source=rss-363fb115145d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d360025c0cc6</guid>
            <category><![CDATA[indie-game-dev]]></category>
            <category><![CDATA[game-audio]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Made Indrayana]]></dc:creator>
            <pubDate>Tue, 21 Jul 2020 13:22:41 GMT</pubDate>
            <atom:updated>2020-07-21T13:22:41.790Z</atom:updated>
            <content:encoded><![CDATA[<p>Today we’ll be talking about the Sample Rate options in Unity’s Audio Import Settings and why understanding sample rate is important for <strong>your game</strong>.</p><p>This blog post has been made as a supplement to our video tutorial on this same topic.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DPLaTdxrbUcR8IcWkBEvOc9yJ-vD54AxmEb&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DdRSNyw7DRUs&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FdRSNyw7DRUs%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/40bd7e7f3346cdb014b70c515969a4f4/href">https://medium.com/media/40bd7e7f3346cdb014b70c515969a4f4/href</a></iframe><h3>Introduction</h3><p>We’ve arrived at the final topic of our Unity Audio Import Settings series, the Sample Rate setting.</p><p>For people who don’t know the basic theory of digital audio, the term sample rate may sound cryptic and doesn’t say much about what it is and what effect it has on audio quality.</p><p>I think it is best then to quickly explain the concept of sample rate and then we will see and hear the difference it makes for our audio assets in Unity.</p><h3>Sample Rate: Basic Theory</h3><p>Let’s start with the question: <strong>what is Sample Rate in audio</strong>? To be able to explain that, we have to understand what sound is and how it is stored in a digital format.</p><p>Normal, everyday sound is transmitted through space and to our ears by <em>sound waves</em>. What does a sound wave look like? Let’s take a look at the mother of all sound: a sine wave</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lnr7xxa3FGJCxZ6sJrj2dQ.png" /><figcaption>Ride the wave</figcaption></figure><p>We can see here a smooth sine wave oscillating 500 times per second. Another term you might have heard is <strong>Hertz (Hz)</strong>. A sound wave oscillating 500 times a second is a 500 Hz sound wave. Here’s what this sine wave sounds like:</p><p>The curve of this wave looks perfectly smooth, but if we zoom in close enough, we start to see that it is actually made up of <em>tiny steps</em>. This is what we call <strong>samples.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7If5by498o97aO3hkK5mGA.png" /><figcaption>Digital waveforms look more like a staircase if you zoom in far enough</figcaption></figure><p>Think about it like pixels in a picture. When you zoom in to the level of a pixel, you see only one color. But once you zoom out and see the other pixels around that which contain other colors, you start to understand the picture as a whole.</p><p>In picture, this is defined as the picture resolution, like 1920 pixels by 1080 pixels, which tells us how many pixels are there in the horizontal and vertical plane.</p><p>Sample rate is essentially the picture resolution of digital audio and the numbers we see here like 44.1 kHz and 48 kHz represent how many (thousands) of times an audio source was “sampled” over one second. Just like with pictures, a higher sample rate means higher audio resolution.</p><p>So what is actually stored in these samples and what do these numbers mean?</p><p>In pixels, you would store information about color and intensity. In our audio samples, we store <strong>amplitude</strong> or the<strong> </strong><em>volume information</em> of the sound wave at that particular point in time.</p><p>To summarize, audio data contains <em>x</em> amount of <em>samples per second</em> and each sample contains the <em>volume information</em> of the sound wave at the exact point in time it was recorded. Cool? Cool.</p><p>But what does 44,1 kHz or 48 kHz mean? Those numbers are gibberish to me. Human hearing range only goes as high as 20 kHz, right?</p><p>True, we humans can only hear frequencies ranging from 20 Hz to 20 kHz. The people behind those odd numbers for sample rate are <a href="https://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem"><strong>Harry Nyquist</strong> <strong>and</strong> <strong>Claude Shannon</strong></a>. In a nutshell, they concluded that you need to sample an audio signal <em>twice as many times per second as the highest frequency that you want to capture</em>. Alas, 44,1 kHz was born as the bare minimum sample rate to represent all of the frequency that humans can hear, plus a little headroom.</p><p>Even though 44,1 kHz is the bare minimum, and the standard sample rate for CD, 48 kHz has been the long-standing standard in audio for motion picture.</p><p>There are other sample rates, but we won’t discuss the technical reasons, advantages, and disadvantages for having higher sample rates like 48 kHz, 88,2 kHz, 96 kHz, as that is another topic entirely.</p><h3>Sample Rate in Unity</h3><p>Now that we understand sample rate, let’s go to Unity and get a little bit more practical.</p><p>When you click on an audio asset, you can see its sample rate in the asset preview window on the bottom right.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*dikfrfyEd_lYt-MRnE4vMg.png" /></figure><p>Right now we have an Earthquake Rumble and some other files sampled in 48 kHz. Let’s take a listen to this earthquake rumble.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F861240955%26show_artwork%3Dtrue%26secret_token%3Ds-VeTfo4BXW82&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fearthquake-rumble-original-01%2Fs-VeTfo4BXW82&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/ebc99fc424e847934b8a72a808e61fc1/href">https://medium.com/media/ebc99fc424e847934b8a72a808e61fc1/href</a></iframe><p>By default Unity will always “Preserve Sample Rate”, meaning it will not change the sample rate of the original audio file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*Yd5cHzlkgIZbCfn74G5VAQ.png" /></figure><h4>Optimize Sample Rate</h4><p>Let’s select “Optimize Sample Rate” and see what happens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*KkmY2bHbZaif458Os5LHng.png" /></figure><p><strong>Boom</strong>. The size of the audio file has been reduced to only 5% of the original because the sample rate has dropped from 48 kHz to a mere 3.7 kHz.</p><p>Hold on, what happened just now?</p><p>Because this audio doesn’t really have any high-frequency content, Unity’s frequency content analyzer found that the highest frequency of importance in this particular audio file is just around 7.4 kHz, so it reduced the sample rate to around two times the highest frequency, thus drastically reducing the file size</p><p>Take a listen again.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F861240952%26show_artwork%3Dtrue%26secret_token%3Ds-qqyClK1nyIn&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fearthquake-rumble-unity-sample%2Fs-qqyClK1nyIn&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/501459f5bacb74471e7cc513c8476274/href">https://medium.com/media/501459f5bacb74471e7cc513c8476274/href</a></iframe><p>I heard something that wasn’t there before that sounds like an 8-bit artifact. Do you hear that too?</p><p>Let’s put both versions of the audio into a program with a spectrogram view to see what exactly is happening.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1PVXZAxRd2phMzo7ohEh3w.png" /></figure><p>As we can see from the original 48 kHz audio file, Unity was not 100% correct with its analysis. It’s true that there’s not <em>much </em>going on above 3,7 kHz, but it is <strong>not</strong> true that there’s nothing above that.</p><p>Let’s see what happened to the downsampled audio.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q01Y6BgjTS5DC-Wz5QCsvg.png" /></figure><p>Here we can see the two “lines” that were visible in the original audio disappeared from the top but then<em> </em>appeared again at the bottom. This is a normal occurrence and it is called <strong>aliasing</strong><em>.</em></p><p>To keep things short: aliasing will happen if your sample rate converter is not good enough.</p><p>Audio aliasing results in artifacts, sometimes clearly audible and sometimes very subtle. In our case right with this earthquake sound effect, it added an 8-bit-like sound that gives the impression of the sound being very low quality.</p><p>Let’s try it on a few other audio files to see if they’re any different.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F861240961%26show_artwork%3Dtrue%26secret_token%3Ds-r0BgAzf8mRt&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fearthquake-big-original-02%2Fs-r0BgAzf8mRt&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6e3d43f340b1ffe3f6c74d105f1128a/href">https://medium.com/media/c6e3d43f340b1ffe3f6c74d105f1128a/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F861811477%26show_artwork%3Dtrue%26secret_token%3Ds-Nb6eX1EVyWk&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fearthquake-big-optimize-sample-rate%2Fs-Nb6eX1EVyWk&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/149dcce83fb8bbf6c0b6520f7f9a54fc/href">https://medium.com/media/149dcce83fb8bbf6c0b6520f7f9a54fc/href</a></iframe><p>With this file, it doesn’t reduce the sample rate because the frequency content in this file spans to the highest possible frequency, thus no optimization could occur.</p><p>How about a different audio file?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F861240892%26show_artwork%3Dtrue%26in%3Ddoubleshot-audio%252Fsets%252Fsample-rate-video%252Fs-PL02N6XEhrb%26secret_token%3Ds-TXr9UYEaAZb&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fwaterfalls-original-03%2Fs-TXr9UYEaAZb%3Fin%3Ddoubleshot-audio%2Fsets%2Fsample-rate-video%2Fs-PL02N6XEhrb&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4fd73fb2460b810bc18fe994c8ac299/href">https://medium.com/media/c4fd73fb2460b810bc18fe994c8ac299/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F861811177%26show_artwork%3Dtrue%26secret_token%3Ds-cOjfsgOBJdm&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fwaterfalls-optimize-sample-rate2%2Fs-cOjfsgOBJdm&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/3889ca66c97c651661802322a8e34dcf/href">https://medium.com/media/3889ca66c97c651661802322a8e34dcf/href</a></iframe><p>Same thing here with the waterfall.</p><p>Let’s try the military radio.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F861240919%26show_artwork%3Dtrue%26in%3Ddoubleshot-audio%252Fsets%252Fsample-rate-video%252Fs-PL02N6XEhrb%26secret_token%3Ds-yQkkZIJBp8w&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fmilitary-radio-original-04%2Fs-yQkkZIJBp8w%3Fin%3Ddoubleshot-audio%2Fsets%2Fsample-rate-video%2Fs-PL02N6XEhrb&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/fcfe7bc1ef2868ed98809774aaf9bbc3/href">https://medium.com/media/fcfe7bc1ef2868ed98809774aaf9bbc3/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F861240934%26show_artwork%3Dtrue%26in%3Ddoubleshot-audio%252Fsets%252Fsample-rate-video%252Fs-PL02N6XEhrb%26secret_token%3Ds-1hRSBqEEufT&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fmilitary-audio-unity-sample%2Fs-1hRSBqEEufT%3Fin%3Ddoubleshot-audio%2Fsets%2Fsample-rate-video%2Fs-PL02N6XEhrb&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/4f3be39ed879d826ec9a674ea4001bf1/href">https://medium.com/media/4f3be39ed879d826ec9a674ea4001bf1/href</a></iframe><p>Some degree of optimization occurs here but it has again changed the original sound slightly by reducing the sample rate too much, leaving us with less high-frequency content. The optimized version has a more lo-fi vibe than the original one and from a creative perspective it might fit the project better, but I still like the original version more because it sounds more authentic.</p><p>The <strong>main lesson</strong> to learn here is that it’s perhaps better not to trust Unity to automatically optimize your sample rate and keep the “Preserve Sample Rate” setting to retain your original quality. If your concern is to optimize space, you might want to experiment more with your <a href="https://bit.ly/2VLwmld">audio compression formats</a>.</p><h4>Override Sample Rate</h4><p>Let’s take a look at the last option: Override Sample Rate.</p><p>When you select Override Sample Rate, you are given a selection of pre-defined sample rates that you can choose from.</p><p>You already know what happens when you try to downsample audio — you get less high-frequency content and eventually aliasing. If this yields a desirable “effect” for your sound design, e.g. to make it lo-fi and grainy, this option could be helpful.</p><p>This is, however, <strong>not best practice</strong> because results will vary with different audio files. It’s recommended that you take care of your sound effects <em>before</em> importing them into Unity.</p><p>For the sake of it, let’s try downsampling a few of our audio assets in the scene.</p><h4>Example 1: Earthquake</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F861240961%26show_artwork%3Dtrue%26in%3Ddoubleshot-audio%252Fsets%252Fsample-rate-video%252Fs-PL02N6XEhrb%26secret_token%3Ds-r0BgAzf8mRt&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fearthquake-big-original-02%2Fs-r0BgAzf8mRt%3Fin%3Ddoubleshot-audio%2Fsets%2Fsample-rate-video%2Fs-PL02N6XEhrb&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/77d063440acc1fa478ab0f5394d4b459/href">https://medium.com/media/77d063440acc1fa478ab0f5394d4b459/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F861240946%26show_artwork%3Dtrue%26in%3Ddoubleshot-audio%252Fsets%252Fsample-rate-video%252Fs-PL02N6XEhrb%26secret_token%3Ds-4yAeZEurjem&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Feartrhquake-big-22khz%2Fs-4yAeZEurjem%3Fin%3Ddoubleshot-audio%2Fsets%2Fsample-rate-video%2Fs-PL02N6XEhrb&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5a2bb2a43446184230934cd9a846034/href">https://medium.com/media/e5a2bb2a43446184230934cd9a846034/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F861240949%26show_artwork%3Dtrue%26in%3Ddoubleshot-audio%252Fsets%252Fsample-rate-video%252Fs-PL02N6XEhrb%26secret_token%3Ds-6rUaI63eXQM&amp;display_name=SoundCloud&amp;url=http%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Feartrhquake-big-11khz%2Fs-6rUaI63eXQM%3Fin%3Ddoubleshot-audio%2Fsets%2Fsample-rate-video%2Fs-PL02N6XEhrb&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce6edebac6483775392f36fa8caa6c92/href">https://medium.com/media/ce6edebac6483775392f36fa8caa6c92/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F861240940%26show_artwork%3Dtrue%26in%3Ddoubleshot-audio%252Fsets%252Fsample-rate-video%252Fs-PL02N6XEhrb%26secret_token%3Ds-9o0LAyhfMDY&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Feartrhquake-big-8-khz%2Fs-9o0LAyhfMDY%3Fin%3Ddoubleshot-audio%2Fsets%2Fsample-rate-video%2Fs-PL02N6XEhrb&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/0f05e82035e9e964dcb7589eaa388a9c/href">https://medium.com/media/0f05e82035e9e964dcb7589eaa388a9c/href</a></iframe><h4>Example 2: Waterfall</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F861240892%26show_artwork%3Dtrue%26in%3Ddoubleshot-audio%252Fsets%252Fsample-rate-video%252Fs-PL02N6XEhrb%26secret_token%3Ds-TXr9UYEaAZb&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fwaterfalls-original-03%2Fs-TXr9UYEaAZb%3Fin%3Ddoubleshot-audio%2Fsets%2Fsample-rate-video%2Fs-PL02N6XEhrb&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/c4fd73fb2460b810bc18fe994c8ac299/href">https://medium.com/media/c4fd73fb2460b810bc18fe994c8ac299/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F861240901%26show_artwork%3Dtrue%26in%3Ddoubleshot-audio%252Fsets%252Fsample-rate-video%252Fs-PL02N6XEhrb%26secret_token%3Ds-FJuFJw31htA&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fwaterfall-22khz-downsampling%2Fs-FJuFJw31htA%3Fin%3Ddoubleshot-audio%2Fsets%2Fsample-rate-video%2Fs-PL02N6XEhrb&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/37473a70b100324cfeaa3c197001fd8a/href">https://medium.com/media/37473a70b100324cfeaa3c197001fd8a/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F861240904%26show_artwork%3Dtrue%26in%3Ddoubleshot-audio%252Fsets%252Fsample-rate-video%252Fs-PL02N6XEhrb%26secret_token%3Ds-kzG2YsUia1Y&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fwaterfall-11khz-downsampling%2Fs-kzG2YsUia1Y%3Fin%3Ddoubleshot-audio%2Fsets%2Fsample-rate-video%2Fs-PL02N6XEhrb&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/ab5988a3163f7e5d6dc15dcf51bc1a99/href">https://medium.com/media/ab5988a3163f7e5d6dc15dcf51bc1a99/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F861240895%26show_artwork%3Dtrue%26in%3Ddoubleshot-audio%252Fsets%252Fsample-rate-video%252Fs-PL02N6XEhrb%26secret_token%3Ds-LT5LZC37BMp&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fwaterfall-8khz-downsampling-v2%2Fs-LT5LZC37BMp%3Fin%3Ddoubleshot-audio%2Fsets%2Fsample-rate-video%2Fs-PL02N6XEhrb&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a102851003c054ae5eecd01caa25152/href">https://medium.com/media/1a102851003c054ae5eecd01caa25152/href</a></iframe><h4>Example 3: Music</h4><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F861807115%26show_artwork%3Dtrue%26in%3Ddoubleshot-audio%252Fsets%252Fsample-rate-video%252Fs-PL02N6XEhrb%26secret_token%3Ds-86zcYgqRvfg&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fmusic-original%2Fs-86zcYgqRvfg%3Fin%3Ddoubleshot-audio%2Fsets%2Fsample-rate-video%2Fs-PL02N6XEhrb&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d01bd8c0aeb4f1a6c322b28099bd66e/href">https://medium.com/media/5d01bd8c0aeb4f1a6c322b28099bd66e/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F861240913%26show_artwork%3Dtrue%26in%3Ddoubleshot-audio%252Fsets%252Fsample-rate-video%252Fs-PL02N6XEhrb%26secret_token%3Ds-Lj6V6huNdxO&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fmusic-22khz-downsampling-v2%2Fs-Lj6V6huNdxO%3Fin%3Ddoubleshot-audio%2Fsets%2Fsample-rate-video%2Fs-PL02N6XEhrb&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/845c42ac0609da272888da0a351a1d28/href">https://medium.com/media/845c42ac0609da272888da0a351a1d28/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F861240916%26show_artwork%3Dtrue%26in%3Ddoubleshot-audio%252Fsets%252Fsample-rate-video%252Fs-PL02N6XEhrb%26secret_token%3Ds-v7w61A5bI0p&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fmusic-11khz-downsampling-v2%2Fs-v7w61A5bI0p%3Fin%3Ddoubleshot-audio%2Fsets%2Fsample-rate-video%2Fs-PL02N6XEhrb&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/82eb56f82045c415c328e6cee0112af6/href">https://medium.com/media/82eb56f82045c415c328e6cee0112af6/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F861240910%26show_artwork%3Dtrue%26in%3Ddoubleshot-audio%252Fsets%252Fsample-rate-video%252Fs-PL02N6XEhrb%26secret_token%3Ds-rZAhBm72Me7&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fmusic-8khz-downsampling-v2%2Fs-rZAhBm72Me7%3Fin%3Ddoubleshot-audio%2Fsets%2Fsample-rate-video%2Fs-PL02N6XEhrb&amp;image=https%3A%2F%2Fsoundcloud.com%2Fimages%2Ffb_placeholder.png&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/343a49626aac8110ead0147a852e09d5/href">https://medium.com/media/343a49626aac8110ead0147a852e09d5/href</a></iframe><p>A final note on sample rate: Upsampling audio will produce no artifacts but also has no advantages. It would not make your audio have more “resolution”, it will just make the file larger which will take up unnecessary space. It will also not change the quality of the original audio.</p><h3>Final Words</h3><p>So, let’s summarize:</p><ul><li><strong>Preserve Sample Rate</strong> is already the <strong>best option</strong> for 99% of your audio assets. <em>Finally, </em>we find a default Unity setting that is actually the best choice.</li><li><strong>Optimize</strong> and <strong>Override Sample Rate</strong> settings could in <em>rare cases</em> be helpful if you want to give some sound effects that “lofi” feeling, but we would recommend doing this with proper audio software instead simply because Unity’s sample rate converter is not particularly good.</li></ul><p>That’s it! We hope this tutorial has helped you to understand the Sample Rate options in Unity’s Import Settings and why this information is important for <strong>your game</strong>.</p><p>If you want to learn more about how audio functions in Unity, be sure to check out our other tutorials <em>(linked below)</em>. If you have a question, leave it in the comments or contact us directly through our website:</p><p><a href="https://doubleshot-audio.com/">Double Shot Audio</a></p><h3>Other Tutorials:</h3><ul><li><a href="https://medium.com/double-shot-audio/load-in-background-optimizing-audio-load-times-in-unity-33d3cc04c47e">Load in Background - Optimizing Audio Load Times in Unity</a></li><li><a href="https://medium.com/double-shot-audio/preload-audio-data-how-unity-decides-which-audio-assets-to-load-to-a-scene-a440a654e7e2">Preload Audio Data &amp; How Unity Decides Which Audio Assets to Load to a Scene</a></li><li><a href="https://medium.com/double-shot-audio/understanding-audio-compression-settings-in-unity-e879a821023f">Understanding Audio Compression Settings in Unity</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d360025c0cc6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Load in Background - Optimizing Audio Load Times in Unity]]></title>
            <link>https://medium.com/@made-indrayana/load-in-background-optimizing-audio-load-times-in-unity-33d3cc04c47e?source=rss-363fb115145d------2</link>
            <guid isPermaLink="false">https://medium.com/p/33d3cc04c47e</guid>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[indie-game-dev]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[game-audio]]></category>
            <dc:creator><![CDATA[Made Indrayana]]></dc:creator>
            <pubDate>Thu, 18 Jun 2020 07:38:08 GMT</pubDate>
            <atom:updated>2020-06-18T07:48:34.366Z</atom:updated>
            <content:encoded><![CDATA[<p>Today we’ll be talking about the Load in Background option in Unity’s Audio Import Settings and why deferring the loading of certain audio assets is important for <strong>your game</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/590/1*0DlbByrE-p6KpXGjB3dqoQ.jpeg" /><figcaption>What’s going on in the background? Could it be game audio optimization?</figcaption></figure><p><em>Editor’s Note: Compression Formats, Load Type and the Preload Audio Data/Load in Background settings go hand in hand. We recommend reading our blog posts on all three in the following order for a complete overview:</em></p><p>Blog 1: <a href="https://bit.ly/2VLwmld">Compression Formats</a></p><p>Blog 2: <a href="https://bit.ly/2W5pQXA">Load Types</a></p><p>Blog 3: <a href="https://bit.ly/2Xan4Rn">Preload Audio Data</a></p><p>Blog 4: Load in Background (this post)</p><p>This blog post has been made as a supplement to our video tutorial on this same topic.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DPLaTdxrbUcR8IcWkBEvOc9yJ-vD54AxmEb&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DOGmt7pgFXXI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FOGmt7pgFXXI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ecc4a6eadf296087986bfbb76589f7b/href">https://medium.com/media/3ecc4a6eadf296087986bfbb76589f7b/href</a></iframe><h3>Introduction</h3><p>If you haven’t check out our tutorial on <a href="https://bit.ly/2Xan4Rn">Preload Audio Data</a>, we’d recommend doing so before continuing. These two options are intricately related and it’s important to understand how they function in context.</p><p>If our <a href="https://bit.ly/2W5pQXA">Load Type</a> settings determine <strong>how</strong> our audio assets will be loaded, then the Preload Audio Data and Load in Background settings determine <strong>when</strong><em> </em>they will be loaded. This tutorial explains why optimizing the <em>“when”</em> factor is so important for your game’s performance</p><h3>Load in Background</h3><p>The Unity Manual provides a good explanation for Load in Background so let’s start there:</p><blockquote>If enabled, the audio clip will be loading in the background without causing stalls on the main thread. Note that play requests on AudioClips that are still loading in the background will be deferred until the clip is done loading.</blockquote><p>As we know from our previous tutorial, when we select Preload Audio Data, the loading of the audio files will take place <em>before</em> the scene is actually playable.</p><p>In the case that you have a lot of audio data to be loaded and decompressed into memory, and the loading of all other game elements is done, the scene loading process will be stalled by the audio. This can be good because the loading process <strong>will not interrupt real-time gameplay</strong>.</p><p>However, any audio elements that aren’t needed in the scene within the first few seconds of gameplay may be <em>unnecessarily delaying the start of the scene</em>.</p><h4>Preload Audio Data &amp; Load in Background</h4><p>If we select both Preload Audio Data and Load in Background, our assets will begin loading with the scene but they will not stall the main thread should the scene be ready to play before the audio assets are.</p><p>I’ll repeat, <em>any AudioClips that are needed right away in the scene should be marked with Preload Audio Data </em><strong><em>only</em></strong> to ensure they are playable from the first moment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*dnTEqGOQyLjEzO49uiK-0A.png" /><figcaption>Select Preload Audio Data ONLY for audio assets needed immediately in the scene.</figcaption></figure><p>Let’s dig a little deeper:</p><p>If an AudioClip is marked with Load in Background ONLY, the loading process will only begin once the AudioClip has been called in the scene. Since there will be a small delay between loading the clip and playing, this could result in an out-of-sync sound effect in relation to the picture or action.</p><p>If you try to play an AudioClip which has not been marked with either Load in Background <em>or</em><strong> </strong>Preload Audio Data, it will not only <strong>not load</strong> until the clip is called in the scene, it will also <strong>stall the main thread</strong> until loading is finished. If the audio file is too big, this could result in a frame hitch, i.e. the frame freezing for the few milliseconds that are needed to load the file. That is obviously a situation that we under no circumstances can allow to happen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*5OB0r2xytdcZmYi6vJRODQ.jpeg" /><figcaption>Game Dev 101: No amount of lag is acceptable in any game.</figcaption></figure><p>Up to this point, we have heard the phrase <em>“stalling the main thread”</em> several times. Let’s take a look at what that means in a real-world example.</p><h4>Stalling the Main Thread</h4><p>I have a 3rd Unity scene prepared in addition to the other two I used in the Preload Audio Data tutorial. The first two scenes, however, will not play any role here other than to demonstrate scene loading time in a live build.</p><p>The scene contains a 500 MB audio file with a video of a second counter, normally used for diagnosing latency issues between your video and audio output.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*iizE3evoXj36JZIRdbXQ8Q.gif" /><figcaption>Classic second counter for diagnosing audio/video sync issues.</figcaption></figure><p>This video will show us whether the main thread has stalled or not. If it has, we will see the second counter stop.</p><p>Let’s check the first scenario: We’ll set the audio to <strong>Preload Audio Data only</strong>, put the AudioSource to <em>play on awake</em>, and see how long it takes to load the scene.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*74IXBX6Z0c3dvBNBw6x0wg.gif" /><figcaption>Check out our video for the full demonstration.</figcaption></figure><p>The first two scenes loaded instantly because they hardly have anything in the scene, but let’s see the third one.</p><p>It looks like it took around 6 seconds to load the scene, but the audio plays as soon as the video is played. Whether we called the AudioClip with Play on Awake or through another method, the result would still be the same because the audio was preloaded and ready to play. Now, let’s tick <strong>Load in Background as well</strong> and see what happens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*siYQLcHXqWbYrfaA0nlHSw.gif" /></figure><p>The scene loads instantly, the video is playing, but the audio is not played until 6 seconds after. For audio assets that need to play <em>right away</em>, particularly if they are synced to visual elements, this would not be an optimal setting.</p><p>However, for audio not triggered until later in the scene, <em>this will reduce scene load times without resulting in missing audio data</em>. We have to use our best judgment here and give those later audio elements enough time to load completely. Otherwise, we might still experience a delay.</p><p>If we had selected <strong>Load in Background only</strong>, which I won’t demo here to save time, there will be a delay regardless of when we play our audio, as it won’t begin the loading process until we’ve called it. Smaller files might not have a noticeable delay but, in the end, it’s up to us to decide if that delay is acceptable for that particular asset.</p><h4>Warning: Extreme Testing</h4><p>Let’s do a more extreme test. I will <strong>turn off Preload Audio Data and Load in Background</strong>, turn off Play on Awake and instead trigger the audio with a button, and see what happens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*sthqJWUvgiLsa5xpk7L1IQ.gif" /><figcaption>Wrong audio settings can be seriously bad news.</figcaption></figure><p>…and the main thread stalled. It stalled so badly that Windows reported the build as unresponsive for a fraction of a second!</p><blockquote>Do note that once the audio has been loaded, it can be played again with no delay, as it’s already primed for playback with the correct Load Type.</blockquote><p>This example may be a little (or a lot) too exaggerated. There’s no realistic situation in which you would have to wait almost 8 seconds for audio files to load. Nonetheless, it’s good to keep in mind that this setting could potentially freeze your game and no freeze is acceptable for your players, no matter how short!</p><h3>Final Words</h3><p>Let’s summarize:</p><ul><li>If our Load Type settings determine <em>how</em> our audio assets will be loaded, then the Preload Audio Data and Load in Background settings determine <em>when </em>they will be loaded.</li><li><strong>Selecting only Preload Audio Data</strong> means the scene will not be playable until the audio data is completely loaded. This is <em>important for audio that needs to be ready as soon as the scene is</em>, such as footsteps, UI, and any audio that might be synced to visual elements that occur early in the scene.</li><li><strong>Selecting both Preload Audio Data and Load in Background</strong> means the audio data will begin loading during the scene loading process, but the scene’s playability won’t be delayed by it. With this setting, the scene will be ready faster because <em>it isn’t waiting unnecessarily on audio assets that aren’t needed right away</em>. This is great for audio assets linked to enemies or items that appear at a further point in the scene, victory and loss sound effects that come only after combat situations, or audio synced to visual elements triggered at a later point in the gameplay.</li><li><strong>When only Load in Background is selected</strong>, the audio file will load once it is called and play as soon as it is ready. Depending on the file size, this could cause a noticeable delay between the play call and the actual sound. The file will remain loaded so this problem will only be there for the first call. <em>Sounds that have no relationship to visual elements can benefit the most from the setting</em>, the best example being random ambient sounds. Since they are just there to add a dynamic ambience to the scene and are not connected to any specific gameplay elements, it doesn’t matter if loading them results in delay.</li><li><strong>Deselecting both Preload Audio Data and Load in Background</strong> leaves us with the final option. When audio assets with this setting are called, they will use the main thread to load themselves. If they are too big, they could stall the main thread, resulting in a frame hitch, something we definitely don’t want. <em>We’d recommend this option only for very small files</em> and only in the case that you’re certain they will be triggered one at a time and not all at once.</li></ul><p>That’s it! We hope this video has helped you to understand the relationship between the Preload Audio Data and Load in Background options in Unity’s Import Settings and why this information is important for <strong>your game</strong>.</p><p>If you want to learn more about how audio functions in Unity, be sure to check out our other tutorials <em>(linked below)</em>. If you have a question, leave it in the comments or contact us directly through our website:</p><p><a href="https://doubleshot-audio.com/">Double Shot Audio</a></p><h3>Other Tutorials:</h3><ul><li><a href="https://medium.com/double-shot-audio/preload-audio-data-how-unity-decides-which-audio-assets-to-load-to-a-scene-a440a654e7e2">Preload Audio Data &amp; How Unity Decides Which Audio Assets to Load to a Scene</a></li><li><a href="https://medium.com/double-shot-audio/choosing-the-right-load-type-in-unitys-audio-import-settings-1880a61134c7">Choosing the Right Load Type in Unity’s Audio Import Settings</a></li><li><a href="https://medium.com/double-shot-audio/understanding-audio-compression-settings-in-unity-e879a821023f">Understanding Audio Compression Settings in Unity</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33d3cc04c47e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Preload Audio Data & How Unity Decides Which Audio Assets to Load to a Scene]]></title>
            <link>https://medium.com/@made-indrayana/preload-audio-data-how-unity-decides-which-audio-assets-to-load-to-a-scene-a440a654e7e2?source=rss-363fb115145d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a440a654e7e2</guid>
            <category><![CDATA[audio-programming]]></category>
            <category><![CDATA[sound-design]]></category>
            <category><![CDATA[unity-game-development]]></category>
            <category><![CDATA[game-audio]]></category>
            <category><![CDATA[unity3d]]></category>
            <dc:creator><![CDATA[Made Indrayana]]></dc:creator>
            <pubDate>Thu, 28 May 2020 11:52:28 GMT</pubDate>
            <atom:updated>2020-05-28T11:52:28.462Z</atom:updated>
            <content:encoded><![CDATA[<p>Today we’ll be talking about the Preload Audio Data option in Unity’s Audio Import Settings and why understanding this small but critical checkbox is important for <strong>your game</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wL7BP-A3YGzaEgGhk4hlWg.jpeg" /><figcaption>So many options… How does Unity choose which audio is loaded to a scene?</figcaption></figure><p><em>Editor’s Note: Compression Formats, Load Type and the Preload Audio Data/Load in Background settings go hand in hand. We recommend reading our blog posts on all three in the following order for a complete overview:</em></p><p>Blog 1: <a href="https://bit.ly/2VLwmld">Compression Formats</a></p><p>Blog 2: <a href="https://bit.ly/2W5pQXA">Load Types</a></p><p>Blog 3: Preload Audio (this post)</p><p>Blog 4: Load in Background <em>(coming soon)</em></p><p>This blog post has been made as a supplement to our video tutorial on this same topic.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DPLaTdxrbUcR8IcWkBEvOc9yJ-vD54AxmEb&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DPaP5soZ3WWI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FPaP5soZ3WWI%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/acee4443eeed2d64600887c354ceaf4f/href">https://medium.com/media/acee4443eeed2d64600887c354ceaf4f/href</a></iframe><h3>Introduction</h3><p>After figuring out how Unity compresses your audio with the different compression formats, and primes your audio for playing with the different Load Type settings, the next question to answer is: What does the Preload Audio Data option do?</p><p>The Unity Documentation provides important information on this subject, but it doesn’t explain exactly when and how audio files are selected to be loaded in an active scene.</p><h3>Preload Audio Data</h3><p>Here’s Unity’s definition of Preload Audio Data from their manual:</p><blockquote>If enabled, the audio clip will be pre-loaded when the scene is loaded. This is on by default to reflect standard Unity behavior where all AudioClips have finished loading when the scene starts playing.</blockquote><p>This information is pretty clear already. If you choose this option, you want the audio priming process with the respective Load Types to take place <em>before the scene is activated and becomes playable</em>.</p><p>This will result in mission-critical audio files being ready to be played at all times at the expense of making the scene load time a little bit longer.</p><p>So far, so good. But there is one question left unanswered:</p><p><strong><em>How does Unity decide which Audio is going to be loaded in which Scene?</em></strong></p><h4>References</h4><p>Let’s imagine this situation: you’re developing a large game that has 15 hours of playtime and around 30 scenes. You have something like 1000 SFX and 2000 dialogue files. You would <strong>not</strong> want every single audio asset marked with Preload Audio Data to be loaded in every scene, would you?</p><p>Unfortunately, the documentation doesn’t address this in detail, making the process of deciding whether or not to Preload your audio assets very difficult and full of uncertainty.</p><p>Luckily, Unity is a sophisticated engine. After many tests, we concluded that Unity will scan everything in our scene and <strong>load all audio files flagged with Preload Audio Data that are referenced in the scene in any way</strong>.</p><p>Let’s take a step back here because now we have another question to answer:</p><p><strong><em>What is a reference?</em></strong></p><p>Let’s open up Unity and find out.</p><h4>Testing Testing</h4><p>We’ve imported 10 sound effects, 10 dialogue, and 2 music files into a Unity project. They’re all marked with Preload Audio Data to simulate a larger game. There are also two different scenes to simulate loading and unloading audio in a normal scene transition.</p><p>Let’s start with the first scene. We have a GameObject here with an AudioSource that has an AudioClip.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/1*WiVFXwJGf_fV5e-x1jfJ_A.png" /><figcaption>We hope this looks familiar.</figcaption></figure><p>This is already a so-called reference and this audio file will be loaded when the scene is loaded. I turned off Play on Awake for this to make sure that the audio is not played. Let’s build this and confirm with the profiler.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*M8CVTm7zTNtckEDI-ThsrA.png" /><figcaption>Our AudioClip is loaded and ready for action.</figcaption></figure><p>Perfect. Even though the AudioClip is not played at all, it is loaded because it has been referenced.</p><p><em>Note that this music file, which has “Streaming” selected as its Load Type, is only 311 bytes in the memory, unlike the 200-ish kilobytes from the last tutorial. That will change if we actually play the sound file.</em></p><p>Let’s now add two scripts we’ve prepared for another GameObject.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zq0X-Glis4WT0HER-wbXwQ.png" /></figure><p>These two scripts do nothing but define a public AudioClip variable and a public AudioClip array. Let’s add an AudioClip to that and profile this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*MfKFT9EE1bXowP35xoXw_w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qmTjrLAjIJeFGCaDczecVQ.png" /></figure><p>Voilá. We have the second audio clip loaded.</p><p>For the sake of this demonstration, I will add another two AudioClips to the array and check the profiler once again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*9ab16bxDbU8KmxaxDbZDaw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XwCsaV_EqTdyNMSbRNFr7w.png" /></figure><p>As you might have guessed, without Preload Audio Data selected, <em>Unity will not load the AudioClip until it is called</em>, even though it is referenced in the scene. We’ll be going more in-depth on this in our next tutorial.</p><p>So, a reference is as simple as that. As long as you have a reference of any kind to an AudioClip, be it directly in the AudioSource, as a variable in a script, or even in a ScriptableObject, it will be loaded when the scene is loaded if you have checked Preload Audio Data.</p><h4>Scene Transitions</h4><p>Now: what happens if we change to another scene? Will the audio data we loaded in this scene be automatically unloaded?</p><p>Let’s go to the second scene. We’ll keep one AudioClip constant across both scenes but change the rest. Now we can build and profile this once again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*XwCsaV_EqTdyNMSbRNFr7w.png" /></figure><p>And then we’ll transition to the next scene.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zAk9u8Dz_cvYbZiglOkI3w.png" /></figure><p>We see here that all but one of our AudioClips from the first scene are already unloaded from the memory, leaving only the one that is used again in the second scene.</p><p>The unloading process took place as the scene was changed; this is a normal routine that Unity does in the background called <strong>GarbageCollection</strong>.</p><h3>Final Words</h3><p>Let’s summarize what we’ve learned:</p><ul><li>Selecting <strong>Preload Audio Data</strong> means <strong>the scene will not start until all sounds with this setting are loaded into memory</strong><em>.</em> This is <em>most important for audio content that is needed right away in the scene</em>, such as footsteps, UI, or anything synced to visual content that plays immediately upon the scene’s activation.</li><li>Unity determines which files to load in a scene by searching for <strong>references</strong>. If an audio file is referenced unnecessarily, for example, an AudioClip in an AudioSource that you ended up not using but didn’t delete from the scene, it will be loaded as well, <em>even if the entire GameObject is deactivated</em>. In that respect, it’s important to keep your scenes clear of unused references.</li></ul><p>That’s it! We hope this tutorial has helped you to understand the Preload Audio Data option in Unity’s Import Settings and why this information is important for <strong>your game</strong>.</p><p>If you want to learn more about how audio functions in Unity, be sure to check out our other tutorials <em>(linked below)</em>. If you have a question, leave it in the comments or contact us directly through our website:</p><p><a href="https://doubleshot-audio.com/">Double Shot Audio</a></p><h4>Other Tutorials:</h4><ul><li><a href="https://medium.com/double-shot-audio/choosing-the-right-load-type-in-unitys-audio-import-settings-1880a61134c7">Choosing the Right Load Type in Unity’s Audio Import Settings</a></li><li><a href="https://medium.com/double-shot-audio/understanding-audio-compression-settings-in-unity-e879a821023f">Understanding Audio Compression Settings in Unity</a></li><li><a href="https://medium.com/double-shot-audio/why-the-difference-between-mono-and-stereo-audio-files-is-important-for-your-game-2fbf92ddb7b3">Why the Difference between Mono and Stereo Audio Files is Important for Your Game</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a440a654e7e2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Choosing the Right Load Type in Unity’s Audio Import Settings]]></title>
            <link>https://medium.com/@made-indrayana/choosing-the-right-load-type-in-unitys-audio-import-settings-1880a61134c7?source=rss-363fb115145d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1880a61134c7</guid>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[unity3d]]></category>
            <category><![CDATA[game-design]]></category>
            <category><![CDATA[game-audio]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Made Indrayana]]></dc:creator>
            <pubDate>Wed, 06 May 2020 09:11:34 GMT</pubDate>
            <atom:updated>2020-05-06T09:53:48.478Z</atom:updated>
            <content:encoded><![CDATA[<p>Today we’ll be talking about the different Load Types in Unity’s Audio Import Settings and why selecting the right Load Type is important for <strong>your game</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KF8XGKS6KSz8ucjxi79paw.jpeg" /><figcaption>Correct Load Type settings are critical for your game’s performance!</figcaption></figure><p><em>Editor’s Note: Compression Formats, Load Type and the Preload Audio Data/Load in Background settings go hand in hand. We recommend reading our blog posts on all three in the following order for a complete overview:</em></p><p>Blog 1: <a href="https://bit.ly/2VLwmld">Compression Formats</a></p><p>Blog 2: <a href="https://bit.ly/2W5pQXA">Load Types</a> (this post)</p><p>Blog 3: Preload Audio / Load in Background <em>(coming soon)</em></p><p>This blog post has been made as a supplement to our video tutorial on this same topic.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fvideoseries%3Flist%3DPLaTdxrbUcR8IcWkBEvOc9yJ-vD54AxmEb&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DT6Uag8VlMck&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FT6Uag8VlMck%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/fbec5e1d5866c6f1015691d6e5e11652/href">https://medium.com/media/fbec5e1d5866c6f1015691d6e5e11652/href</a></iframe><h3>Introduction</h3><p>The topic Load Type is somewhat vaguely described in the <a href="https://docs.unity3d.com/Manual/class-AudioClip.html">Unity Documentation</a> and many of the articles and blog posts we’ve read about it left us with questions.</p><p>The reason for this is that the term<em> “Load” </em>is rarely explained properly.</p><p>We had to do <strong>a lot</strong> of experimentation to find out exactly when and how audio clips are loaded and unloaded to the scene.</p><p>So, to really understand the Load Type settings, as well as its role in the Audio Import Settings, we need to know <strong>exactly what loading and unloading audio means in Unity</strong>.</p><h3>Load Types</h3><p>“Loading” an audio file simply means the audio data has been primed for playback in Unity. <em>How</em> it will be primed is determined by the corresponding load type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/369/1*r5vH-dStUDYf-b4Nt0WCzA.jpeg" /><figcaption>The three different load types in Unity</figcaption></figure><p>When the AudioClip has been primed, Unity will be ready to playback that audio data and has step by step instructions to follow for when the scene requests that AudioClip be played.</p><p>There are only two priming methods that Unity offers:</p><ul><li>storing the audio data in memory</li><li>or… not</li></ul><p>We’ll elaborate later on the “not” but first, let’s take a look at storing audio data in memory.</p><h4>Storing Audio Data in Memory</h4><p>Storing the audio data in the memory (or RAM, which stands for <a href="https://en.wikipedia.org/wiki/Random-access_memory">Random Access Memory</a>) is a very efficient way to prime audio data because RAM has a higher read rate compared to the storage medium, i.e. your hard disk or SSD.</p><p>Using this method, you can optimize the time it takes to read the audio data by bypassing the storage medium and reading directly from the very fast memory.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F1rSQ2dv8uJEEvd9AlR%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F1rSQ2dv8uJEEvd9AlR%2Fgiphy.gif&amp;image=https%3A%2F%2Fi.giphy.com%2Fmedia%2F1rSQ2dv8uJEEvd9AlR%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/89eceb9652418ef9c16d3abf9decc729/href">https://medium.com/media/89eceb9652418ef9c16d3abf9decc729/href</a></iframe><p>Unity offers two ways of priming the audio data in the computer’s memory:</p><ul><li>Decompress on Load</li><li>Compressed In Memory</li></ul><p><strong>Decompress on Load</strong> means that Unity will decompress and decode the audio data completely from its codec to PCM format before loading it into the memory.</p><p><strong>Compressed in Memory</strong> means that the audio data will be loaded into the memory still compressed in the format you’ve defined, whether it’s ADPCM, Vorbis, MP3, or something else. Decompression and decoding happen only when the audio asset is played.</p><p><strong>If an AudioClip is already formatted as PCM</strong>, both Decompress on Load and Compressed In Memory will do the <em>exact same thing</em>: which is just loading the audio data to the memory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*1MbJN27eD1E9I8yCzUnKDQ.jpeg" /><figcaption>Where and when audio is decompressed and decoded depends on the Load Type</figcaption></figure><h4>Why is PCM Always the Final Format?</h4><p>At this point, you might be wondering why all of the audio data we’ve stored so carefully as Vorbis, ADPCM, or other compressed formats need to be decompressed and decoded to the PCM format.</p><p>This may seem like a contradiction, but if you’ve read through <a href="https://bit.ly/2VLwmld">our last post</a> you know that PCM’s advantage is the very low to almost non-existent CPU usage needed for playback. <em>Why is this exactly?</em></p><p>Usually, an application that plays encoded files (be it audio or video) will need to decode that file to a format that the target device can output on a standard port.</p><p><strong>Most audio devices are waiting for PCM data</strong>. The decoder will most likely be integrated into the software or, in some rare cases, you will have actual hardware or a chip taking over the decoding process to relieve your CPU.</p><p>That means: to be able to create an audio signal that a playback device actually understands,<em> it needs to be converted to PCM</em>.</p><h3>Decompress on Load</h3><p>If we return to the topic of <strong>Decompress on Load</strong> with this information, it suddenly makes much more sense. Audio data is primed in PCM format in the memory, so it is actually in a very ready-to-play state. When that audio is needed, Unity simply sends the audio data directly to the audio device and voilá: you have sound.</p><p>This is very <em>advantageous for audio data that is used very often</em>, as it is constantly ready to be played. The major drawback to this is that <em>audio data will require much more space in the memory</em> because it will be stored there in its full, uncompressed size.</p><h4>Real-World Example</h4><p>Take a look at this audio file from our <a href="https://bit.ly/2VIFc36">Royalty Free Music Library</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*Yd0LkS8s3LUz9LqbuTM87A.jpeg" /><figcaption>Original imported size as PCM is 26.8 MB</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*aYgzv8_lh__xPw2A7F-D4Q.jpeg" /><figcaption>Imported size formatted as Vorbis with 70% quality is 3.4 MB</figcaption></figure><p>Its original imported size with PCM is 26.8 MB but then, after compressing it with Vorbis, it is reduced to 3.4 MB. Very small and effective for storage. However, as soon as it is decompressed and stored in the memory, <strong>it will become as large as the original uncompressed data.</strong></p><p>Let’s go to the profiler to check. For this, I will <em>always profile from a build </em>instead of the editor, as the editor often provides inaccurate readings in terms of memory usage.</p><p>If we take a look at the memory profiler and examine one of the current frames with Detailed mode selected…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I4n33XAPo-_hJN-DqzjPvQ.jpeg" /><figcaption>Always profile with the build when possible. Profiling in the editor can sometimes lead to inaccurate readings.</figcaption></figure><p>…it’s exactly as predicted.</p><p>This is why simply leaving the default Audio Import Settings from Unity <em>(Decompress on Load with Vorbis compression) </em>selected is very counterproductive for memory usage. Applying this setting for all audio files in any normal-sized project would <strong>immediately fill, if not completely overload, the RAM</strong>.</p><h4>Summary</h4><p>The main advantage of <strong>Decompress on Load</strong> is that the respective audio data being called is ready to play and <em>requires very minimal CPU to do so</em>. This setting is <strong>optimal for small audio files that are played back very often</strong> (for example footsteps and UI sounds) because they don’t take up too much space in the memory and won’t require additional CPU when being played back all the time.</p><h3>Compressed in Memory</h3><p>Let’s now take a look at what happens in the profiler when we set the same audio data to <strong>Compressed In Memory</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4I9YUajP1Mm7y1Hus5hOZQ.jpeg" /><figcaption>Less space required in memory, but we needed more CPU for playback.</figcaption></figure><p>As expected, the audio data is loaded into the memory in its compressed size. Unity has a small overhead on storing compressed audio files in the memory, making it always a tiny bit bigger than its compressed size in the storage medium.</p><p>As soon as we play the audio data, <em>it will first be decompressed and decoded</em>, a process that <strong>requires CPU resources</strong> as the audio data is playing.</p><h4>Summary</h4><p>Compressed In Memory gives us the <em>advantage of the lightning-fast read access from RAM</em>, but will require CPU power every time the sound is played back. Contrary to some information we’ve found online, <strong>once played back the audio will stay compressed and will need CPU to decompress and decode every time the audio is called</strong>.</p><p>This compromise between RAM and CPU makes Compressed In Memory a <strong>good setting for audio files that are played back somewhat often</strong>, but not often enough to need them constantly ready in a decompressed and decoded state, such as object interaction sounds.</p><h3>Streaming</h3><p>We’ll now discuss the last Load Type, which is <strong>Streaming</strong>.</p><p>Do you still remember what we said in the beginning about the two ways Unity primes audio assets, storing them in memory or… <em>not</em>?</p><p>This is the “not” situation. Choosing Streaming as your Load Type in Unity is actually purposefully saying that you don’t want to prime your audio data. This means the <strong>audio will stay in the storage medium</strong> and will be read, decompressed, and decoded on the fly when needed, hence the word <em>streamed</em>.</p><p>Let’s take a look at the profiler once again.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ply3mO9IezSMV4VZML4Pqg.jpeg" /><figcaption>Almost non-existant memory requirements, but CPU is being constantly drained.</figcaption></figure><p>We see here only very minimal memory usage but very high CPU usage as the audio data is playing. For this reason, the general recommendation is to <strong>not have more than one or two audio files streaming at the same time</strong>.</p><h4>Summary</h4><p>Streaming uses the <em>least amount of memory</em> but the <em>highest amount of CPU</em>. Commonly, this setting is <strong>used for music</strong> because music files normally are the biggest audio files in the scene and you don’t want them taking up space in the memory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O9qQW3RXwKdyrJIHSBkp_g.jpeg" /><figcaption>The original audio asset was 26.8 MB and was compressed with Vorbis for a final size of 3.4 MB</figcaption></figure><h3>Final Words</h3><p>Let’s summarize what we’ve learned so far:</p><ul><li><strong>Decompress on Load</strong> will decompress and decode the audio data into the memory to its original size, making it ready to play on-demand with the <em>least amount of CPU usage</em>. The trade-off to this is that the audio data will take up the <em>maximum amount of space in the memory</em>, and that’s why it’s only <strong>suitable for small audio files that are played very often and need to be ready in a very short time</strong>, like footsteps, UI sounds, gunshots and other weapon sounds, etc…</li><li><strong>Compressed in Memory</strong> will store the audio data in its compressed state in the memory, but will require CPU to decompress and decode when it’s played. This has the advantage of no reading time from the storage medium and <em>small memory usage with the tradeoff of using a little bit more CPU</em> to decompress and decode every time it is played. This setting is <strong>recommended for sounds that are not played very often</strong>, like object interaction sounds, random ambience sounds, and many others.</li><li><strong>Streaming</strong> will not prime the audio and will decode and decompress while the audio data is being read from the storage medium on the fly. This has the <em>least memory usage, but the highest CPU usage</em>. It will be quite slow because the CPU has to read first from the storage medium, which is slower than memory. Because of this, this option is only recommended to be used on one or two audio files per scene. Most often this setting will be <strong>used for music or ambience files</strong>, as these assets are large and you don’t want them to occupy precious memory resources that could be used for something else.</li></ul><p>Alright. That’s it! We hope this blog has helped you to understand the difference between Load Types in Unity and why this information is important for <strong>your game</strong>.</p><p>If you want to learn more about how audio functions in Unity, be sure to check out our other tutorials <em>(linked below)</em>. If you have a question, leave it in the comments or contact us directly through our website:</p><p><a href="https://bit.ly/2S8Cumk">Double Shot Audio</a></p><h4>Other Tutorials:</h4><ul><li><a href="https://medium.com/double-shot-audio/why-the-difference-between-mono-and-stereo-audio-files-is-important-for-your-game-2fbf92ddb7b3">Why the Difference between Mono and Stereo Audio Files is Important for Your Game</a></li><li><a href="https://medium.com/double-shot-audio/understanding-audio-compression-settings-in-unity-e879a821023f">Understanding Audio Compression Settings in Unity</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1880a61134c7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding Audio Compression Settings in Unity]]></title>
            <link>https://medium.com/@made-indrayana/understanding-audio-compression-settings-in-unity-e879a821023f?source=rss-363fb115145d------2</link>
            <guid isPermaLink="false">https://medium.com/p/e879a821023f</guid>
            <category><![CDATA[audio]]></category>
            <category><![CDATA[compression]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[unity]]></category>
            <category><![CDATA[game-audio]]></category>
            <dc:creator><![CDATA[Made Indrayana]]></dc:creator>
            <pubDate>Wed, 15 Apr 2020 14:50:37 GMT</pubDate>
            <atom:updated>2020-05-06T09:51:41.956Z</atom:updated>
            <content:encoded><![CDATA[<p>Today we’ll be talking about audio compression formats in Unity’s Audio Import Settings and why setting the right compression type is important for <strong>your game</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0l2uUEd_E609nnkLZcBWcg.jpeg" /><figcaption>Compression formats? Just squash it to death and be done with it. It worked for Metallica, right?</figcaption></figure><p><em>Editor’s Note: Compression Formats, Load Type and the Preload Audio Data/Load in Background settings go hand in hand. We recommend reading our blog posts on all three in the following order for a complete overview:</em></p><p>Blog 1: <a href="https://bit.ly/2VLwmld">Compression Formats</a> (this post)</p><p>Blog 2: <a href="https://bit.ly/2W5pQXA">Load Types</a></p><p>Blog 3: Preload Audio / Load in Background <em>(coming soon)</em></p><p>This blog post has been made as a supplement to our video tutorial on this same topic.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F4dr_1Yie4Os%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D4dr_1Yie4Os&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F4dr_1Yie4Os%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/8bd9fe83ed3311d19dd75b82d17558c5/href">https://medium.com/media/8bd9fe83ed3311d19dd75b82d17558c5/href</a></iframe><h3>Introduction</h3><p>I don’t think we need to go over the general concept of file compression in detail. <em>We compress files to make them smaller and easier to store.</em> In our case, we want to store audio data in our game in a way that makes it as small as possible without degrading the audio quality more than necessary or leading to performance issues.</p><p>There are several different compression formats available in Unity. If you develop for computers, you will likely recognize them: The standard options are <strong>PCM</strong>, <strong>ADPCM</strong>, and <strong>Vorbis</strong>. Some platforms have other options available, such as <strong>MP3 for mobile</strong>.</p><p>Let’s take a look at the first option, <strong>PCM</strong>.</p><h3>Lossless Formats (PCM)</h3><p>PCM is short from <strong>Pulse Code Modulation</strong> and it is a <strong>lossless, uncompressed codec and format. </strong>Theoretically, this doesn’t really qualify as “compression”, as this is a standard for uncompressed audio formats in the professional audio world.</p><p>Speaking only of the quality, <strong>PCM is the best format for audio</strong> as it retains everything from the original audio content. It also requires almost no CPU processing to play in Unity because it requires no decompressing.</p><p>As good as it sounds,<em> its strength is also its Achilles’ heel.</em></p><p>Because no compression is taking place, the audio retains its original size. This big size is a big disadvantage, as having many uncompressed audio files can quickly lead to a large increase in the size of your build. The devs (and players) are not going to be very happy about this, especially if you’re developing for mobile.</p><p>One side note on PCM is that Unity seems to be doing its own kind of lossless compression on some audio files. For example, with this file I have PCM selected but it is nonetheless compressed to 66%.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*L9rvg5gqeeM3KvV_MBCppA.jpeg" /></figure><p>With this other example, however, it stays at 100%.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/385/1*mq3rKjKYGqeYy0Djyp9ZYw.jpeg" /></figure><p>We couldn’t find any reliable documentation on how or why Unity is doing this, but it seems that the audio stays lossless in spite of what appears to be compression.</p><p>Before moving on to the various compressed formats, let’s take a closer look at a term I mentioned at the beginning of this blog: <strong>codec.</strong></p><h4>What is a Codec?</h4><p>The word “codec” is a <a href="https://www.lexico.com/en/definition/portmanteau">portmanteau</a> for <em>coder-decoder.</em></p><p>I’ll cite <a href="https://en.wikipedia.org/wiki/Audio_codec">Wikipedia </a>here:</p><blockquote><em>“In software, an audio codec is a computer program implementing an algorithm that compresses and decompresses digital audio data according to a given audio file or streaming media audio coding format. The objective of the algorithm is to represent the high-fidelity audio signal with minimum number of bits while retaining quality. This can effectively reduce the storage space and the bandwidth required for transmission of the stored audio file.”</em></blockquote><p>In the audio world, <strong>PCM</strong>, <strong>ADPCM</strong>, <strong>Vorbis</strong>, <strong>MP3</strong>, <strong>M4A</strong>, and many others, are all examples of audio codecs.</p><p>Audio codecs have different methods of compressing audio data. PCM happens to be the one that does not “compress” in the normal sense, but rather in terms of storing data digitally.</p><p>All other formats such as MP3 and Vorbis compress the audio data with their own algorithms, resulting in much smaller file size. <em>However</em>, this means that <strong>they do not retain the full quality of the original PCM audio</strong>, like file compression in your operating system would. Once compressed, you cannot restore the lost details through the decoding/decompressing process. This puts them into a new category called <strong>lossy compression.</strong></p><h3>Lossy Formats (ADPCM, Vorbis, MP3)</h3><p>In Unity, depending on what platform you are developing, you can choose from a wide variety of lossy compression formats.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-fCScF5ZN7nntB2u9kCcHg.jpeg" /><figcaption>Different lossy compression formats are available depending on what platform you’re developing for.</figcaption></figure><p>Let’s take a look at <strong>ADPCM</strong> first.</p><h4>ADPCM Compression</h4><p>ADPCM is short for <strong>Adaptive Differential Pulse Code Modulation</strong>. From the name alone you might get the impression that this format is also one of the lossless codecs, like PCM. In reality, it is not.</p><p>ADPCM’s algorithm offers a <strong>fixed ratio of compression</strong> in Unity, which results in a file <strong>around 3.5 times smaller</strong> than the original PCM audio.</p><p>We’ll use this piece of music from our <a href="https://soundcloud.com/doubleshot-audio/sets/royalty-free-music-free-stock">personal royalty-free library</a> to demonstrate. As PCM, it is already compressed to 66,66% of its original size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/371/1*rmKqrQZczaEGcm88mn5UTw.jpeg" /></figure><p>With ADPCM, it drops to 18,75%, which is roughly 3.5 times smaller.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*TFDmhuD2XwS3FJ5mSd-n-w.jpeg" /></figure><p><strong>Advantages &amp; Disadvantages:</strong></p><p>What is the advantage of ADPDM compression? Like PCM, the cost of decompressing or decoding this codec is very light, just a tad more in comparison to PCM in exchange for a greatly reduced file size.</p><p>The disadvantage of this format <em>is the compression method itself</em>. The way ADPCM compresses audio data can occasionally cause distortion, or “extra noises”, that weren’t there in the original file.</p><p>For the nerds, this is called <strong>quantization distortion</strong>.</p><p>How much quantization distortion, or <em>extra noise</em>, is introduced depends on the frequency content of the original audio file. Let’s take a listen to this example:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F798274414%26show_artwork%3Dtrue%26in%3Ddoubleshot-audio%252Fsets%252Funity-audio-compression-formats-adpcm-examples%252Fs-n7y5VEcOA3A%26secret_token%3Ds-GOmPdrzh7Fx&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fadpcm-example-1-sfx-pre%2Fs-GOmPdrzh7Fx%3Fin%3Ddoubleshot-audio%2Fsets%2Funity-audio-compression-formats-adpcm-examples%2Fs-n7y5VEcOA3A&amp;image=https%3A%2F%2Fi1.sndcdn.com%2Fartworks-zKz5dbdfHHJQ4pk3-M9yXlg-t500x500.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/285fd738e1fe4128fabe9ce92413b123/href">https://medium.com/media/285fd738e1fe4128fabe9ce92413b123/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F798274411%26show_artwork%3Dtrue%26in%3Ddoubleshot-audio%252Fsets%252Funity-audio-compression-formats-adpcm-examples%252Fs-n7y5VEcOA3A%26secret_token%3Ds-PpZ33SDIBNg&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fadpcm-example-1-sfx-post%2Fs-PpZ33SDIBNg%3Fin%3Ddoubleshot-audio%2Fsets%2Funity-audio-compression-formats-adpcm-examples%2Fs-n7y5VEcOA3A&amp;image=https%3A%2F%2Fi1.sndcdn.com%2Fartworks-zKz5dbdfHHJQ4pk3-M9yXlg-t500x500.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/e24ef9bc31ca885eea6b55476669a3be/href">https://medium.com/media/e24ef9bc31ca885eea6b55476669a3be/href</a></iframe><p>When we convert this sound effect to ADPCM, we suddenly hear something that wasn’t there before.</p><p>Let’s have a listen to a different example. This time, we’ll use a dialogue example from a game we worked on, <a href="https://store.steampowered.com/app/765870/Leisure_Suit_Larry__Wet_Dreams_Dont_Dry/">Leisure Suit Larry</a>:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F798274396%26show_artwork%3Dtrue%26in%3Ddoubleshot-audio%252Fsets%252Funity-audio-compression-formats-adpcm-examples%252Fs-n7y5VEcOA3A%26secret_token%3Ds-KCXZwOztCbO&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fadpcm-example-2-dialogue-pre%2Fs-KCXZwOztCbO%3Fin%3Ddoubleshot-audio%2Fsets%2Funity-audio-compression-formats-adpcm-examples%2Fs-n7y5VEcOA3A&amp;image=https%3A%2F%2Fi1.sndcdn.com%2Fartworks-zKz5dbdfHHJQ4pk3-M9yXlg-t500x500.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/15ed1aa9061c5f9cf00ea19566dcbb3d/href">https://medium.com/media/15ed1aa9061c5f9cf00ea19566dcbb3d/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F798274375%26show_artwork%3Dtrue%26in%3Ddoubleshot-audio%252Fsets%252Funity-audio-compression-formats-adpcm-examples%252Fs-n7y5VEcOA3A%26secret_token%3Ds-dKH1SDYpACq&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fadpcm-example-2-dialogue-post%2Fs-dKH1SDYpACq%3Fin%3Ddoubleshot-audio%2Fsets%2Funity-audio-compression-formats-adpcm-examples%2Fs-n7y5VEcOA3A&amp;image=https%3A%2F%2Fi1.sndcdn.com%2Fartworks-zKz5dbdfHHJQ4pk3-M9yXlg-t500x500.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/526131e52bb017edf6ab523e5ec85597/href">https://medium.com/media/526131e52bb017edf6ab523e5ec85597/href</a></iframe><p>In this case, there is no audible difference between pre- and post-compression.</p><p>In our personal experience, this quantization distortion <em>occurs more often with files containing lots of high-frequency content</em>. Because of this potential for unwanted noise, our advice would be: <strong>always double-check the resulting audio file when you use ADPCM</strong>.</p><h4>Vorbis Compression</h4><p>According to the Vorbis website, Vorbis is a fully <a href="https://xiph.org/vorbis/">open, non-proprietary, patent-and-royalty-free, general-purpose audio format</a>. It is a very efficient audio codec that offers high-quality lossy compression.</p><p>When we select the Vorbis option in Unity, we also have a quality slider. This allows us to decide how much we want to reduce audio quality which will, of course, also reduce the size of the file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/369/1*8lykTd_IhiXIXaRcNjcMgA.jpeg" /></figure><p>Interestingly, if we go back to our <a href="https://soundcloud.com/doubleshot-audio/sets/royalty-free-music-free-stock">royalty-free music</a> file for a quick comparison, Vorbis with 100% quality is actually bigger than ADPCM.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*ZRXROQdgop5Dl1VF32ulMw.jpeg" /><figcaption>With ADPCM our file is just 18% the size of the original</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*hsr19JKz2oY4kgvtXOJGpA.jpeg" /><figcaption>With Vorbis 100 our file is nearly 21% the size of the original</figcaption></figure><p>Let’s see what happens to the file size when we reduce the quality to 70%:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/387/1*zPZ5mwe7p5Al-Ht6hyNAPQ.jpeg" /></figure><p>How about 40%?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*9zENvlOYKkxEMaXHT0JhUA.jpeg" /></figure><p>What happens if we bring it all the way down to 1%?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/388/1*DxyA5t-wT_WBMeL0Km3LfA.jpeg" /></figure><p><strong>Advantages &amp; Disadvantages</strong></p><p>Vorbis actually does an impressive job of reducing file size while retaining sonic quality in the audio data that it compresses. This is great for our game because it <strong>reduces file size without compromising too much quality</strong>.</p><p>The downside to this is that it <strong>requires significantly higher CPU resource</strong>s to decompress the audio for playback.</p><p>By default, Unity sets all audio assets to Vorbis. At first, this seems like an attractive setting because all the files are much smaller. <em>However</em>, this combination requires a lot of precious CPU resources for decompression <em>and</em> makes load times significantly higher.</p><h3>MP3</h3><p>MP3 is another efficient audio codec for lossy compression which most of us have probably heard of.</p><p>In many ways, MP3 is similar to Vorbis. It can compress audio to a very small size without much loss in quality.</p><p>One major difference between MP3 and Vorbis is that MP3 <strong>cannot loop seamlessly</strong>. If you want a sound in your game to loop, such as music or ambience, this is something you need to be aware of.</p><p>Generally, we recommend choosing Vorbis over MP3 when possible because Vorbis offers more efficient coding at the same bitrate, meaning you will get <em>more quality for the same file size</em>.</p><h3>Listening Examples</h3><p>OK, that was a lot of theory. Let’s do a little listening to compare the effects these different compression formats have on our sound effects.</p><p>Each of the following examples changes compression format when it loops. The formats change in the following order:</p><p>PCM, ADPCM, Vorbis 70%, Vorbis 40%, Vorbis 10%, and Vorbis 1%.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F798301891%26show_artwork%3Dtrue%26in%3Ddoubleshot-audio%252Fsets%252Funity-audio-compression-formats-all-formats-examples%252Fs-M6MkFGBJCOU%26secret_token%3Ds-YQgBy30kCjd&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fexample-1-music%2Fs-YQgBy30kCjd%3Fin%3Ddoubleshot-audio%2Fsets%2Funity-audio-compression-formats-all-formats-examples%2Fs-M6MkFGBJCOU&amp;image=https%3A%2F%2Fi1.sndcdn.com%2Fartworks-7Mz4k4st2vtliAnB-oz0YKw-t500x500.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/b50b8a00cc558c134371f4b804e058d9/href">https://medium.com/media/b50b8a00cc558c134371f4b804e058d9/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F798301870%26show_artwork%3Dtrue%26in%3Ddoubleshot-audio%252Fsets%252Funity-audio-compression-formats-all-formats-examples%252Fs-M6MkFGBJCOU%26secret_token%3Ds-HEhGfQCsDXI&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fexample-2-dialogue%2Fs-HEhGfQCsDXI%3Fin%3Ddoubleshot-audio%2Fsets%2Funity-audio-compression-formats-all-formats-examples%2Fs-M6MkFGBJCOU&amp;image=https%3A%2F%2Fi1.sndcdn.com%2Fartworks-7Mz4k4st2vtliAnB-oz0YKw-t500x500.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/99880d3bf7b7dd4f0d2a924e79621509/href">https://medium.com/media/99880d3bf7b7dd4f0d2a924e79621509/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F798301861%26show_artwork%3Dtrue%26in%3Ddoubleshot-audio%252Fsets%252Funity-audio-compression-formats-all-formats-examples%252Fs-M6MkFGBJCOU%26secret_token%3Ds-VlyCldzbshC&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fexample-3-sfx%2Fs-VlyCldzbshC%3Fin%3Ddoubleshot-audio%2Fsets%2Funity-audio-compression-formats-all-formats-examples%2Fs-M6MkFGBJCOU&amp;image=https%3A%2F%2Fi1.sndcdn.com%2Fartworks-7Mz4k4st2vtliAnB-oz0YKw-t500x500.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/9bb47a68a02c3b769252fea3ce70d66c/href">https://medium.com/media/9bb47a68a02c3b769252fea3ce70d66c/href</a></iframe><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fw.soundcloud.com%2Fplayer%2F%3Furl%3Dhttps%253A%252F%252Fapi.soundcloud.com%252Ftracks%252F798301840%26show_artwork%3Dtrue%26in%3Ddoubleshot-audio%252Fsets%252Funity-audio-compression-formats-all-formats-examples%252Fs-M6MkFGBJCOU%26secret_token%3Ds-JJ9c5ZB8S8F&amp;display_name=SoundCloud&amp;url=https%3A%2F%2Fsoundcloud.com%2Fdoubleshot-audio%2Fexample-4-sfx%2Fs-JJ9c5ZB8S8F%3Fin%3Ddoubleshot-audio%2Fsets%2Funity-audio-compression-formats-all-formats-examples%2Fs-M6MkFGBJCOU&amp;image=https%3A%2F%2Fi1.sndcdn.com%2Fartworks-7Mz4k4st2vtliAnB-oz0YKw-t500x500.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=soundcloud" width="800" height="166" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d921ce556996ec154af1a1817cfd008/href">https://medium.com/media/4d921ce556996ec154af1a1817cfd008/href</a></iframe><h3>Final Words</h3><p>Let’s summarize what we’ve learned about the Unity’s standard audio compression options:</p><ul><li><strong>PCM</strong> is lossless compression and, while light on the CPU, has a <em>much larger file size</em></li><li><strong>ADPCM</strong> has a fixed compression ratio of about 3.5 and, while a good compromise between PCM and Vorbis/MP3, <em>can sometimes cause unwanted noise</em> (quantization distortion) in audio files with lots of high-frequency content</li><li><strong>Vorbis</strong> is a very efficient audio codec that offers high-quality lossy compression<em> but requires more CPU resources for decompression</em></li><li><strong>MP3</strong> also offers high-quality lossy compression but <em>causes problems for audio assets that should loop</em></li></ul><p>Generally, as sound designers, we always recommend audio to stay uncompressed as a PCM file wherever possible but we also know that this is nearly impossible to do in game development because of space and performance requirements.</p><p>How do we choose which compression format to use for our audio assets? We’ll discuss some recommendations in the next tutorial because this decision is also dependent on Unity’s Load Type options as well as the Preload Audio Data and Load in Background settings.</p><p><em>Link to our “Load Type” and “Preload Audio Data/Load in Background” blog posts coming soon</em></p><p>That’s it! We hope this tutorial has helped you to understand the difference between audio compression formats in Unity’s Audio Import Settings and why setting the right compression type is important for <strong>your game</strong>.</p><p>If you want to learn more about how audio functions in Unity, be sure to check out our other tutorials <em>(linked below)</em>. If you have a question, leave it in the comments or contact us directly through our website:</p><p><a href="https://doubleshot-audio.com/">Double Shot Audio</a></p><h4>Other Tutorials:</h4><ul><li><a href="https://medium.com/double-shot-audio/why-the-difference-between-mono-and-stereo-audio-files-is-important-for-your-game-2fbf92ddb7b3">Why the Difference between Mono and Stereo Audio Files is Important for Your Game</a></li><li><a href="https://medium.com/double-shot-audio/choosing-the-right-load-type-in-unitys-audio-import-settings-1880a61134c7">Choosing the Right Load Type in Unity’s Audio Import Settings</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e879a821023f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why the Difference between Mono and Stereo Audio Files is Important for Your Game]]></title>
            <link>https://medium.com/@made-indrayana/why-the-difference-between-mono-and-stereo-audio-files-is-important-for-your-game-2fbf92ddb7b3?source=rss-363fb115145d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2fbf92ddb7b3</guid>
            <category><![CDATA[audio-production]]></category>
            <category><![CDATA[sfx]]></category>
            <category><![CDATA[game-audio]]></category>
            <category><![CDATA[performance-optimization]]></category>
            <category><![CDATA[unity]]></category>
            <dc:creator><![CDATA[Made Indrayana]]></dc:creator>
            <pubDate>Fri, 10 Apr 2020 08:08:04 GMT</pubDate>
            <atom:updated>2020-05-06T09:52:58.363Z</atom:updated>
            <content:encoded><![CDATA[<p>Today we’ll be covering Unity’s “Force To Mono” option in the Audio Import Settings, mono &amp; stereo audio files, and why the difference is important for <strong>your</strong> <strong>game</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y5itD8v6DIwXKP0p-vJt3A.jpeg" /><figcaption>Mono, stereo, what does this all mean and why is it important for my game?</figcaption></figure><p>This blog post accompanies the video tutorial we’ve created for this subject, which can be viewed here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FeBJzP6ecUFU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DeBJzP6ecUFU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FeBJzP6ecUFU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/70a2b1f7b99b345386b09ed5db230915/href">https://medium.com/media/70a2b1f7b99b345386b09ed5db230915/href</a></iframe><p><em>(Guideline for which audio assets should be mono/stereo at the end of this blog)</em></p><h3>Mono &amp; Stereo</h3><p>Before we get to Unity, let’s talk a little bit about the terms mono and stereo. We often hear these terms, but what exactly do they mean?</p><p>In the audio world, these terms are relevant in <strong>two different contexts</strong>:</p><ul><li>Format <em>and</em></li><li>Content</li></ul><h4>Format</h4><p>Mono and stereo as a format implicate the number of channels in an audio file or container.</p><ul><li><strong>Mono format</strong> refers to the fact that the file contains only one channel of audio</li><li><strong>Stereo format</strong> means that the audio file contains two channels, which will be mapped as left and right (L/R)</li></ul><p>When viewing audio files in an audio or video editing program, the difference between mono and stereo will look something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/843/1*7JyXyUH7MwBn8pDO6MFFvQ.jpeg" /><figcaption>Pictured above : Stereo (top) &amp; Mono (bottom)</figcaption></figure><h4>Content</h4><p>Mono and stereo <em>content</em> proves to be a little more complicated to explain. The standard playback system of the day is stereo, i.e. two speakers to play audio through. When a mono audio file is mapped to play through such a system, it will play the one channel of audio content equally through both speakers. With stereo, the two channels are separated and played discreetly through the left and right speakers.</p><p>However, when we have a stereo file where the two channels of audio are exact replicas of each other, it will be audibly no different than the same content in a mono container, because either way, the playback result is the same.</p><h4>Stereo Content</h4><p>So what then is “stereo” content exactly?</p><p>“Stereo”, in the everyday use of the word, means you have differences in either <em>level/loudness, time of arrival, </em>or<em> frequency content </em>in the two channels within your audio file, which gives you the effect, should you be sitting between two speakers or listening with headphones, that sounds come from the left, the right, or somewhere in between, often referred to as the <em>stereo field.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*nsf_ObjppjEed5H-bk-pqw.jpeg" /><figcaption><em>Skip to 5:00 in our video tutorial for in-depth listening examples</em></figcaption></figure><p>These differences, when used correctly, can give one the impression that there is a <em>panorama of sound</em> between the two speakers, or in the case of headphones, between your ears. With the addition of just one extra speaker, we have tricked the brain into perceiving a horizontal field of sound. Pretty cool, right?</p><h4>Phase Cancellation</h4><p>The last and most important point that we want to discuss before moving to Unity is <em>phase cancellation</em>.</p><p>Phase cancellation occurs in audio if you sum (i.e. combine) two or more channels of audio that have phase and/or time of arrival differences into a mono audio container.</p><p>The most classic and stark example of phase cancellation is that of a <em>pure</em> <em>sine wave</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*uBMfOj79RUjBsD7uXzbv7Q.jpeg" /><figcaption>A pure sine wave at 200Hz</figcaption></figure><p>If we duplicate this sine wave and combine it with the original, we just get a louder sine wave, 6dB louder to be exact. This will always happen when two exact sounds get combined together. Now, if we reverse the phase of the second sine wave (i.e. flip the sound wave upside down) the resulting audio is…. nothing!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/1*jDqPj4N35jUQKctq4KpYig.jpeg" /><figcaption>With the phase reversed (i.e. inverted) the two sound waves cancel each other out and no sound is played!</figcaption></figure><p>Why does this happen? Because the combination of the original sine wave and a perfectly inverted copy of itself cancels out the sound completely. Think of it like shooting a cannonball out of the rear end of a truck at the same speed as the truck is driving forwards. The speed of the cannonball and the truck cancel each other out, as shown here:</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fxp4WcjKGpZDJm%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fdirection-mythbusters-cannon-xp4WcjKGpZDJm&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2Fxp4WcjKGpZDJm%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/b3d365b6f0f8fa2b0d4c74816cf1169a/href">https://medium.com/media/b3d365b6f0f8fa2b0d4c74816cf1169a/href</a></iframe><p>This is the most extreme example of phase cancellation, but phase cancellation can also occur partially and unevenly across the frequency spectrum. That means, <em>when multiple channels of audio are combined, certain frequencies that will add together and become louder and others will cancel each other out</em>. Depending on the original frequency content, the summing of these channels could have a very subtle or a very drastic effect on the quality of the resulting mono audio file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*T9TM_jBAtFknGCz1w7l3sA.jpeg" /><figcaption>See 8:55 in our video tutorial to hear the potential negative effects of phase cancellation.</figcaption></figure><p>Let’s move on to the Audio Import Settings in Unity and talk about why this information about stereo and mono is important for <strong>your game</strong>.</p><h3>Force To Mono in Unity</h3><p>When you click on an audio asset and take a look at the inspector, you will see “<em>Force to Mono” </em>as the first option in Unity’s Audio Import Settings. By checking this box, we tell Unity to do what we just did in the previous section, which is to <strong>force the combination of two or more audio channels into a mono audio container</strong>, hence the word <em>“force”</em>.</p><p>There are <strong>two reasons</strong> to consider forcing sounds to mono in your game:</p><ul><li>Optimizing for Performance <em>and</em></li><li>Optimizing for Unity’s Audio System.</li></ul><h4>Force to Mono for Performance Optimization</h4><p>Forcing stereo/multichannel audio files to mono is a great way to save space in your build and optimize your game’s performance. Since a stereo file has two channels instead of one, it needs <em>twice the storage space and twice the computer resources for playback</em> during runtime.</p><p>You might be thinking, “but audio doesn’t normally take up that much space or performance compared to other aspects of the game”, and you would be right. However, if you are dealing with hundreds or even thousands of audio files, or making games for machines with low-performance specs (mobile, for example), the difference is often not so trivial.</p><h4>Force to Mono for Unity’s Audio System</h4><p>The other reason Force to Mono is so important has to do with Unity’s audio playback, specifically what Unity does when you switch a sound from 2D to 3D in the audio source component.</p><p>When you tell Unity to playback stereo sounds in 3D space, be it for 3D games or VR, both left and right channels will <em>originate at the same point in 3D space</em>,<strong> making them essentially a mono sound</strong>. That means that there is no benefit to having a stereo audio file if it will be used in a 3D setting and leaving it in stereo is just a <em>waste of space and resources</em>.</p><h4>When to use Force to Mono</h4><p>So how do you best move forward with this knowledge?</p><p>Our main recommendation would be: <strong>make sure your audio assets are delivered in the correct channel format so that you don’t have to worry about this!</strong></p><p>Experienced game sound designers will know which format certain sounds should be in and design them that way from the beginning.</p><p>If you’re doing your own sound or working with a sound designer who doesn’t have much experience in games, here are a few situations to look out for where “force to mono” can be either helpful or harmful:</p><h4>Mono Content in a Stereo Container</h4><p>Stereo is the <em>most standard of audio formats</em>. This means that many sound effects you might find online or from the Unity Asset Store may be packaged in a stereo container even though there is <strong>no real stereo content.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/859/1*hXUbBvd50zuv-gty_ttu1g.jpeg" /><figcaption><em>Skip to 15:55 in our video tutorial for audio examples of this situation.</em></figcaption></figure><p>As you can hear from the Wilhelm Scream example, there is no difference in sound after forcing it to mono. In this situation, it is safe to say that this was effectively already a mono sound effect, just packaged in a stereo container (i.e. the two channels of audio had the exact same content). In our experience, <em>this is a very common occurrence</em> so always double-check.</p><h4>Loudness Issues after Force to Mono</h4><p>Another thing to notice when forcing to mono is the loudness of the newly created mono audio file. It’s somewhat quieter than the original. Unity is aware of this issue, and you can remedy it by selecting the <em>normalize </em>option.</p><h4>Phase Cancellation</h4><p>Forcing a stereo file with stereo information to mono can cause phase cancellation issues like those we encountered in the examples from the last section. If there is a noticeable difference in the quality of the audio after forcing to mono, you’ll have to decide for yourself whether it is acceptable for that sound and its role in your game.</p><p>Now that we’ve discussed this issue in-depth, do we need to go through all of our audio assets and make this decision for each one individually? Luckily, no.</p><h4>How to Choose</h4><p>There are always exceptions to the rules, but the guidelines below should help you make some basic decisions regarding the audio assets in your game.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*p1RQmnNmqt69pAqSgpRkTQ.jpeg" /></figure><h3>Final Words</h3><p>Let’s summarize the most important information:</p><ul><li>Force to Mono is extremely important for <em>optimizing the performance </em>of your audio</li><li>For 3D sound sources, <em>Unity will force to mono automatically</em> so there is no reason not to force stereo sounds to mono in this situation</li><li>Mono SFX often comes packaged in stereo containers. Leaving these sounds as stereo files <em>waste your game’s resources</em></li><li>Be careful that <em>phase cancellation</em> doesn’t degrade the sound quality of your stereo SFX when forcing them to mono</li></ul><p>That’s it! We hope this has helped you to understand the difference between mono and stereo audio, the <em>“Force to Mono”</em> option in Unity’s Audio Import Settings, and why it is important for <strong>your game</strong>.</p><p>If you want to learn more about how audio functions in Unity, be sure to check out our other tutorials (<em>linked below</em>). If you have a question, leave it in the comments or contact us directly through our website:</p><p><a href="https://doubleshot-audio.com/">Double Shot Audio</a></p><h4>Other Tutorials:</h4><ul><li><a href="https://medium.com/double-shot-audio/understanding-audio-compression-settings-in-unity-e879a821023f">Understanding Audio Compression Settings in Unity</a></li><li><a href="https://medium.com/double-shot-audio/choosing-the-right-load-type-in-unitys-audio-import-settings-1880a61134c7">Choosing the Right Load Type in Unity’s Audio Import Settings</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2fbf92ddb7b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>