Audio recording in stereo with the same data in the left and right channels

I am trying to record and process audio data based on the differences in what is written to the left and right channels. For this I use the Audio Record class, with MIC as input and STEREO mode.

recorder = new AudioRecord(MediaRecorder.AudioSource.MIC, sampleRate,
                                    AudioFormat.CHANNEL_IN_STEREO,
                                    AudioFormat.ENCODING_PCM_16BIT, bufferSize);

      

My problem is that I am getting exactly the same data in both channels. (alternative samples are split to get separate input channels). Please help. I'm not sure why this is happening.

+2


source to share


3 answers


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 audio data looks like this.

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

      



So, you need to split 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 it helps.

+1


source


Here is a working example for capturing audio in stereo (tested with Samsung Galaxy S3 4.4.2 SlimKat):

private void startRecording() {
    String filename = Environment.getExternalStorageDirectory().getPath()+"/SoundRecords/"+System.currentTimeMillis()+".aac";
    File record = new File(filename);
    recorder = new MediaRecorder();
    recorder.setAudioSource(MediaRecorder.AudioSource.CAMCORDER);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    recorder.setAudioEncodingBitRate(128000);
    recorder.setAudioSamplingRate(96000);
    recorder.setAudioChannels(2);
    recorder.setOutputFile(filename);
    t_filename.setText(record.getName());
    try {
        recorder.prepare();
        recorder.start();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

      



If your phone supports stereo capture then this should work :)

+1


source


You cannot get stereo input this way on your device.

While the Nexus 4 has two microphones, they are not intended for stereo recording, but background noise will likely be canceled instead.

See https://groups.google.com/forum/#!topic/android-platform/SptXI964eEI where various low-level audio system modifications are discussed in an attempt to perform stereo recording.

0


source







All Articles