Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!valid!caber!lou From: lou@caber.valid.com (Louis K. Scheffer) Newsgroups: comp.dsp Subject: Re: 48k to 44.1k sample rate conversion Message-ID: <457@valid.valid.com> Date: 18 May 91 08:06:35 GMT References: <5826@media-lab.media.mit.edu.MEDIA.MIT.EDU> Sender: news@valid.com Lines: 58 joe@media-lab.media.mit.edu.MEDIA.MIT.EDU (Joe Chung) writes: >In the digital audio world, a lot of sound is recorded at a 48k sample >rate. A CD, however, is at 44.1k. As we all know, the classic >technique of sample rate conversion would have us upsample to the >lowest common multiple, low-pass filter, and downsample to the desired >rate. The only problem is that the LCM of 44.1k and 48k is 21.168 Meg! >A 4 minute stereo soundfile at 48k takes up about 50 megabytes, which >means that it's 21.168M upsampled version would be over 22 gigabytes! >Obviously, sample rate converters don't store the entire intermediate, >upsampled version, but I was wondering if anyone has a good idea of >what sorts of schemes they do use. Do they do some sort of overlap- >save method akin to block convolution? Does anyone have any code >to do this? The most straightforward way is as follows: You interpolate 146 zeros between every sample to get a data rate of 7.056 MHz. You then design a digital filter to low-pass this to 20 KHz. This can be an FIR filter with perfect phase and arbitrarily good frequency response, subject only to the limits of your computing power. One DSP chip will easily get you +-0.05 db. You then discard 159 of every 160 samples to get 44.1 KHz. Since there is no content above 22.05 KHz, this loses nothing. Assuming you have done all high-precision math up to this point, then the last step, rounding back to 16 bits, is the only one that introduces any error. This error will most likely appear as white noise spread over the whole spectrum (just like the noise introduced on the first A/D conversion). The level should be very low (-96 db, more or less). Computationally, you never store the interpolated 0s, and you never compute the samples that will be discarded. Say the FIR filter with a 7 MHz rate and a 20KHz cutoff has 20000 coefficients (just a guess). Since 146/147 of the data are 0, you must do 20000/147 = 136 multiplies to get each output point. Hence you keep the last 136 samples at 48 KHz, and multiply by 136 coefficients (spaced 147 apart) from the FIR filter. Since all possible phases between the two signals are present (otherwise you did not have the least common multiple) you must keep all 20000 coefficients. Each output point uses a different 136 element subset up to the 147th output point, which uses the same coefficients as the first output point, and the cycle repeats. So the only question is computing the coefficients to use in the FIR filter. This is conceptually straightforward (See, for example, the fortran program in Rabiner and Gold, "Theory and Application of Digital Signal Processing") but such a long filter may stress the limits of computer arithmetic. Since you only need to compute it once, however, it should be simple to adapt the algorithm to higher precision arithmetic. I have the coefficients lying around somewhere for 48.0 -> 44.0 KHz conversion (an easier problem) but not for 48.0 -> 44.1. If someone computes them, or has them, maybe they could post a message saying where they can be found. Hope this helps, Lou Scheffer