5

The application that I am trying to develop for andriod, records frames at 48Khz (PCM 16bits & mono) and sends them to the network. Also, there is an incoming stream of audio at 8Khz. So, I receive 8Khz sampled frames and play them (my AudioTrack object is set to 8Khz), but when playing them, everything works but the latency is HUGE. It takes like around 3 seconds until you hear something.

I think that if I upsample the received frames from 8Khz to 48Khz and play them, there won't be such a huge playing latency. In fact when I record and play frames at the same rate, the latency is really low. The bad thing is that I am forced to do it this way: send to 48Khz and receive to 8Khz.

As explained before, I'm trying to upsample a sound frame (16bits PCM) from 8Khz to 48Khz. Does anybody know any routine/library/API in Java that does this???

I know the basics about upsampling a discreet signal, but I consider that to design and implement my own FIR filter and convolute it with the audio stream ....is way too much. Also, it is over my knowledge.

So...does anybody can help me with this?? Does anybody know any library/routine in Java that I can use?? Any suggestions or alternatives??

4

4 回答 4

5

一个快速而肮脏的解决方案是线性插值。由于您总是以六倍的倍数进行采样,因此这很容易做到:

它的工作方式有点像这样(C 代码,未经测试,我没有正确处理最后一次迭代,但它显示了我认为的想法)。

void resample (short * output, short * input, int n)
{
  // output ought to be 6 times as large as input (48000/8000).

  int i;
  for (i=0; i<n-1; i++)
  {
    output[i*6+0] = input[i]*6/6 + input[i+1]*0/6;
    output[i*6+1] = input[i]*5/6 + input[i+1]*1/6;
    output[i*6+2] = input[i]*4/6 + input[i+1]*2/6;
    output[i*6+3] = input[i]*3/6 + input[i+1]*3/6;
    output[i*6+4] = input[i]*2/6 + input[i+1]*4/6;
    output[i*6+5] = input[i]*1/6 + input[i+1]*5/6;
  }

线性插值不会为您提供出色的音质,但它既便宜又快速。如果您愿意,可以使用三次插值来改进这一点。

如果您想要快速和高质量的重采样,我建议您使用 Android-NDK 编译像 libresample 这样的 ac 重采样库,并使用 JNI 从 java 调用它。那会快很多。编写 JNI 代码是大多数人回避的事情,但这很容易。NDK 有很多这方面的示例。

http://www.mega-nerd.com/SRC/index.html

于 2010-07-15T23:02:23.347 回答
2

线性插值引入了伪影。有一个很好的带有高质量重采样的 java 库 - JSSRC ( http://jssrc.khadkevich.org/ )。

代码现已在 Github 上提供: https ://github.com/hutm/JSSRC

于 2013-02-28T15:33:24.297 回答
0

TarsosDPS 库对我的需求来说太重了,但我发现重采样工具最初是作为更轻的 3 类库发布的:https ://github.com/dnault/libresample4j

至于 TarsosDPS 不需要 javax

于 2020-02-03T18:41:42.240 回答
0

我无法让大多数图书馆工作(https://github.com/hutm/JSSRChttps://github.com/simingweng/android-pcm-resamplehttps://github.com/ashqal/android-libresample)。他们在生成的音频中都有问题,或者只是未能从 48000Hz 转换为 44100Hz(这就是我所需要的)。

这个虽然完美: https ://github.com/JorenSix/TarsosDSP

这是一个在 Android 上工作的大型纯 Java 库(没有 javax.sound 依赖项),它可以做很多事情,但是如果你只使用包 be.tarsos.dsp.resample 中的 FilterKit、Resampler 和 SampelBuffers 类,它就可以工作非常好,易于使用。

于 2019-06-13T13:08:48.683 回答