3

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 input and STEREO mode.

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

My issue is that I get exactly the same data in both the channels. (alternate samples are separated to get individual channel inputs). Please help. I am not sure why this is happening.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
Neetha
  • 43
  • 1
  • 5
  • Don't almost 100% of devices have only a single microphone? I would expect you to need to plug in a special stereo mic to actually get stereo input. – Tenfour04 Dec 17 '13 at 13:03
  • My phone is a Nexus 4 and it has 2 microphones. In fact I am also adding permission in the manifest.xml file to allow stereo recording. – Neetha Dec 17 '13 at 13:24
  • @Tenfour04: It's fairly common for devices to have multiple mics. Although their primary motivation is noise cancellation, it's also possible to use them for multi-channel recording. Back when I worked in the Sony Mobile audio team nearly all the phones I worked on from 2011 and onward supported stereo recording. – Michael Dec 18 '13 at 10:37
  • @Michael Can you suggest a way to get over this issue? I rooted my Nexus 4 and even had changed /etc/media_profiles.xml making Maxchannels = 2 for AudioEncoderCap. But I see no improvement. Is it because I am using raw audio data without any form of compression? – Neetha Dec 22 '13 at 08:57
  • @Neetha: I have the same problem as you had before and asked this question for it. Did you find any solution for this problem in these month? could you record stereo with your galaxy at end? thanks – sandra Aug 30 '14 at 15:16
  • @Tenfour04 Almost all phone/tablet devices made early-2000s and beyond have 2+ mics, with some new Sony phones having 4. Many IBM and ASUS laptops almost come w/2 mics about 10cm apart. Typically, one is linked to the camcorder feature. – EntangledLoops May 03 '16 at 16:22

3 Answers3

3

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.

Yuntao Wang
  • 159
  • 1
  • 9
1

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 capturing, then this should work :)

Rokas
  • 11
  • 2
0

You cannot obtain a stereo input in this way on your device.

Although the Nexus 4 has two microphones, they are not intended for stereo recording, but instead are likely for background noise cancellation.

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

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
  • Hi Chris, As you suggested I followed the link and their suggestions. I rooted my phone and finally managed to edit the media_profiles.xml file to make Maxchannels = 2 for AudioEncoderCap. But still the problem of same data persists. I wonder if the issue is that I am bringing in raw audio data using AudioRecord class (using Eclipse SDK). There are no related compression standards or definitions in media_profiles.xml for this. Please let me know if you have any suggestions – Neetha Dec 22 '13 at 06:34