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).

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
newbie_old
  • 500
  • 5
  • 19
  • 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 07: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
  • @Michael: 10.313 s is what i can see. – newbie_old Jul 20 '15 at 15:16
  • And is that the expected length? What was the length of the original non-separated audio clip? – Michael Jul 20 '15 at 15:17
  • @Michael: no that is weird.Separated out buffer should have half no? I am just dumping 240 bytes separated buffers but i see it is same as full stereo buffer i.e. 10.313 s. – newbie_old Jul 20 '15 at 15:22
  • @Michael: file size of the left and right separated out buffer is 892kb and stereo is 1.73MB. – newbie_old Jul 20 '15 at 15:25
  • @Michael: got it. Basically the audioflinger output is 1.73MB which is double of left (892*2) and that is why it is playing almost same time but stereo is playing 2 samples at a time. – newbie_old Jul 20 '15 at 18:38

0 Answers0