Audio and Prompts Discussions

Flat
Downsampling and interpolation
User: johnwcassidy
Date: 9/22/2008 10:21 am
Views: 6528
Rating: 3

I have audio files recorded at 44100 Hz, and I want to downsample them to 16000 Hz. I wrote a downsampler function that simply takes the factor of the original / desired and creates a new byte array of that size, and grabs the byte values using that factor as a jumping point.

downsample(byte[] inputAudio, inSample, outSample)
{
factor = inSample/ outSample;
length = inputAudio.length / factor;
newData = new byte[length];
           int index;
           for(int i=0; i<newData.length-1; i++)
           {
               index = (int)(i*factor);
               newData = audioData[index];
               i++;
               newData = audioData[index+1];
           }
//create wav header, output
}

This only works if the outSample is a factor of the inSample. If I want to convert from 441000 to 16000 we get a factor of 2.75 which will not work.


The solution I believe would be interpolating the data.


Does anybody have any information on the best way to approach this problem? Linear interpolation using a factor of 3, and the known amplitude of that datapoint I believe would result in amplitudes never reaching the max.


for example, if the integer value a single data point of a 16 bit signed audio stream is 65000, the interpolated result would always be below this level. I can't imagine this would produce an accurate result.

--- (Edited on 9/22/2008 10:21 am [GMT-0500] by Visitor) ---

Re: Downsampling and interpolation
User: Tony Robinson
Date: 9/22/2008 1:40 pm
Views: 2859
Rating: 4

Sorry to tell you, but even at integer rates you are going to get a lot of distortion (known as aliasing).

If you really want to do it yourself I suggest you start at http://en.wikipedia.org/wiki/Downsampling

Otherwise common packages such as sox can do this for you.

 

Tony

-- 

Dr Tony Robinson
CEO Cantab Research Ltd

--- (Edited on 22-September-2008 7:40 pm [GMT+0100] by Tony Robinson) ---

PreviousNext