blob: ffacba6648bebf94ad39ac87c6804b887433e6cf [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
Clay Murphy3a7af3a2014-09-09 17:29:09 -070012<h2 id="srcIntro">Introduction</h2>
13
Glenn Kasten46ac61c2014-01-24 08:59:11 -080014<p>
15See the Wikipedia article
Clay Murphydc85c742014-09-10 15:10:03 -070016<a href="http://en.wikipedia.org/wiki/Resampling_(audio)">Resampling (audio)</a>
Glenn Kasten46ac61c2014-01-24 08:59:11 -080017for a generic definition of sample rate conversion, also known as "resampling."
18The remainder of this article describes resampling within Android.
19</p>
20
21<p>
22Sample rate conversion is the process of changing a
23stream of discrete samples at one sample rate to another stream at
24another sample rate. A sample rate converter, or resampler, is a module
25that implements sample rate conversion. With respect to the resampler,
26the original stream is called the source signal, and the resampled stream is
27the sink signal.
28</p>
29
30<p>
31Resamplers are used in several places in Android.
32For example, an MP3 file may be encoded at 44.1 kHz sample rate and
33needs to be played back on an Android device supporting 48 kHz audio
34internally. In that case, a resampler would be used to upsample the MP3
35output audio from 44.1 kHz source sample rate to a 48 kHz sink sample rate
36used within the Android device.
37</p>
38
39<p>
40The characteristics of a resampler can be expressed using metrics, including:
41</p>
42
43<ul>
44<li>degree of preservation of the overall amplitude of the signal</li>
45<li>degree of preservation of the frequency bandwidth of the signal,
46 subject to limitations of the sink sample rate</li>
47<li>overall latency through the resampler</li>
48<li>consistent phase and group delay with respect to frequency</li>
49<li>computational complexity, expressed in CPU cycles or power draw</li>
50<li>permitted ratios of source and sink sample rates</li>
51<li>ability to dynamically change sample rate ratios</li>
52<li>which digital audio sample formats are supported</li>
53</ul>
54
55<p>
56The ideal resampler would exactly preserve the source signal's amplitude
57and frequency bandwidth (subject to limitations of the sink
58sample rate), have minimal and consistent delay, have minimal
59computational complexity, permit arbitrary and dynamic conversion ratios,
60and support all common digital audio sample formats.
61In practice, ideal resamplers do not exist, and actual resamplers are
62a compromise among these characteristics.
63For example, the goals of ideal quality conflict with short delay and low complexity.
64</p>
65
66<p>
67Android includes a variety of audio resamplers, so that appropriate
68compromises can be made depending on the application use case and load.
69Section <a href="#srcResamplers">Resampler implementations</a>
70below lists the available resamplers, summarizes their characteristics,
71and identifies where they should typically be used.
72</p>
73
Glenn Kasten46ac61c2014-01-24 08:59:11 -080074<h2 id="srcResamplers">Resampler implementations</h2>
75
76<p>
77Available resampler implementations change frequently,
78and may be customized by OEMs.
79As of Android 4.4, the default resamplers
80in descending order of signal distortion, and ascending order of
81computational complexity include:
82</p>
83
84<ul>
85<li>linear</li>
86<li>cubic</li>
87<li>sinc with original coefficients</li>
88<li>sinc with revised coefficients</li>
89</ul>
90
91<p>
92In general, the sinc resamplers are more appropriate for higher-quality
93music playback, and the other resamplers should be reserved for cases
94where quality is less important (an example might be "key clicks" or similar).
95</p>
96
97<p>
98The specific resampler implementation selected depends on
99the use case, load, and the value of system property
100<code>af.resampler.quality</code>. For details,
101consult the audio resampler source code in AudioFlinger.
102</p>