tags:

views:

553

answers:

2
+1  Q: 

libsox help

EDIT: i want to use libsox to programatically convert a wav file's sample rate, audio format, channels, and etc.

in the libsox man page, there are a bunch of functions I can use but I'm clueless as hell on what to do. Can anyone give me a sort of steps on how to do it?

Help?


Can anyone please explain this?

   The  function  sox_write  writes  len samples from buf using the format
   handler specified by ft. Data in buf must be 32-bit signed samples  and
   will  be converted during the write process. The value of len is speci-
   fied in total samples. If its value is not evenly divisable by the num-
   ber of channels, undefined behavior will occur.
A: 

Well, I guess your question has something to do with the last sentence. If you have an interleaved buffer, the number of samples in the buffer has to be divisable by the number of channels, because this is the number of per-channel samples you will write. For example, let's say you have L and R channels; your data will be like this on the buffer:

[0] 1st sample - L
[1] 1st sample - R
[2] 2nd sample - L
[3] 2nd sample - R
...
[n-1] n/2-th sample - L
[n] n-th sample - R

Hope it helps.

jfsantos
how can you determine the len samples?
for example, if you have audio with 2 channels with 44100 Hz of sampling rate, you will have 44100 samples per second per channel. In this case, for every second of audio you will have 88200 samples.
jfsantos
A: 

I'd recommend a combination of libsndfile and libsamplerate

http://www.mega-nerd.com/SRC

SRC provides a small set of converters to allow quality to be traded off against computation cost. The current best converter provides a signal-to-noise ratio of 145dB with -3dB passband extending from DC to 96% of the theoretical best bandwidth for a given pair of input and output sample rates.

http://www.mega-nerd.com/libsndfile/

  • Ability to read and write a large number of file formats.
  • A simple, elegant and easy to use Applications Programming Interface.
  • Usable on Unix, Win32, MacOS and others.
  • On the fly format conversion, including endian-ness swapping, type conversion and bitwidth scaling.
  • Optional normalisation when reading floating point data from files containing integer data.
  • Ability to open files in read/write mode.
  • The ability to write the file header without closing the file (only on files open for write or read/write).
  • Ability to query the library about all supported formats and retrieve text strings describing each format.
James Morris