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 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.