本文介绍了从8kHz的重采样/上采样声音帧至48kHz(Java / Android的)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我想开发Andriod的应用程序,记录以48kHz帧(PCM 16位和放大器;单声道),并将它们发送到网络上。另外,有声频的在8kHz传入流。所以,我收到的8kHz采样的框架和发挥他们(我的AudioTrack对象设置为8kHz的),但打他们的时候,一切正常,但延迟是巨大的。它需要像约3秒钟,直到你听到的东西。

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.

我想,如果我上采样为8kHz接收帧至48kHz和发挥他们,也不会有如此巨大的播放延迟。事实上,当我记录和以相同的速率播放的帧,等待时间是非常低。坏的事情是,我不得不做这种方式:发送至48kHz和接收到8KHZ

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.

如前所述,我想上采样声音帧(16位PCM)8kHz至48kHz。有谁知道,这是否所有程序/库/ API在Java中???

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

我知道上采样一个谨慎的信号的基础知识,但我认为,设计和实施自己的FIR滤波器和音频流回旋吧....是太多。此外,它是在我的知识。

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.

所以...没有任何人能帮助我?有谁知道任何库/例程在Java中,我可以使用?任何建议或替代方案?

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

推荐答案

一个快速和肮脏的解决方案是线性插值。因为你总是用6倍采样起来,这是很容易做到:

A quick and dirty solution would be linear interpolation. Since you're always sampling up by a factor of six this is really easy to do:

它的工作原理有点像这样(C-code和未经考验的,我不处理的最后一次迭代正常,但它给出了这个概念,我认为)。

It works somewhat like this (C-code, and untested, and I don't handle the last iteration properly, but it shows the idea I think).

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;
  }

直线插补不会给你带来很大的音质,但它是便宜又快捷。如果你想,你可以改善这种使用三次插值。

Linear interpolation won't give you great sound quality but it is cheap and fast. You can improve this using cubic interpolation if you want to.

如果你想要一个快速和高品质的重采样我建议你编译交流采样库就像libresample使用Android的NDK和使用JNI从Java调用它。这将是快了很多。编写JNI code是大多数人回避,但它是很容易的。该NDK有很多例子这一点。

If you want a fast and high quality resampling I suggest that you compile a c resampling library like libresample using the Android-NDK and call it from java using JNI. That will be a lot faster. Writing the JNI code is something most people shy away from, but it's quite easy.. The NDK has lots of examples for this.

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

这篇关于从8kHz的重采样/上采样声音帧至48kHz(Java / Android的)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 01:21