Android AudioRecord Supported Sampling Rates

前端 未结 8 693
悲&欢浪女
悲&欢浪女 2020-11-28 22:47

I\'m trying to figure out what sampling rates are supported for phones running Android 2.2 and greater. We\'d like to sample at a rate lower than 44.1kHz and not have to re

8条回答
  •  野性不改
    2020-11-28 23:23

        public  class Bigestnumber extends AsyncTask{
            ProgressDialog pdLoading = new ProgressDialog(MainActivity.this);
    
            @Override
            protected String doInBackground(String... params) {
                final int validSampleRates[] = new int[]{
                        5644800, 2822400, 352800, 192000, 176400, 96000,
                        88200, 50400, 50000, 48000,47250, 44100, 44056, 37800, 32000, 22050, 16000, 11025, 4800, 8000};
                TrueMan = new ArrayList  ();
                for (int smaple : validSampleRates){
                    if(validSampleRate(smaple) == true) {
                        TrueMan.add(smaple);
                    }}
    
    
                return null;
            }
            @Override
            protected void onPostExecute(String result) {
    
                Integer largest = Collections.max(TrueMan);
                System.out.println("Largest   " + String.valueOf(largest));
    
    
    
            }
    
        }
    
       public boolean validSampleRate(int sample_rate) {
            AudioRecord recorder = null;
            try {
                int bufferSize = AudioRecord.getMinBufferSize(sample_rate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT);
                recorder = new AudioRecord(MediaRecorder.AudioSource.MIC, sample_rate, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT, bufferSize);
            } catch(IllegalArgumentException e) {
                return false;
            } finally {
                if(recorder != null)
                    recorder.release();
            }
            return true;
        }
    

    This Code will give you Max Supported Sample Rate on your Android OS. Just Declare ArrayList TrueMan; in your beggining of the class. Then you can use high sample rate in AudioTrack and AudioRecord to get better sound quality. Reference.

提交回复
热议问题