Implement getMaxAmplitude for audioRecord

前端 未结 3 1228
借酒劲吻你
借酒劲吻你 2021-02-08 03:11

I am using audioRecord instead of mediarecorder in my app it\'s working fine but I have a logic that depends highly on the maxamplitude which is really hard to obtain using the

3条回答
  •  野的像风
    2021-02-08 03:47

    If your encoding is ENCODING_PCM_16BIT , Then you should use

    private int cAmplitude= 0;
    
    while(isRecording) {
        read = recorder.read(data, 0, bufferSize);
    
        for (int i=0; i cAmplitude) {
                cAmplitude = curSample;
            }
        }
    
        Log.d("amplitude",Integer.toString(cAmplitude));
        cAmplitude = 0;
    }
    
    private short getShort(byte argB1, byte argB2) {
        return (short)(argB1 | (argB2 << 8));
    }
    

    For more info, have a look at How to record voice in "wav" format in Android

提交回复
热议问题