爪哇 - 下采样WAV音频文件 [英] Java - downsampling wav audio file

查看:240
本文介绍了爪哇 - 下采样WAV音频文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我需要将一个WAV音频文件的采样率降低采样率从44.1到8kHz的。我必须用一个字节数组手工做的所有工作......这是为学术目的。

Hi I need to downsample a wav audio file's sample rate from 44.1kHz to 8kHz. I have to do all the work manually with a byte array...it's for academic purposes.

我目前使用的2类,库源,流行,推动字节数组。一切顺利,直到我达到我需要采用线性插值下采样数据块的部分。

I am currently using 2 classes, Sink and Source, to pop and push arrays of bytes. Everything goes well until I reach the part where I need to downsample the data chunk using a linear interpolation.

由于我是从44100下采样到8000赫兹,我怎么插含有类似128 000 000字节一个字节数组?现在我弹出取决于则i%2 == 0 5,6或7个字节,则i%2 == 1和则i%80 == 0和这些5,6或7个字节的平均推入新的文件。

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

结果确实比原来更小的音频文件,但它不能在Windows媒体播放器(说有在读取文件中的错误),并有一个很大的噪音,虽然我可以听到身后的正轨发挥噪音。

The result is indeed a smaller audio file than the original but it cannot be played on windows media player (says there is an error while reading the file) and there is a lot of noise although I can hear the right track behind the noise.

所以,总结的东西了,我需要有关线性插值部分帮助。先谢谢了。

So, to sum things up, I need help concerning the linear interpolation part. Thanks in advance.

推荐答案

我觉得你不应该使用这些样本的平均值作为这将是一个中值滤波,不完全下采样。只要使用每5/6/7样品,并编写新的文件。

I think you shouldn't use the average of those samples as that would be a median filter, not exactly downsampling. Just use every 5th/6th/7th sample and write that to the new file.

这将可能有一些锯齿,但可能总体可识别。

That will probably have some aliasing artifacts but might overall be recognizable.

另外一个更复杂的解决方案,但可能是一个用更好的成绩,质量的角度来看,将是第一个你的样品转换成使用FFT或DFT的频率分布,然后再转换回来用适当的采样率。它已经有一段时间,因为我曾经做过这样的事情,但它肯定是可行的。您可能需要反复折腾了一下得到它正常工作,虽然。

Another, more complex solution but probably one with better results, quality-wise, would be to first convert your samples into a frequency distribution using a FFT or DFT and then convert it back with the appropriate sample rate. It's been a while since I have done such a thing but it's definitely doable. You may need to fiddle around a bit to get it working properly, though.

也不采取FT在整个阵列的,而是在细分你有段边界是0,几年前,当我用这些东西打的问题,我没有拿出一个可行的解决方案,这(因为它产生的文物以及),但有可能是一个,如果你读了合适的书籍: - )

Also when not taking a FT of the complete array but rather in segments you have the problem of the segment boundaries being 0. A few years ago when I played with those things I didn't come up with a viable solution to this (since it generates artifacts as well) but there probably is one if you read the right books :-)

至于WMP抱怨文件:您的没有的修改您编写相应的标题,右

As for WMP complaining about the file: You did modify the header you write accordingly, right?

这篇关于爪哇 - 下采样WAV音频文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆