Java - downsampling wav audio file

Hi, I need to reduce the sample size of wav audio files from 44.1 kHz to 8 kHz. I have to do all the work manually using an array of bytes ... for academic purposes.

I am currently using 2 classes, Sink and Source, to create byte arrays as well. Everything is going well until I get to the part where I need to reduce the amount of data using linear interpolation.

Since I am downsampling from 44100 to 8000 Hz, how can I interpolate an array of bytes containing something like 128,000,000 bytes? Right now, I am outputting 5, 6 or 7 bytes depending on i% 2 == 0, i% 2 == 1 and i% 80 == 0 and popping the average of these 5, 6 or 7 bytes into a new file,

The result is a smaller sound file than the original, but it cannot be played on the Windows media player (it says there is an error while reading the file), and there is a lot of noise, although I hear the correct track behind the noise.

So, to summarize, I need help regarding the linear interpolation part. Thanks in advance.

+6
java audio wav
source share
1 answer

I think you should not use the average of these samples, as this will be a middle filter, and not exactly downsampling. Just use every 5/6 / 7th pattern and write this to a new file.

This will probably have some anti-aliasing artifacts, but can be generally recognized.

Another, more complex solution, but probably with better results, in terms of quality, would first convert your samples to a frequency distribution using FFT or DFT, and then convert it with the appropriate sample rate. It has been a while since I did this, but it is definitely doable. You may need to play a little to make it work properly.

Also, when you do not accept the FT of the full array, but rather in segments, the problem with the boundaries of the segments is 0. Several years ago, when I played with these things, I did not come up with a viable solution to this problem (since it also creates artifacts), but there is probably one if you are reading the right books :-)

As for the WMP complaining about the file: you changed the header you write accordingly, right?

+7
source share

All Articles