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!
Asked
Active
Viewed 1,304 times
2 Answers
0
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.)

chirlu
- 3,141
- 2
- 21
- 22
-
Thanks for your reply~ I will have a try. Be excited I get the first answer of my first question in StackOverFlow. Haha~~~ BTW, I am a Chinese, pls forgive my bad English~ – gold_luck May 30 '13 at 07:27
0
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~

gold_luck
- 49
- 8