blob: ab70fee5ad403a1ca1cbc8b2ae0ece8b8cacf687 [file] [log] [blame]
page.title=Sample Rate Conversion
Copyright 2013 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.
<div id="qv-wrapper">
<div id="qv">
<h2>In this document</h2>
<ol id="auto-toc">
<h2 id="srcIntro">Introduction</h2>
See the Wikipedia article
<a href="">Resampling (audio)</a>
for a generic definition of sample rate conversion, also known as "resampling."
The remainder of this article describes resampling within Android.
See <a href="terminology.html#srcTerms">Sample Rate Conversion</a> for related terminology.
Sample rate conversion is the process of changing a
stream of discrete samples at one sample rate to another stream at
another sample rate. A sample rate converter, or resampler, is a module
that implements sample rate conversion. With respect to the resampler,
the original stream is called the source signal, and the resampled stream is
the sink signal.
Resamplers are used in several places in Android.
For example, an MP3 file may be encoded at 44.1 kHz sample rate and
needs to be played back on an Android device supporting 48 kHz audio
internally. In that case, a resampler would be used to upsample the MP3
output audio from 44.1 kHz source sample rate to a 48 kHz sink sample rate
used within the Android device.
The characteristics of a resampler can be expressed using metrics, including:
<li>degree of preservation of the overall amplitude of the signal</li>
<li>degree of preservation of the frequency bandwidth of the signal,
subject to limitations of the sink sample rate</li>
<li>overall latency through the resampler</li>
<li>consistent phase and group delay with respect to frequency</li>
<li>computational complexity, expressed in CPU cycles or power draw</li>
<li>permitted ratios of source and sink sample rates</li>
<li>ability to dynamically change sample rate ratios</li>
<li>which digital audio sample formats are supported</li>
The ideal resampler would exactly preserve the source signal's amplitude
and frequency bandwidth (subject to limitations of the sink
sample rate), have minimal and consistent delay, have minimal
computational complexity, permit arbitrary and dynamic conversion ratios,
and support all common digital audio sample formats.
In practice, ideal resamplers do not exist, and actual resamplers are
a compromise among these characteristics.
For example, the goals of ideal quality conflict with short delay and low complexity.
Android includes a variety of audio resamplers, so that appropriate
compromises can be made depending on the application use case and load.
Section <a href="#srcResamplers">Resampler implementations</a>
below lists the available resamplers, summarizes their characteristics,
and identifies where they should typically be used.
<h2 id="srcResamplers">Resampler implementations</h2>
Available resampler implementations change frequently,
and may be customized by OEMs.
As of Android 4.4, the default resamplers
in descending order of signal distortion, and ascending order of
computational complexity include:
<li>sinc with original coefficients</li>
<li>sinc with revised coefficients</li>
In general, the sinc resamplers are more appropriate for higher-quality
music playback, and the other resamplers should be reserved for cases
where quality is less important (an example might be "key clicks" or similar).
The specific resampler implementation selected depends on
the use case, load, and the value of system property
<code>af.resampler.quality</code>. For details,
consult the audio resampler source code in AudioFlinger.