How to change the samples rates when do the format conversion by sox C libraries?

StackOverflow https://stackoverflow.com/questions/16806592

  •  30-05-2022
  •  | 
  •  

I am trying the format conversion between two audio files using the sox libraries. I can convert one to another with no parameters changing by the API provided by the library.Just like the process by executing the command: sox a.wav b.ul And now the question I encounter is how to change the samples rates while converting the audio files. Please give me a hand! Thanks!

有帮助吗?

解决方案

The rate effect is used for resampling. See src/example3.c in the SoX git repository for an example how to use it with the library API. (You should make sure to use the example3.c from current git, because the version in recent releases is buggy.)

其他提示

Thanks very well. After reading the examples3.c and some testing, I find the way to solve my problem. To change the samples rates when conversion, just add two steps in your conversion codes:

......
out->signal.channels = 1    //change the channel of outfile to 1
......
//add the effect of "rate", which means samples rates
e = sox_create_effect(sox_find_effect("rate"));
args[0] = "8000", assert(sox_effect_options(e, 1, args) == SOX_SUCCESS);
assert(sox_add_effect(chain, e, &in->signal, &out->signal) == SOX_SUCCESS);
free(e);
......

I change the samples rates successfully by this way. And so is changing the channel. Hope it can help others. Thanks chirlu again~

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top