当前位置: 移动技术网 > IT编程>移动开发>Android > android downsample降低音频采样频率代码

android downsample降低音频采样频率代码

2019年07月24日  | 移动技术网IT编程  | 我要评论

无忧中文,高贵的夫妇,甜心宝贝误闯吸血鬼美男团

使用android audiorecord 录制pcm文件,android sdk保证在所有设备上都支持的采样频率只有44100hz,
所以如果想得到其他采样频率的pcm数据,有几种方式:
1.在设备上尝试可用的采样频率,
2.使用44.1k采样后转换采样频率。


其中第二种转换采样频率的操作,有很多种方法。目前我使用的是ssrc,效果很好。

复制代码 代码如下:

private void simpledownsample() {
        file beforedownsamplefile = new file(rawrecordfilepath);
        file downsampled = new file(downsampledfilepath);
        try {
            fileinputstream fileinputstream = new fileinputstream(beforedownsamplefile);
            fileoutputstream fileoutputstream = new fileoutputstream(downsampled);
            new ssrc(fileinputstream, fileoutputstream, 44100, 8000,
                    2,
                    2,
                    1, integer.max_value, 0, 0, true);
        } catch (filenotfoundexception e) {
            e.printstacktrace();
        } catch (ioexception e) {
            e.printstacktrace();
        }
    }

上述代码中的8000是目标采样频率。
ssrc官网:http://shibatch.sourceforge.net/
jssrc:https://github.com/hutm/jssrc

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网