converting pcm file to mp3 using liblame in android

巧了我就是萌 提交于 2019-11-29 11:17:19

I implemented a PCM to MP3 encoder just yesterday for my application using lame. I suggest not using SimpleLameLibForAndroid and instead adding lame to your project yourself. If you are using Android Studio, here is a good guide to get you started on that if you haven't done NDK before.

http://www.shaneenishry.com/blog/2014/08/17/ndk-with-android-studio/

As for implementing lame itself, below is a really good guide that I followed to get my application up and running. Use the wrapper.c from the .zip at the top of the page. This exposes useful methods so that you can avoid all the nasty Stream and Buffer stuff.

http://developer.samsung.com/technical-doc/view.do?v=T000000090

When all is said and done, the actual calls to the lame encoder are super simple as follows.

For initializing (use whatever settings you like):

public static final int NUM_CHANNELS = 1;
public static final int SAMPLE_RATE = 16000;
public static final int BITRATE = 64;
public static final int MODE = 1;
public static final int QUALITY = 7;
...

initEncoder(NUM_CHANNELS, SAMPLE_RATE, BITRATE, MODE, QUALITY);

For encoding (very easy):

int result = encodeFile(pcm.getPath(), mp3.getPath());
if (result == 0) {
    //success
}

And of course destroy the encoder when done with destroyEncoder().

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!