resample / upsample sound frames from 8Khz to 48Khz (Java/Android)

后端 未结 4 2076
被撕碎了的回忆
被撕碎了的回忆 2021-01-18 15:30

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

4条回答
  •  说谎
    说谎 (楼主)
    2021-01-18 16:14

    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:

    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

    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.

    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

提交回复
热议问题