I am currently trying to convert data from a non compressed WAV file for academic purposes and I'm stuck with that linear interpolation theory.
According to captfoss in this
post , he explains how linear interpolation can work from 8000 to 16000.
Say you have the following "sound" data at 8000, and you want to convert it to 16000.
1 3 1 3 1 3 1 3 (@ 8000)
becomes
1 ? 3 ? 1 ? 3 ? 1 ? 3 ? 1 ? 3 (@ 16000)
The first thing I think I understand is that from 44100 to 8000 I will need to sample
5 bytes when i % 2 == 1
6 bytes when i % 2 == 0
7 bytes when i % 80 == 0
where i is the byte from a byte array data.
I'm trying to interpolate these samples using an average and the outputed file has the correct sound within but with HUGE noise.
I have a file source and file sink where I pop bytes from the data and push the resampled one.
The WAV reader is already parsed in this code sample:
int counter = 1;
int counterPush = 0;
while( counter <= subchunk2IDSize ) {
int toPop = 5;
if( 0 == counter % 2 ) {
toPop++;
}
if( 0 == counter % 80 ) {
toPop++;
}
byte[] toPush = new byte[]{ByteArray.getAverageByte(_source.pop(toPop))};
counterPush++;
_sink.push(toPush);
counter += toPop;
}
_sink.close();
ByteArray.getAverageByte function:
static public byte getAverageByte(byte[] bytes)
{
int sum = 0;
for (byte b : bytes) {
sum += b;
}
return (byte) (sum / bytes.length);
}
I would be grateful if someone could help me or direct me in the good way :)