Re: [linux-audio-dev] Re: Bandlimited interpolation suitable for realtime audio

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: Re: [linux-audio-dev] Re: Bandlimited interpolation suitable for realtime audio
From: David Olofson (audiality_AT_swipnet.se)
Date: pe syys   03 1999 - 20:19:56 EDT


On Sat, 04 Sep 1999, Benno Senoner wrote:
[...]
> By oversampling by a factor of 2
[...]
> If this is the only approach for oversampling, then the drawback is it's use
of > in a comple audio engine like audiality,
> since you have to run the entire signal-path at twice the samplingrate,
> until you output the results to the DAC.
> This is very expensive in terms of CPU usage.

Indeed. Think about FIR filters and the like. Not only does the sample rate
double; many algorithms also have to deal with doubled window sizes at that
rate... (Unless, of course, they cheat and take for granted that the supersonic
noise won't get out of the system in any form. Wouldn't be a nice burden to put
on plug-in developers, though.)

> Another approach could be to put a 20kHz lowpassfilter after each
> polinomial interpolator/oversampler,
> but that means if you play 30 voices on your soft-sampler you have to
> activate 20 low-passfilters which means additional CPU consumption.

Low pass filters at fixed frequencies related to the sample rate don't have to
be very CPU consuming, especially not compared to most alternative solutions.
(That is, getting a nice signal directly from the rate conversion.)

OTOH, that would have to be a very steep filter not to cut the treble of the
resampled signals... Of course, such and "analog style" artifact would be _a
lot_ better than any the usual kinds of distortion in digital systems.

[...]
> I want an interpolation method that has good quality , even when you play
> the data at let's say -2 octaves, but does not use too much multiply-adds.

I'd like to know how the EMU8000 chip (AWE) does it... It sounds very good for
being something you can find on low end sound cards, so the obvious question is
"How do they do it without lots of expensive DSP power?"

Ok, the chip *does* have some restrictions, but as long as you stay within
reasonable sample rates, it sounds pretty clean. (Heck, pro synths have
audible artifacts! The EMU8000 + decent external DAC beats many of them
easily...)

> Using linear interpolating condributes to "edges" into the signal , which means
> harmonic distortion.

Yep... It draws straight lines between the samles, which is not a very good
aproximation for data with high frequency components.

> I experimented a bit with the "natural cubic spline" ( 3rd order) ,
> I tested this by sampling 2 periods (4*PI) of a pure sine ,
> using 20 points.
> for the first 17 samples the maximum error between interpolated signal
> and original sine is about -68dB which is quite good if you consider that
> there are only 10 points per 2PI period.
> The last 3 samples show higher errors , up to -35dB, but I think this is
> because the interpolator does not know how the sine wave continues.

This is a common problem. BTW, this is one of the limitations of that EMU chip;
it doesn't feed samples into the resampling algo through the "DMA", so it fails
to handle loops correctly. You have to copy the first two samples of the loop
to after the end of the loop to avoid clicks. Not nice if you had in mind
sliding the loops in real time, and bl**dy frustrating the patch editor
doesn't handle it automatically...

> It's interesting that the last sample is one step before the next zero cross,
> and if I choose 21 points (therefore including the last zero cross),
> the maximum error stays below the -68dB mark even for the last samples.
> The algorithm takes about 12 multiplications per sample or so.
>
> comments about this algorithm ?
> (There seems to be some software aroung which uses the spline approach
> to perform audio interpolation)

Don't know if they're using something like that, but E-mu claims to have
"8-point interpolation" in their newer samplers. Unfortunately, I'm afraid
asking them how they do it wouldn't work! ;-)

> > Another point is that if you're willing to spend 5-6 mulitiplications per
> > sample on interpolation, I don't believe polynomial interpolation is
> > superior to bandlimited interpolation at that complexity level. To
> > compare them, we have to view polynomial interpolation in terms of its
> > frequency response as a "bandlimited interpolation filter". (After all,
> > both methods simply implement time-varying linear filters on the original
> > samples, so on that level they are equivalent --- they only differ
> > fundamentally in the coefficients used.)
>
> About the complexity level of bandlimited interpolation:
>
> Using polinomial interpolation the number of multiplications per sample stays
> constant, regardless of pitch, we just have to traverse the wave table faster
> or slower.
> Using bandlimited interpolation , lowering the pitch by 2 octaves produces four
> times the CPU load of the playback at normal pitch.
>
> The big advantage of bandlimited interpolation is that you can play the data
> at higher pitches without aliasing problems + higher pitches = no increased CPU
> load.
> correct me please if I'm wrong.

What about crossfading or switching? (Is there a "safe" switch point, that
wouldn't result in a sudden change of the frequency response?) From what I have
managed to find out about synthesizers, most use various tricks to get good
quality across the entire resampling range. It seems that some do only
downsampling, while others do only upsampling. That's used in combination
with either some highly optimized +/- n octaves resampling algorithms, or just
plain preprocessed data.

(Again, that EMU does up to +2 octaves, and doesn't seem to have a low limit.
However, only around +1/-2 octaves can be used without undesired side effects,
but that depends a bit on the actual data.)

[...]
> > Ultimately, the question is how do you want to design the lowpass filter that
> > guards against aliasing.
> > The bandlimited interpolation formulation allows you to address that issue
> > explicitly rather than just "getting what you get" with polynomial
> > interpolation.
>
> What kind of 20kHz lowpass filter would you recommend ?
> Butterworth / Bessel / Chebyshev ? which order ? ( is 6th order to heavy ?)

20 kHz doesn't sound like a very good choice to me... There's a reason why we
use 44.1 or 48 kHz and not 40 kHz, and that's the fact that higher rates means
less steep filters without getting a drop within the audible range, or letting
the "problems" out through the filter...

Back in the Amiga days, I managed to cut away lots of distortion in a CPU based
music engine by simply running the resampler (no interpolation - no way to do
that even with my 25 MHz 68030!) at twice the output sample rate, and then
downsampling the mixed signal through a simple interpolation filter.

> Which factors are more important for sample-playback engines ?
> (like impulse response , step response etc.)

Percieved audio quality is important. The rest is just theory. In some cases,
this means h*ll, in other cases, it means "cheating" actually results in better
audio quality.

For example, the very simple filters I used in the old Win16 Audiality engine
were "simulated RC filters", which meant that they had the normal problems
simple analog RC filters have. They probably did far more weird stuff to the
signal than carefully designed FIR filters, but they showed no audible
"digital" side effects whatsoever. And a 6dB filter can be as little as one
subtraction, one multiplication (or shift) and one add, regardless of the
sample rate/cutoff frequency ratio...

> I jus did a quick math:
>
> let's assume a spline interpolator + 6th order ( 36dB/oct) Butterworth
> lowpass at 20kHz
> 12 multiplications for the interpolator and 9 for the lowpass filter =
> 21 multiplications.
>
> Let's assume playback at pitch -2 octaves:
> nr.of multiplications / output-sample:
>
> 104 for bandlimited interpolation
> 21 for the cubic interpolation + lowpass filter.
>
> correct ?
>
> (David: your thoughts about quality vs. performance tradeoffs ?)

Well, as a system with obvious and unpleasant digital artifacts is more or less
usless for anything but entertainment systems and consumer products, we just
have to pay what it costs.

However, trying to achieve the Perfect Resampling Algorithm is just plain
pointless. First, it'll most likely use up so much CPU power that no one will
afford building a usable system. Second, there's a good chance our efforts of
getting a clinically perfect sound will only result in a harch, cold and dead
system... All systems affect the audio in one way or another, and the important
thing is to make sure the effect doesn't destroy the signals.

Extra harmonics are often regarded as a *positive* effect, but unfortunately,
most distortion we're likely to get in a digital system is of everything but
that kind... Noise is usually less noticable than aliasing distortion. An
unlinear frequency response is far more pleasant to the ears than audible
interference frequenices.

So, "If it sounds good, it IS good", but of course, keeping an eye on the
frequency response and phase diagrams may save us from some unpleasant
surprises. Some audio signals just have a way of making most systems sound like
@£$@¤...

And of course, there's always the option of just using a different resampler
plug-in, if you don't like the standard one. Or use different ones for
different kinds of audio, if you're really picky. Try that with a dedicated
sampler... ;-)

//David

 ·A·U·D·I·A·L·I·T·Y· P r o f e s s i o n a l L i n u x A u d i o
- - ------------------------------------------------------------- - -
    ·Rock Solid David Olofson:
    ·Low Latency www.angelfire.com/or/audiality ·Audio Hacker
    ·Plug-Ins audiality_AT_swipnet.se ·Linux Advocate
    ·Open Source ·Singer/Composer


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : pe maalis 10 2000 - 07:25:53 EST