AudioRecorder getminbuffersize并不总是返回相同的值

时间:2013-12-13 08:59:21

标签: android audio

我正在开发一个Android应用程序来处理音频。要了解设备支持的可能配置,我会在本论坛中看到手动算法。具体而言:

for (int rate : mSampleRates) {
            for (short audioFormat : aformats) {
                for (short channelConfig : chConfigs) {
                    try {
                        Log.d("Log:", "Attempting rate " + rate + "Hz, bits: "
                                + audioFormat + ", channel: " + channelConfig);
                        int bufferSize = AudioRecord.getMinBufferSize(rate,
                                channelConfig, audioFormat);

                        if (bufferSize > 0) {

                            AudioRecord recorder2 = new AudioRecord(
                                    MediaRecorder.AudioSource.MIC, rate,
                                    channelConfig, audioFormat,
                                    java.lang.Math.max(bufferSize, 1024 * 800));

                            if (recorder2.getState() == AudioRecord.STATE_INITIALIZED) {
                                auxicapture = new StructCapture();
                                auxicapture.setfrequency(rate);
                                auxicapture.setencoding(audioFormat);
                                auxicapture.setchannel(channelConfig);
                                captureoptions.add(aux, auxicapture);

                                aux++;
                                recorder2.release();

                            }

                        }
                    } catch (Exception e) {
                        Log.e("Log:", rate + "Exception, keep trying.", e);
                    }
                }
            }
        }

但每次我使用这个算法都会返回不同的值,有时程序会产生错误。 所以我的问题是,你知道其他检查方法。

感谢

0 个答案:

没有答案
相关问题