VoxForge
Downsampling and interpolation
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) ---