From alsa-devel-owner@alsa.jcu.cz  Sun Jul 26 12:50:40 1998
Received: from altrade.nijmegen.inter.nl.net (altrade.nijmegen.inter.nl.net [193.67.237.6])
	by marvin.jcu.cz (8.8.8/8.8.8) with ESMTP id MAA31364
	for <alsa-devel@jcu.cz>; Sun, 26 Jul 1998 12:50:16 +0200
Received: from obelix.fvdpol.inter.nl.net by altrade.nijmegen.inter.nl.net
	via bd99-9.Breda.NL.net [193.79.246.234] with ESMTP for <alsa-devel@jcu.cz>
	id MAA11716 (8.8.8/3.28); Sun, 26 Jul 1998 12:50:14 +0200 (MET DST)
Received: (from frank@localhost) by obelix.fvdpol.inter.nl.net (8.8.7/8.7.3) id MAA05890 for alsa-devel@jcu.cz; Sun, 26 Jul 1998 12:04:51 +0200
From: Frank van de Pol <F.K.W.van.de.Pol@inter.nl.net>
Message-Id: <199807261004.MAA05890@obelix.fvdpol.inter.nl.net>
Subject: Sample rate conversion (was: ALSA driver 0.2.0-pre2)
To: alsa-devel@jcu.cz
Date: Sun, 26 Jul 1998 12:04:51 +0200 (MET DST)
In-Reply-To: <19980723121606.B1702@ruhr-uni-bochum.de> from "Marcus Brinkmann" at Jul 23, 98 12:16:06 pm
Content-Type: text
Reply-To: alsa-devel@alsa.jcu.cz
Sender: alsa-devel-owner@alsa.jcu.cz
Precedence: list

Marcus Brinkmann wrote:
> 
> On Thu, Jul 23, 1998 at 11:19:55AM +0200, Thomas Sailer wrote:
> > 
> > Ugh. What you're suggesting is linear interpolation.
> > This is indeed used in commercial sample rate converter chips,
> > _BUT_ only as a last stage, preceded by a polyphase low pass filter,
> > and this is what you have to do if you want decent quality.
> > Just using linear interpolation gives you significant new (and thus
> > unwanted) spectral components.
> 
> Okay, I see everyone else than me knows better about this. :) Thank you for
> your explanation, it is very much appreciated. I think the low pass is used
> to filter out the high frequencies that can't be presented in the new sample
> rate? How are pass filteers implemented in software (do you need Fourier for
> this, this would be slow...)?
> 

Sorry if i'm wrong or my memory has faded too much, but in my understanding
most chips/dsp's that perform sample rate conversion do _first_ a linear
interpolation to a sample rate that is multiple times higher than the
desired output rate (4fs or even higher), then perform a low-pass filter at
fs/2 to cut the unwanted (mirrored) frequency components, and then resample
it to the desired frequency (fs) by simply decimating the samples.

The trick to first resample to a higher frequency and not directly to the
desired frequency is to allow a simpler filter. In this case a 'not so
steep' filter (ie. shorter FIR filter) is good enough. 

One big concern:

Please keep in mind that mixing of multiple sample streams is a cpu
intensive process. Doing an "perfect" sample rate conversion will make this
computation much more intensive, and requires quite some DSP power. It is
not a coincidence that the big DSP companies are producing dedicated sample
conversions chips!

If we do want to implement proper sample rate conversion it will have to be
at least configurable (per stream?). If the whole conversion and mixing
algorithm appears be too slow to run in real time on a certain machine, the
grade of conversion qualtity can perhaps be dynamicly reduced.


quality 0: (least)
	- simple sample rate conversion, by simply repeating old values.
	  will give a 'harsh' sound, with losts of additional frequencies

quality 1: (better)
	- use linear interpolation to get the desired frequency. For most
	  applications this does sound quitte good.

quality 2: (even better)
	- linear interpolation, with the over sampling and low-pass
	  filtering.

quality >2: even better, more costly algorithms???


For a start quality 0 or 1 will be good enough. Perfection can be added
later...

Setting conversion quality on a 'per input stream' basis allow for tuning
the cpu performance/sound quality trade-off. Some sounds are less sensitive
to distortion caused by resampling than others.

Just my 0.02 euro's

Frank.


+---- --- -- -  -   -    - 
|Frank van de Pol                  -o)
|F.K.W.van.de.Pol@inter.NL.net     /\\
|                                 _\_v
|Linux - Why use Windows, since there is a door?
|
|ALSA Sequencer: http://www.inter.nl.net/users/F.K.W.van.de.Pol/alsa/

