0

I want to split a Multichannel (2,8 or 16) wav file into its channels and save every channel in another wav-File.

So far I've accomplished to get libsox up and running in my c++, objective c++ project.

Libsox isnt well documented and there aren many examples on how to do it :(

I started by first openning the Inputfile

sox_format_t * in, * out;
assert(sox_init() == SOX_SUCCESS);
assert(in = sox_open_read((const char*)filename.c_str(),NULL,NULL,NULL));

Now I must find a way to get the number of channels of this file. Then I have to create the same amount of out-files and save every channel itself inside them.

How to do?

Thanks!

hmrc87
  • 352
  • 1
  • 4
  • 12
  • You might consider libsndfile instead. – Bjorn Roche Sep 10 '12 at 02:09
  • Thanks for the advice, but I just read, that libsndfile can't do that. Q5 : Why doesn't libsndfile do interleaving/de-interleaving? This problem is bigger than it may seem at first. For a stereo file, it is a pretty safe bet that a simple interleaving/de-interleaving could satisfy most users. However, for files with more than 2 channels this is unlikely to be the case. If the user has a 4 channel file and want to play that file on a stereo output sound card they either want the first 2 channels or they want some mixed combination of the 4 channels. – hmrc87 Sep 10 '12 at 08:31
  • With regards to documentation, the examples in the [git repository](http://sox.git.sourceforge.net/git/gitweb.cgi?p=sox/sox;a=tree) might be helpful, they are in `src/example*c`. There's also [libsox(3)](http://sox.sourceforge.net/libsox.html) although it is a bit sparse. – Thor Sep 10 '12 at 10:30
  • @MalawiM It seems like that FAQ entry isn't really referring to inderleaving/deinterleaving, but really downmixing. It's very easy to pick channel n out of m channels from libsndfile data the same way you describe in your answer. – Bjorn Roche Sep 10 '12 at 14:07

1 Answers1

0

I think I will do it the old fashioned way.

  • Determine the channel count of the file.
  • Determine the length of the Data block.

    Length of Data block / channelCount = Size of each channelBlock
    
  • Channels are saved like that inside a WavFile-Datablock (for 4Channel WavFile) CH1/Ch2/Ch3/Ch4 CH1/Ch2/Ch3/Ch4.

  • I run through the datablock extract the channels and put them into a mono-wav-file
Julius Vainora
  • 47,421
  • 9
  • 90
  • 102
hmrc87
  • 352
  • 1
  • 4
  • 12