Home | History | Annotate | Download | only in devices
      1 page.title=Sample Rate Conversion
      2 @jd:body
      3 
      4 <!--
      5     Copyright 2013 The Android Open Source Project
      6 
      7     Licensed under the Apache License, Version 2.0 (the "License");
      8     you may not use this file except in compliance with the License.
      9     You may obtain a copy of the License at
     10 
     11         http://www.apache.org/licenses/LICENSE-2.0
     12 
     13     Unless required by applicable law or agreed to in writing, software
     14     distributed under the License is distributed on an "AS IS" BASIS,
     15     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     16     See the License for the specific language governing permissions and
     17     limitations under the License.
     18 -->
     19 <div id="qv-wrapper">
     20   <div id="qv">
     21     <h2>In this document</h2>
     22     <ol id="auto-toc">
     23     </ol>
     24   </div>
     25 </div>
     26 
     27 <h2 id="srcIntro">Introduction</h2>
     28 
     29 <p>
     30 See the Wikipedia article
     31 <a href="http://en.wikipedia.org/wiki/Resampling_(audio)">Resampling (audio)</a>
     32 for a generic definition of sample rate conversion, also known as "resampling."
     33 The remainder of this article describes resampling within Android.
     34 </p>
     35 
     36 <p>
     37 Sample rate conversion is the process of changing a
     38 stream of discrete samples at one sample rate to another stream at
     39 another sample rate.  A sample rate converter, or resampler, is a module
     40 that implements sample rate conversion.  With respect to the resampler,
     41 the original stream is called the source signal, and the resampled stream is
     42 the sink signal.
     43 </p>
     44 
     45 <p>
     46 Resamplers are used in several places in Android.
     47 For example, an MP3 file may be encoded at 44.1 kHz sample rate and
     48 needs to be played back on an Android device supporting 48 kHz audio
     49 internally. In that case, a resampler would be used to upsample the MP3
     50 output audio from 44.1 kHz source sample rate to a 48 kHz sink sample rate
     51 used within the Android device.
     52 </p>
     53 
     54 <p>
     55 The characteristics of a resampler can be expressed using metrics, including:
     56 </p>
     57 
     58 <ul>
     59 <li>degree of preservation of the overall amplitude of the signal</li>
     60 <li>degree of preservation of the frequency bandwidth of the signal,
     61     subject to limitations of the sink sample rate</li>
     62 <li>overall latency through the resampler</li>
     63 <li>consistent phase and group delay with respect to frequency</li>
     64 <li>computational complexity, expressed in CPU cycles or power draw</li>
     65 <li>permitted ratios of source and sink sample rates</li>
     66 <li>ability to dynamically change sample rate ratios</li>
     67 <li>which digital audio sample formats are supported</li>
     68 </ul>
     69 
     70 <p>
     71 The ideal resampler would exactly preserve the source signal's amplitude
     72 and frequency bandwidth (subject to limitations of the sink
     73 sample rate), have minimal and consistent delay, have minimal
     74 computational complexity, permit arbitrary and dynamic conversion ratios,
     75 and support all common digital audio sample formats.
     76 In practice, ideal resamplers do not exist, and actual resamplers are
     77 a compromise among these characteristics.
     78 For example, the goals of ideal quality conflict with short delay and low complexity.
     79 </p>
     80 
     81 <p>
     82 Android includes a variety of audio resamplers, so that appropriate
     83 compromises can be made depending on the application use case and load.
     84 Section <a href="#srcResamplers">Resampler implementations</a>
     85 below lists the available resamplers, summarizes their characteristics,
     86 and identifies where they should typically be used.
     87 </p>
     88 
     89 <h2 id="srcResamplers">Resampler implementations</h2>
     90 
     91 <p>
     92 Available resampler implementations change frequently,
     93 and may be customized by OEMs.
     94 As of Android 4.4, the default resamplers
     95 in descending order of signal distortion, and ascending order of
     96 computational complexity include:
     97 </p>
     98 
     99 <ul>
    100 <li>linear</li>
    101 <li>cubic</li>
    102 <li>sinc with original coefficients</li>
    103 <li>sinc with revised coefficients</li>
    104 </ul>
    105 
    106 <p>
    107 In general, the sinc resamplers are more appropriate for higher-quality
    108 music playback, and the other resamplers should be reserved for cases
    109 where quality is less important (an example might be "key clicks" or similar).
    110 </p>
    111 
    112 <p>
    113 The specific resampler implementation selected depends on
    114 the use case, load, and the value of system property
    115 <code>af.resampler.quality</code>.  For details,
    116 consult the audio resampler source code in AudioFlinger.
    117 </p>
    118