1page.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>
30See the Wikipedia article
31<a href="http://en.wikipedia.org/wiki/Resampling_(audio)">Resampling (audio)</a>
32for a generic definition of sample rate conversion, also known as "resampling."
33The remainder of this article describes resampling within Android.
34</p>
35
36<p>
37Sample rate conversion is the process of changing a
38stream of discrete samples at one sample rate to another stream at
39another sample rate.  A sample rate converter, or resampler, is a module
40that implements sample rate conversion.  With respect to the resampler,
41the original stream is called the source signal, and the resampled stream is
42the sink signal.
43</p>
44
45<p>
46Resamplers are used in several places in Android.
47For example, an MP3 file may be encoded at 44.1 kHz sample rate and
48needs to be played back on an Android device supporting 48 kHz audio
49internally. In that case, a resampler would be used to upsample the MP3
50output audio from 44.1 kHz source sample rate to a 48 kHz sink sample rate
51used within the Android device.
52</p>
53
54<p>
55The 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>
71The ideal resampler would exactly preserve the source signal's amplitude
72and frequency bandwidth (subject to limitations of the sink
73sample rate), have minimal and consistent delay, have minimal
74computational complexity, permit arbitrary and dynamic conversion ratios,
75and support all common digital audio sample formats.
76In practice, ideal resamplers do not exist, and actual resamplers are
77a compromise among these characteristics.
78For example, the goals of ideal quality conflict with short delay and low complexity.
79</p>
80
81<p>
82Android includes a variety of audio resamplers, so that appropriate
83compromises can be made depending on the application use case and load.
84Section <a href="#srcResamplers">Resampler implementations</a>
85below lists the available resamplers, summarizes their characteristics,
86and identifies where they should typically be used.
87</p>
88
89<h2 id="srcResamplers">Resampler implementations</h2>
90
91<p>
92Available resampler implementations change frequently,
93and may be customized by OEMs.
94As of Android 4.4, the default resamplers
95in descending order of signal distortion, and ascending order of
96computational 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>
107In general, the sinc resamplers are more appropriate for higher-quality
108music playback, and the other resamplers should be reserved for cases
109where quality is less important (an example might be "key clicks" or similar).
110</p>
111
112<p>
113The specific resampler implementation selected depends on
114the use case, load, and the value of system property
115<code>af.resampler.quality</code>.  For details,
116consult the audio resampler source code in AudioFlinger.
117</p>
118