android - 为什么 AudioRecord.getMinBufferSize 会返回 ERROR_BAD_VALUE (-2)?

标签 android audio-recording

我正在三星 Galaxy S i9000 上对此进行测试。

int sampleRate = 44100;
int bufferSize = AudioRecord.getMinBufferSize(sampleRate, 
    AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_8BIT);

它返回 -2 ERROR_BAD_VALUE

native 采样率为 44100Hz,由

返回

AudioTrack.getNativeOutputSampleRate(AudioManager.STREAM_SYSTEM).

我尝试将采样率设置为 1000、8000、22100 和 44100。我还尝试将 AudioFormat.CHANNEL_IN_MONO 更改为 AudioFormat.CHANNEL_CONFIGURATION_MONO。我也尝试过 STEREO(IN_STEREOCONFIGURATION_STEREO)。我也尝试过 16 位编码而不是 8 位编码。

更新:我的 list 有AUDIO_RECORD权限。

结果我一直得到-2。为什么会这样?

最佳答案

来自平台源文件AudioRecord.java :

static public int getMinBufferSize(int sampleRateInHz, int channelConfig, int audioFormat) {
    ...
    // PCM_8BIT is not supported at the moment
    if (audioFormat != AudioFormat.ENCODING_PCM_16BIT) {
        loge("getMinBufferSize(): Invalid audio format.");
        return AudioRecord.ERROR_BAD_VALUE;
    }
    ...
}

看起来您的选择是 16 位或什么都没有。 :\

关于android - 为什么 AudioRecord.getMinBufferSize 会返回 ERROR_BAD_VALUE (-2)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4781781/

相关文章:

android - 如何为 android native 应用程序生成调试符号?

android - postDelayed 后 View 不能为 null

c++ - C++录音

android - Microsoft Azure DevOps Pipeline 失败,Gradle Android 中出现连接重置错误

android - SimpleDateFormat 在不同的平板电脑上表现不同

使用音频记录 api 的 Android 录音应用程序

windows - 如何从应用程序中捕获发送到扬声器的音频数据?

javascript - 如何在Wordpress中使用RecordJs

python - 请解释为什么我们在音频信号中使用 32768

java - ARcore - 在不使用 TransformableNode 的情况下无法旋转模型