How avoid automatic gain control with AudioRecord?

前端 未结 4 929
我在风中等你
我在风中等你 2020-12-05 01:48

How can I do audio recordings using android.media.AudioRecord without any smartphone-manufacturer-dependent fancy signal processing like automatic gain control

4条回答
  •  情话喂你
    2020-12-05 01:56

    MIC should be fine, and for the rest you need to know if they are supported.

    I've made a class for this:

    enum class AudioSource(val audioSourceValue: Int, val minApi: Int) {
        VOICE_CALL(MediaRecorder.AudioSource.VOICE_CALL, 4), DEFAULT(MediaRecorder.AudioSource.DEFAULT, 1), MIC(MediaRecorder.AudioSource.MIC, 1),
        VOICE_COMMUNICATION(MediaRecorder.AudioSource.VOICE_COMMUNICATION, 11), CAMCORDER(MediaRecorder.AudioSource.CAMCORDER, 7),
        VOICE_RECOGNITION(MediaRecorder.AudioSource.VOICE_RECOGNITION, 7),
        VOICE_UPLINK(MediaRecorder.AudioSource.VOICE_UPLINK, 4), VOICE_DOWNLINK(MediaRecorder.AudioSource.VOICE_DOWNLINK, 4),
        @TargetApi(Build.VERSION_CODES.KITKAT)
        REMOTE_SUBMIX(MediaRecorder.AudioSource.REMOTE_SUBMIX, 19),
        @TargetApi(Build.VERSION_CODES.N)
        UNPROCESSED(MediaRecorder.AudioSource.UNPROCESSED, 24);
    
        fun isSupported(context: Context): Boolean =
                when {
                    Build.VERSION.SDK_INT < minApi -> false
                    this != UNPROCESSED -> true
                    else -> {
                        val audioManager: AudioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
                        Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && "true" == audioManager.getProperty(AudioManager.PROPERTY_SUPPORT_AUDIO_SOURCE_UNPROCESSED)
                    }
                }
    
        companion object {
            fun getAllSupportedValues(context: Context): ArrayList {
                val values = AudioSource.values()
                val result = ArrayList(values.size)
                for (value in values)
                    if (value.isSupported(context))
                        result.add(value)
                return result
            }
        }
    
    }
    

提交回复
热议问题