It’s fairly easy to handle other integer input/output relations than 1:x

and x:1. For example, 2:3 would be something like:

```
out[0] = in[0];
out[1] = (in[0]*43691 + in[1]*21845) >> 16;
out[2] = (in[1]*21845 + in[2]*43691) >> 16;
in += 2;
out += 3;
```

Note that

* the input signal must be limited to a 16 bit

integer range [-32768, 32767], or the filter

will overflow

```
* every iteration will access the first sample
of the next input frame
* incrementing pointers is slow on modern CPUs
```

The filter can be generalized, so that the weight factors are

precalculated and stored in an array of size (input ratio + deepth),

where deepth in this case is 1 (“1 point”/linear interpolation).

A simpler, better sounding, more generic, but much slower method is to

derive a sensible integer ratio from the sample rate ratio (5:8, 8:9

etc), and first downsample (more samples out), then upsample (fewer

samples out). When downsampling, build linear slopes between the input

sample level, and when upsampling, use linear interpolation.

A more sophisticated variant would involve a low pass filter before the

upsampling. A good LP filter can eliminate the need for interpolated

downsampling; just fill in with zeroes between the input samples, and

note that you’ll have to adjust the power level. (Scale all filter

coefficient to increase the sum or something; avoids extra

multiplications just to scale the data, and avoids losing bits in an

integer implementation.)

Oops… If go on like this, I might as well code the converter myself!

Maybe I will.

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.

| Multimedia Application Integration Architecture |

| A Free/Open Source Plugin API for Professional Multimedia |

`----------------------> http://www.linuxaudiodev.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |`

--------------------------------------> david at linuxdj.com -'On Tuesday 24 July 2001 15:54, Ryan C. Gordon wrote:

Actually, I lied. I want someone to write a better sample rate

converter. But that wouldn’t require an API change.

One that works with multi channel audio data would be nice.

Not hard to do unless you want it to do sample interpolation.

I could probably knock one up tonight.

Sample interpolation would also be nice.

Mostly, I’m looking for something that converts betweek 8KHz and 11KHz

samples correctly.