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