我是LibSoX库的新手。我想使用LibSoX将PCM签名的16bit 8000hz音频文件上采样为PCM签名的16bit 16000Hz音频。
我从libSoX源代码的example3
开始,进行了一些修改,以指定音频编码,速率,...和其他参数。
但是,在输出文件中,我只有杂音。我相信libSoX可以进行高质量的升采样,我可以使用CLI进行。
这是我的代码段:
``
int main(int argc, char * argv[])
{
static sox_format_t * in, * out; /* input and output files */
sox_effects_chain_t * chain;
sox_effect_t * e;
char * args[10];
assert(argc == 3);
assert(sox_init() == SOX_SUCCESS);
sox_signalinfo_t in_signal_info;
in_signal_info.channels = 1;
in_signal_info.precision = 16;
in_signal_info.rate = 8000;
sox_encodinginfo_t in_encoding_info;
in_encoding_info.encoding = SOX_ENCODING_SIGN2;
in_encoding_info.bits_per_sample = 16;
in_encoding_info.opposite_endian = 0;
assert(in = sox_open_read(argv[1], &in_signal_info, &in_encoding_info, NULL));
assert(out = sox_open_write(argv[2], &in->signal, NULL, NULL, NULL, NULL));
chain = sox_create_effects_chain(&in->encoding, &out->encoding);
e = sox_create_effect(sox_find_effect("input"));
args[0] = (char *)in, assert(sox_effect_options(e, 1, args) == SOX_SUCCESS);
assert(sox_add_effect(chain, e, &in->signal, &in->signal) == SOX_SUCCESS);
free(e);
out->signal.rate = 16000;
in->signal.rate = 8000;
in->signal.channels =1;
in->signal.length = SOX_UNSPEC;
out->signal.channels =1;
out->encoding.bits_per_sample = 16;
out->encoding.encoding =SOX_ENCODING_SIGN2;
out->signal.length = SOX_UNSPEC;
if (in->signal.rate != out->signal.rate) {
e = sox_create_effect(sox_find_effect("rate"));
args[0] = "8000", assert(sox_effect_options(e, 1, args) == SOX_SUCCESS);
//e->handler.flags |= SOX_EFF_LENGTH;
assert(sox_add_effect(chain, e, &in->signal, &out->signal) == SOX_SUCCESS);
free(e);
}
if (in->signal.channels != out->signal.channels) {
e = sox_create_effect(sox_find_effect("channels"));
assert(sox_effect_options(e, 0, NULL) == SOX_SUCCESS);
assert(sox_add_effect(chain, e, &in->signal, &out->signal) == SOX_SUCCESS);
free(e);
}
e = sox_create_effect(sox_find_effect("output"));
args[0] = (char *)out, assert(sox_effect_options(e, 1, args) == SOX_SUCCESS);
assert(sox_add_effect(chain, e, &in->signal, &out->signal) == SOX_SUCCESS);
free(e);
sox_flow_effects(chain, NULL, NULL);
sox_delete_effects_chain(chain);
sox_close(out);
sox_close(in);
sox_quit();
return 0;
} `` 有人已经遇到了同样的问题吗? 预先感谢。
-Ayb