Downsampling pcm / wav audio 22 kHz to 8 kHz

My Android application should convert PCM (22 kHz) to AMR, but the AmrInputStream API only supports pcm from 8 kHz .

How can I downsample pcm from 22 kHz to 8 kHz?

0
source share
2 answers

The sampling rate is hardcoded in AmrInputStream.java.

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

So, first you need to convert PCM to AMR.

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 .

+1
source

I find java downsample lib: https://github.com/hutm/JSSRC there is also a version of c that jni can use

0
source

All Articles