page.title=Sample Rates @jd:body

On this page

  1. Best Practices for Sampling and Resampling
  2. For More Information

Video

Sample Rates: Why Can't We All Just Agree?

As of Android 5.0 (Lollipop), the audio resamplers are now entirely based on FIR filters derived from a Kaiser windowed-sinc function. The Kaiser windowed-sinc offers the following properties:

See P.P. Vaidyanathan, Multirate Systems and Filter Banks, p. 50 for discussions of the Kaiser Window and its optimality and relationship to Prolate Spheroidal Windows.

The design parameters are automatically computed based on internal quality determination and the sampling ratios desired. Based on the design parameters, the windowed-sinc filter is generated. For music use, the resampler for 44.1 to 48 kHz and vice versa is generated at a higher quality than for arbitrary frequency conversion.

The audio resamplers provide increased quality, as well as speed to achieve that quality. But resamplers can introduce small amounts of passband ripple and aliasing harmonic noise, and they can cause some high frequency loss in the transition band, so avoid using them unnecessarily.

Best Practices for Sampling and Resampling

This section describes some best practices to help you avoid problems with sampling rates.

Choose the sampling rate to fit the device

In general, it is best to choose the sampling rate to fit the device, typically 44.1 kHz or 48 kHz. Use of a sample rate greater than 48 kHz will typically result in decreased quality because a resampler must be used to play back the file.

Use simple resampling ratios (fixed versus interpolated polyphases)

The resampler operates in one of the following modes:

The resampler is fastest in fixed polyphase mode, when the ratio of input rate over output rate L/M (taking out the greatest common divisor) has M less than 256. For example, for 44,100 to 48,000 conversion, L = 147, M = 160.

In fixed polyphase mode, the sampling rate is locked for as many samples converted and does not change. In interpolated polyphase mode, the sampling rate is approximate. The drift is generally on the order of one sample over a few hours of playback on a 48-kHz device. This is not usually a concern because approximation error is much less than frequency error of internal quartz oscillators, thermal drift, or jitter (typically tens of ppm).

Choose simple-ratio sampling rates such as 24 kHz (1:2) and 32 kHz (2:3) when playing back on a 48-kHz device, even though other sampling rates and ratios may be permitted through AudioTrack.

Use upsampling rather than downsampling when changing sample rates

Sampling rates can be changed on the fly. The granularity of such change is based on the internal buffering (typically a few hundred samples), not on a sample-by-sample basis. This can be used for effects.

Do not dynamically change sampling rates when downsampling. When changing sample rates after an audio track is created, differences of around 5 to 10 percent from the original rate may trigger a filter recomputation when downsampling (to properly suppress aliasing). This can consume computing resources and may cause an audible click if the filter is replaced in real time.

Limit downsampling to no more than 6:1

Downsampling is typically triggered by hardware device requirements. When the Sample Rate converter is used for downsampling, try to limit the downsampling ratio to no more than 6:1 for good aliasing suppression (for example, no greater downsample than 48,000 to 8,000). The filter lengths adjust to match the downsampling ratio, but you sacrifice more transition bandwidth at higher downsampling ratios to avoid excessively increasing the filter length. There are no similar aliasing concerns for upsampling. Note that some parts of the audio pipeline may prevent downsampling greater than 2:1.

If you are concerned about latency, do not resample

Resampling prevents the track from being placed in the FastMixer path, which means that significantly higher latency occurs due to the additional, larger buffer in the ordinary Mixer path. Furthermore, there is an implicit delay from the filter length of the resampler, though this is typically on the order of one millisecond or less, which is not as large as the additional buffering for the ordinary Mixer path (typically 20 milliseconds).

For More Information

This section lists some additional resources about sampling and resampling.

Sample rates

Sampling (signal processing) at Wikipedia.

Resampling

Sample rate conversion at Wikipedia.

Sample Rate Conversion at source.android.com.

The high bit-depth and high kHz controversy

24/192 Music Downloads ... and why they make no sense by Christopher "Monty" Montgomery of Xiph.Org.

D/A and A/D | Digital Show and Tell video by Christopher "Monty" Montgomery of Xiph.Org.

The Science of Sample Rates (When Higher Is Better - And When It Isn't).

Audio Myths & DAW Wars

192kHz/24bit vs. 96kHz/24bit "debate"- Interesting revelation