Audio Recording in Stereo giving same data in Left and Right channels

前端 未结 3 614
一个人的身影
一个人的身影 2021-01-03 09:57

I am trying to record and process audio data based on differences in what gets recorded in the left and right channel. For this I am using Audio Record class, with MIC as in

3条回答
  •  迷失自我
    2021-01-03 10:19

    Using this configuration:

    private int audioSource = MediaRecorder.AudioSource.MIC;  
    private static int sampleRateInHz = 48000;  
    private static int channelConfig = AudioFormat.CHANNEL_IN_STEREO;  
    private static int audioFormat = AudioFormat.ENCODING_PCM_16BIT;  
    

    The data in the audio data is as follows.

    leftChannel data: [0,1],[4,5]...
    rightChannel data: [2,3],[6,7]...
    

    So you need to seperate the data.

    readSize = audioRecord.read(audioShortData, 0, bufferSizeInBytes);
    for(int i = 0; i < readSize/2; i = i + 2)
    {
           leftChannelAudioData[i] = audiodata[2*i];
           leftChannelAudioData[i+1] = audiodata[2*i+1]; 
           rightChannelAudioData[i] =  audiodata[2*i+2];
           rightChannelAudioData[i+1] = audiodata[2*i+3];
    }
    

    Hope this helpful.

提交回复
热议问题