Downsampling pcm/wav audio from 22khz to 8khz

这一生的挚爱 提交于 2019-12-11 18:26:51

问题


My android application needs to convert PCM(22khz) to AMR , but the API AmrInputStream only supports with pcm of 8khz.

How can i downsample the pcm from 22 khz to 8 khz?


回答1:


The sample rate is hard coded in AmrInputStream.java.

// frame is 20 msec at 8.000 khz
private final static int SAMPLES_PER_FRAME = 8000 * 20 / 1000;

So you have to convert the PCM to AMR first.

InputStream inStream;
inStream = new FileInputStream(wavFilename);
AmrInputStream aStream = new AmrInputStream(inStream);

File file = new File(amrFilename);        
file.createNewFile();
OutputStream out = new FileOutputStream(file); 

//adding tag #!AMR\n
out.write(0x23);
out.write(0x21);
out.write(0x41);
out.write(0x4D);
out.write(0x52);
out.write(0x0A);    

byte[] x = new byte[1024];
int len;
while ((len=aStream.read(x)) > 0) {
    out.write(x,0,len);
}

out.close();

For Downsampling, You can try the Mary API.




回答2:


I find a java downsample lib :https://github.com/hutm/JSSRC there is also a c version could be used by jni



来源:https://stackoverflow.com/questions/14929478/downsampling-pcm-wav-audio-from-22khz-to-8khz

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