blob: b57717c6138868baa283b310d8678b64c54efd00 [file] [log] [blame]
Glenn Kasten46ac61c2014-01-24 08:59:11 -08001page.title=Sample Rate Conversion
2@jd:body
3
4<div id="qv-wrapper">
5 <div id="qv">
6 <h2>In this document</h2>
7 <ol id="auto-toc">
8 </ol>
9 </div>
10</div>
11
12<p>
13See the Wikipedia article
14<a class="external-link" href="http://en.wikipedia.org/wiki/Resampling_(audio)" target="_android">Resampling (audio)</a>
15for a generic definition of sample rate conversion, also known as "resampling."
16The remainder of this article describes resampling within Android.
17</p>
18
19<p>
20Sample rate conversion is the process of changing a
21stream of discrete samples at one sample rate to another stream at
22another sample rate. A sample rate converter, or resampler, is a module
23that implements sample rate conversion. With respect to the resampler,
24the original stream is called the source signal, and the resampled stream is
25the sink signal.
26</p>
27
28<p>
29Resamplers are used in several places in Android.
30For example, an MP3 file may be encoded at 44.1 kHz sample rate and
31needs to be played back on an Android device supporting 48 kHz audio
32internally. In that case, a resampler would be used to upsample the MP3
33output audio from 44.1 kHz source sample rate to a 48 kHz sink sample rate
34used within the Android device.
35</p>
36
37<p>
38The characteristics of a resampler can be expressed using metrics, including:
39</p>
40
41<ul>
42<li>degree of preservation of the overall amplitude of the signal</li>
43<li>degree of preservation of the frequency bandwidth of the signal,
44 subject to limitations of the sink sample rate</li>
45<li>overall latency through the resampler</li>
46<li>consistent phase and group delay with respect to frequency</li>
47<li>computational complexity, expressed in CPU cycles or power draw</li>
48<li>permitted ratios of source and sink sample rates</li>
49<li>ability to dynamically change sample rate ratios</li>
50<li>which digital audio sample formats are supported</li>
51</ul>
52
53<p>
54The ideal resampler would exactly preserve the source signal's amplitude
55and frequency bandwidth (subject to limitations of the sink
56sample rate), have minimal and consistent delay, have minimal
57computational complexity, permit arbitrary and dynamic conversion ratios,
58and support all common digital audio sample formats.
59In practice, ideal resamplers do not exist, and actual resamplers are
60a compromise among these characteristics.
61For example, the goals of ideal quality conflict with short delay and low complexity.
62</p>
63
64<p>
65Android includes a variety of audio resamplers, so that appropriate
66compromises can be made depending on the application use case and load.
67Section <a href="#srcResamplers">Resampler implementations</a>
68below lists the available resamplers, summarizes their characteristics,
69and identifies where they should typically be used.
70</p>
71
72<h2 id="srcTerms">Terminology</h2>
73
74<dl>
75
76<dt>downsample</dt>
77<dd>to resample, where sink sample rate &lt; source sample rate</dd>
78
79<dt>Nyquist frequency</dt>
80<dd>
81The Nyquist frequency, equal to 1/2 of a given sample rate, is the
82maximum frequency component that can be represented by a discretized
83signal at that sample rate. For example, the human hearing range is
84typically assumed to extend up to approximately 20 kHz, and so a digital
85audio signal must have a sample rate of at least 40 kHz to represent that
86range. In practice, sample rates of 44.1 kHz and 48 kHz are commonly
87used, with Nyquist frequencies of 22.05 kHz and 24 kHz respectively.
88See the Wikipedia articles
89<a class="external-link" href="http://en.wikipedia.org/wiki/Nyquist_frequency" target="_android">Nyquist frequency</a>
90and
91<a class="external-link" href="http://en.wikipedia.org/wiki/Hearing_range" target="_android">Hearing range</a>
92for more information.
93</dd>
94
95<dt>resampler</dt>
96<dd>synonym for sample rate converter</dd>
97
98<dt>resampling</dt>
99<dd>the process of converting sample rate</dd>
100
101<dt>sample rate converter</dt>
102<dd>a module that resamples</dd>
103
104<dt>sink</dt>
105<dd>the output of a resampler</dd>
106
107<dt>source</dt>
108<dd>the input to a resampler</dd>
109
110<dt>upsample</dt>
111<dd>to resample, where sink sample rate &gt; source sample rate</dd>
112
113</dl>
114
115<h2 id="srcResamplers">Resampler implementations</h2>
116
117<p>
118Available resampler implementations change frequently,
119and may be customized by OEMs.
120As of Android 4.4, the default resamplers
121in descending order of signal distortion, and ascending order of
122computational complexity include:
123</p>
124
125<ul>
126<li>linear</li>
127<li>cubic</li>
128<li>sinc with original coefficients</li>
129<li>sinc with revised coefficients</li>
130</ul>
131
132<p>
133In general, the sinc resamplers are more appropriate for higher-quality
134music playback, and the other resamplers should be reserved for cases
135where quality is less important (an example might be "key clicks" or similar).
136</p>
137
138<p>
139The specific resampler implementation selected depends on
140the use case, load, and the value of system property
141<code>af.resampler.quality</code>. For details,
142consult the audio resampler source code in AudioFlinger.
143</p>