I'm new to libsox programming, and I want to reduce a chennel from a stereo audio which named 'a.wav' then generate a mono audio 'b.wav' with the following code:
sox_format_t * in, * out;
sox_effects_chain_t * chain;
sox_effect_t * e;
char * args[10];
sox_init();
in = sox_open_read("E:\\a.wav", NULL, NULL, NULL);
out = sox_open_write("E:\\b.wav", &in->signal, NULL, NULL, NULL, NULL);
out->signal.channels = 1;
chain = sox_create_effects_chain(&in->encoding, &out->encoding);
e = sox_create_effect(sox_find_effect("input"));
sox_add_effect(chain, e, &in->signal, &in->signal);
e = sox_create_effect(sox_find_effect("channels"));
sox_add_effect(chain, e, &in->signal, &out->signal);
e = sox_create_effect(sox_find_effect("output"));
sox_add_effect(chain, e, &in->signal, &out->signal);
sox_flow_effects(chain, NULL, NULL);
sox_delete_effects_chain(chain);
sox_close(out);
sox_close(in);
sox_format_quit();
After running the application, the mono audio 'b.wav' was generated, but the duration of the sound was half of the a.wav. Is there something wrong with my code?
Any reply will be appreciated!