android downsample lower audio sampling frequency code

  • 2020-05-27 07:04:47
  • OfStack

Record PCM files using Android AudioRecord. android SDK guarantees that only 44100HZ sampling frequency is supported on all devices.
So if you want to get PCM data of other sampling frequencies, there are several ways:
1. Try the available sampling frequency on the device,
2. Change the sampling frequency after sampling with 44.1K.


There are many ways to change the sampling frequency. At present, I use SSRC and the effect is very good.


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 in the above code is the target sampling frequency.
SSRC website: http: / / shibatch sourceforge. net /
JSSRC: https: / / github com/hutm/JSSRC


Related articles: