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 See <a href="terminology.html#srcTerms">Sample Rate Conversion</a> for related terminology. 35 </p> 36 37 <p> 38 Sample rate conversion is the process of changing a 39 stream of discrete samples at one sample rate to another stream at 40 another sample rate. A sample rate converter, or resampler, is a module 41 that implements sample rate conversion. With respect to the resampler, 42 the original stream is called the source signal, and the resampled stream is 43 the sink signal. 44 </p> 45 46 <p> 47 Resamplers are used in several places in Android. 48 For example, an MP3 file may be encoded at 44.1 kHz sample rate and 49 needs to be played back on an Android device supporting 48 kHz audio 50 internally. In that case, a resampler would be used to upsample the MP3 51 output audio from 44.1 kHz source sample rate to a 48 kHz sink sample rate 52 used within the Android device. 53 </p> 54 55 <p> 56 The characteristics of a resampler can be expressed using metrics, including: 57 </p> 58 59 <ul> 60 <li>degree of preservation of the overall amplitude of the signal</li> 61 <li>degree of preservation of the frequency bandwidth of the signal, 62 subject to limitations of the sink sample rate</li> 63 <li>overall latency through the resampler</li> 64 <li>consistent phase and group delay with respect to frequency</li> 65 <li>computational complexity, expressed in CPU cycles or power draw</li> 66 <li>permitted ratios of source and sink sample rates</li> 67 <li>ability to dynamically change sample rate ratios</li> 68 <li>which digital audio sample formats are supported</li> 69 </ul> 70 71 <p> 72 The ideal resampler would exactly preserve the source signal's amplitude 73 and frequency bandwidth (subject to limitations of the sink 74 sample rate), have minimal and consistent delay, have minimal 75 computational complexity, permit arbitrary and dynamic conversion ratios, 76 and support all common digital audio sample formats. 77 In practice, ideal resamplers do not exist, and actual resamplers are 78 a compromise among these characteristics. 79 For example, the goals of ideal quality conflict with short delay and low complexity. 80 </p> 81 82 <p> 83 Android includes a variety of audio resamplers, so that appropriate 84 compromises can be made depending on the application use case and load. 85 Section <a href="#srcResamplers">Resampler implementations</a> 86 below lists the available resamplers, summarizes their characteristics, 87 and identifies where they should typically be used. 88 </p> 89 90 <h2 id="srcResamplers">Resampler implementations</h2> 91 92 <p> 93 Available resampler implementations change frequently, 94 and may be customized by OEMs. 95 As of Android 4.4, the default resamplers 96 in descending order of signal distortion, and ascending order of 97 computational complexity include: 98 </p> 99 100 <ul> 101 <li>linear</li> 102 <li>cubic</li> 103 <li>sinc with original coefficients</li> 104 <li>sinc with revised coefficients</li> 105 </ul> 106 107 <p> 108 In general, the sinc resamplers are more appropriate for higher-quality 109 music playback, and the other resamplers should be reserved for cases 110 where quality is less important (an example might be "key clicks" or similar). 111 </p> 112 113 <p> 114 The specific resampler implementation selected depends on 115 the use case, load, and the value of system property 116 <code>af.resampler.quality</code>. For details, 117 consult the audio resampler source code in AudioFlinger. 118 </p> 119