希望你能帮我解决这个问题: 获取音频流PCM16 16 kHz立体声,我尝试转换为ulaw 8kHz
我尝试阅读的部分:
readInfo.format = SF_FORMAT_PCM_16 | SF_FORMAT_RAW;
readInfo.channels = 2;
readInfo.samplerate = 16000;
readInfo.frames = 0;
// sprintf(myStr, "Read Info Check before: %i", sf_format_check (&readInfo));
// vplDebug(myStr);
writeInfo.format = SF_FORMAT_ULAW | SF_FORMAT_RAW;
writeInfo.channels = 1;
writeInfo.samplerate = 8000;
vio_data_in.length = size;
for (i = 0; i < size; i++) {
vio_data_in.data[i] = data[i];
}
/* Set up pointers to the locally defined functions. */
vio.get_filelen = vfget_filelen;
vio.seek = vfseek;
vio.read = vfread;
vio.write = vfwrite;
vio.tell = vftell;
if ((IN = sf_open_virtual(&vio, SFM_READ, &readInfo, &vio_data_in)) == NULL) {
sprintf(myStr, "sf_open_virtual In: Error");
vplDebug(myStr);
// exit (1) ;
};
sprintf(myStr, "Vget filelen is: %i", vfget_filelen(&vio_data_in));
vplDebug(myStr);
打开时我没有错误。然后我尝试打开另一个写入并转换:
if ((OUT = sf_open_virtual(&vio, SFM_READ, &writeInfo, &vio_data_out)) ==
NULL) {
sprintf(myStr, "sf_open_virtual OUT: Error");
vplDebug(myStr);
// exit (1) ;
};
short samples[2048];
for (;;) {
int items = sf_read_short(IN, samples, 2048);
sprintf(myStr, "Items: %i", items);
vplDebug(myStr);
if (items > 0) {
sf_write_short(OUT, samples, items);
} else {
break;
}
}
sprintf(myStr, "via Data out: %i", vio_data_out.data[1]);
vplDebug(myStr);
sf_close(IN);
sf_close(OUT);
稍后应该通过UDP发送vio_data_out
,但现在只是尝试让转换部分工作。但它不起作用,我想我可能误解了它的某些部分。
有什么建议吗?