SoFunction
Updated on 2025-03-11

Android downsample code to reduce audio sampling frequency

Using Android AudioRecord to record PCM files, and the Android SDK ensures that the sampling frequency supported on all devices is only 44100HZ.
So if you want to get PCM data of other sampling frequencies, there are several ways:
1. Try available sampling frequency on the device,
2. Use 44.1K sampling to convert the sampling frequency.


There are many ways to convert the sampling frequency. Currently I am using SSRC and it works very well.

Copy the codeThe code is as follows:

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) {
            ();
        } catch (IOException e) {
            ();
        }
    }

8000 in the above code is the target sampling frequency.
SSRC official website:/
JSSRC:/hutm/JSSRC