0

I am using audacity to play back the raw stereo 16-bit linear PCM (dumped in Android HAL) which is the output of Android audio flinger. Total buffer is 960 bytes. enter image description here What is the right way of converting stereo to individual mono channels (left and right channel in individual buffers) from the audio_flinger_buf (given by audioflinger)? My library needs separated out left and right channel as input.

I have below code which i thought will do aforementioned:

  channels = 2
  for (i=0;i<channels;i++) {
      int j;
      for (j=0;j<240;j++) {
          seperate_buf[240*i+j] = ((int16_t *)audio_flinger_buf)[j*DSM_CHANNELS+i];
      }
  }

so seperate_buf[0..239] will have left sample and seperate_buf[240...479] will have right sample.

seperate_buf[0...239] is shown below: enter image description here seperate_buf[240....479] is shown below: enter image description here Why do i see stereo output here in both the above buffers?

Is my code correct for separating out left and right from a stereo buffer? I see that the audacity also does something similar (https://goo.gl/GZh7fg).

10
  • What is the format you're saving your separated data in? If it's raw PCM, are you importing the new file as mono? If it's WAV or something similar, what are you putting in the header? – Michael Jul 20 '15 at 7:55
  • @Michael: I am importing the new file as stereo. I think audacity basically creates the stereo from my mono data, am I right? – newbie_old Jul 20 '15 at 14:52
  • What's the length of the separated audio after you import it? Is it the expected length, or half the expected length? – Michael Jul 20 '15 at 15:07
  • @Michael: I am importing all the 240 bytes which I think is left buffer as shown in the diagram.As I am dumping 240 bytes I am importing that much. – newbie_old Jul 20 '15 at 15:11
  • I mean the length in seconds as displayed by Audacity. – Michael Jul 20 '15 at 15:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.