Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import android.media.AudioRecord;

public class Main {
    /**
     * Get a valid sample rate for the device
     *
     * @param channelConfiguration
     *     the channel configuration
     * @param audioEncoding
     *     the audio encoding
     * @return the valid sample rates
     */
    public static int getValidSampleRates(int channelConfiguration, int audioEncoding) {
        for (int rate : new int[] { 8000, 11025, 16000, 22050, 44100, 48000 }) { // add the rates you wish to check against
            int bufferSize = AudioRecord.getMinBufferSize(rate, channelConfiguration, audioEncoding);
            if (bufferSize > 0) {
                return rate;
            }
        }
        return 0;
    }
}