2

I have a stereo audio file for which I try to separate the audio channels. Resulting in a bus with the left audio, and a bus with the right audio signal. On these channels I want to do some operations and then merge them again to a single stereo signal.

Reading the audio file, doing operations on the bus and merging it to a single signal is no problem (though I haven't tested if this signal is stereo, as it depends on the prior channels I guess).

My problem is in separating the left and the right channel, so I can independently modify them.

One of my ideas was to use the panproperty of AVAudioPlayerNode to have the signal only left/right, but it seems like (as mentioned in the documentation) this property is not yet implemented in the AVAudioPlayerNode (Even though in all the examples of the WWDC videos it is used).

Another solution I found was this. Using memcpy to create new buffers. I haven't tried this yet as I guess this takes quite some time and is not suitable for a normal player.

Third there is a framework called audiokit. This provides the option of converting the stream to mono left/right channel and then merging the signal again by creating an AKStereoOperation. My problem with this solution is, it is quite a simple use-case. Separating the audio channels. For this I find it hard to justify including such a huge framework, even though it would probably work (not tested).

Is there a simple way to separate the channels?

Thanks!

Community
  • 1
  • 1
Jan
  • 1,827
  • 2
  • 16
  • 29

1 Answers1

0

You can take the raw samples and create an AudioConverter using AudioConverterNew with and output AudioStreamBasicDescription configured to de-interleave the stereo channels. This will result in one buffer with one channel contiguously first and the second channel in the second half of the buffer.

Tim
  • 4,560
  • 2
  • 40
  • 64
  • can we still use AudioConverter if we aren't trying to change the file format? In my case, I'm trying to combine 2 mono CAF files with same sample rate and length into a single stereo file. Is there sample code for AudioConverterNew that shows you how to set the formatting? – A21 Feb 14 '17 at 21:34
  • Yes. The `AudioConverter` documentation lists the conversions that it supports. I believe there is an Apple sample showing how to use it, but I don't have a link handy. – Tim Feb 15 '17 at 00:43
  • I'm looking at the documentation for AudioConverterNew here https://developer.apple.com/reference/audiotoolbox/1502936-audioconverternew?language=objc. There are 3 parameters for this function however the inSourceFormat seems to suggest that it is only taking in a singular source file. However, in my case, I have 2 separate audio files with unique mono streams. I'm clearly missing something here unfortunately there's not a whole lot of documentation on the Apple site. – A21 Feb 15 '17 at 04:14
  • `AudioConverter` does not work on files. It works on buffers of data. Those buffers may come from files, it is up to you to provide them. – Tim Feb 15 '17 at 04:43
  • Sounds good, I guess the approach now is to figure out how to take my input files and extract the buffers and then non-interleave them into a single output buffer. When I work with these input buffers, do I need to be concerned about headers? – A21 Feb 15 '17 at 13:40
  • @A21 Did you ever find out how to do this? – Leonhard Printz Aug 17 '18 at 14:47