If you're an audio buff writing Android apps,
then there's some exciting things
showing up in L Developer Preview.
My name is Andy, and today we're going
to talk about sample rates for digital audio,
and how to give the best sound to your users.
But hold on-- let's start at the top,
and talk about audio sample rates.
There's devices, content, and connectivity.
And each one approaches sample rates differently.
For example, this phone has a device audio rate
of 48 kilohertz.
But that doesn't guarantee apps on it will be using all of it.
Game apps often use 24 kilohertz and 32 kilohertz sample rates.
Streaming music comes in at 44.1 kilohertz.
Streaming video, 48 kilohertz.
Meanwhile, my hands-free Bluetooth
is chugging along at eight kilohertz.
Which means it's a jungle out there with sample rates, even
just considering the smartphone.
So what is sample rate anyhow?
Simply put, given an analog audio signal,
it's how often you sample its waveform.
So when a game uses 32 kilohertz,
we need to use a resampler to convert to the 48 kilohertz
the phone needs.
As you can expect, this process of resampling
can cause lots of issues.
Generally the one problem everyone talks about
is aliasing.
Aliasing can occur when the audio frequency
is too high for the sample rate.
Then the high frequency signal looks like,
or aliases as a low frequency signal--
as shown with the green signal on the right.
The maximum audio frequency without aliasing
is half the sample rate, also called a Nyquist frequency.
In order to get rid of aliasing, we use a low pass filter.
A low pass filter removes the high frequencies,
which cause aliasing.
It has three bands.
The Passband is for the audio frequencies.
The Stopband prevents high frequencies from aliasing.
And the Transition band is between them.
So what makes a good resampler filter?
First, finite length.
With finite length, ripples occur.
This is Gibbs' phenomena.
Second, we want the ripples in the Passband to be small,
to avoid distorting our audio.
Third, we want ripples in the Stopband to be small,
to avoid raising the Stopband, and allowing high frequencies
to alias.
Last, we want to narrow our Transition band.
A shorter filer length means a wider Transition band.
It's related to the uncertainty principal
between frequency and time.
You want a narrow Transition band.
As you might imagine, designing really good filters are hard.
Having the transition bandwidth doubles the filter length,
doubling the stopband attenuation doubles the filter
length.
Ugh-- design trade-offs.
Good news.
In Android, we compute the sampler filters for you.
Check out these links for information on how that works.
There's lots of resamplers out there.
Where do the ones Android audio provides fit in?
Like plants and animals, there are polynomial resamplers
and filter resamplers.
On a polynomial side, you've probably
heard of linear interpolators, and cubic splines.
Those are typically used for images.
We're a filter-based resampler.
This is more typical for audio.
In particular, we're using a windowed sink filter.
Now let's talk about Android audio
where we've improved the resamplers.
We have increased quality.
In a spectrogram of a sine sweep or chirp,
we inspect a single line.
This means one input frequency corresponds
exactly one output frequency.
This should also be true after sample rate conversion.
Our example shows 44.1 kilohertz to 48 kilohertz,
after a sample rate conversion.
Before we reach the top, see that basket weave pattern?
That's aliasing in harmonics.
Bad.
After is the bottom, which is much cleaner.
This at our low quality setting, and means music
from many devices will sound better.
We dynamically compute filters for your frequencies.
In a spectrogram of 42 kilohertz to 32 kilohertz,
before we reach the top, aliasing
is present on the old resamplers,
as shown in the reflected line down.
After is a bottom.
Again, we clean things up.
This is at our high quality setting.
It means we have less audio artifacts
at different frequencies.
We've also expanded the frequency range for use
to any frequency between eight kilohertz to 48 kilohertz.
So resampling we can use for effects,
or reduce synthesis computation.
We've increased speed.
Our resample rates are about twice as fast
as the older resamplers, for comparable or better quality.
This means more processing for other tasks,
and better battery lifetime.
We've made it easier for you to use
the digital audio on Android.
We like it if you're liberated, to use different sample rates.
Now, it's up to you to make something great.
Please follow these links for more information.
Thanks for watching.