开发者

PCM algorithm for upsampling

I have 8k16bit pcm audio and I want to upsample it to 16k16bit. I have to do this manually.

Can someone tell me the algorithm for linear interpolation? Should I interpolate between each two bytes?

Also when I upsample开发者_JS百科 i have to make changes for the wav header - what should I change?


As others have mentioned, linear interpolation doesn't give the best sound quality, but it's simple and cheap.

For each new sample you create, just average it with the next one, e.g.

short[] source = ...;
short[] result = new short[source.length * 2];
for(int i = 0; i < source.length; ++i) {
  result[i * 2] = source[i];
  result[i * 2 + 1] = (source[i] + source[i + 1]) / 2;
}

You should definitely search for a library that helps you with working with WAV files. Even though it's a simple format, you shouldn't have to do that yourself if there's code available that will do what you need. By the way, why are you doing this in the first place? Perhaps you could just use sox or a similar tool to do this.


Can someone tell me the algorithm for linear interpolation? Should I interpolate between each two bytes?

sure:

double interpolate_linear(double a, double b, double x) {
    assert(0.0 <= x);
    assert(1.0 >= x);

    if (0.0 >= x)
        return a;
    else if (1.0 <= x)
        return b;
    else
        return (1.0 - x) * a + x * b;
}

linear interpolation, while better than nothing, has a high amount of error. it's better to zero fill and window if you have the cpu time.

Also when I upsample i have to make changes for the wav header - what should I change?

not sure for java.


Here's a good link to working with WAV files in java:

http://www.labbookpages.co.uk/audio/javaWavFiles.html


Not sure about the header, but I would look into cubic spline interpolation. You could look at this website. It's got a very neat way of performing cubic interpolation. I'm not sure how to modify the header, but I'm pretty sure there have been answers to that on Stack Overflow that you could search for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜