Look, how about you start from the testresample.c file? Oh, and you seem to be reading 320 samples at a time and processing 640, so that can't be good (and even beyond that your code is wrong for other reasons). Jean-Marc On 11/6/19 1:56 AM, zhouyuchen at iauto.com wrote:> Hello, > I printed the log, in/out len is not truncated, which means that the > input and output are not truncated, > but the sound quality is very bad, what would be the cause? > I tried to call speex_resampler_reset_mem before each sample, but the > effect is not as good as usual. > > int main() > { > int err; > SpeexResamplerState *speex_resampler; > speex_resampler = speex_resampler_init(1, 16000, 48000, 10, &err); > FILE *fp = fopen("/data/zhou.wav", "rb+"); > FILE *fp2 = fopen("/data/zhou2.wav", "ab+"); > spx_int16_t inbuff[640] = {0}; > spx_int16_t outbuff[1920] = {0}; > spx_uint32_t inlen = 640; > spx_uint32_t outlen = 1920; > while (1) > { > speex_resampler_reset_mem(speex_resampler); > int len = fread(inbuff, 2, 320, fp); > if (len <= 0) > { > break; > } > int ret = speex_resampler_process_int(speex_resampler, > 0, > inbuff, > &inlen, > outbuff, > &outlen); > printf("ret is %d\n", ret); > printf("inlen is %d\n",inlen); > printf("outlen is %d\n",outlen); > fwrite(outbuff, 1, outlen, fp2); > } > fflush(fp2); > fclose(fp2); > speex_resampler_destroy(speex_resampler); > return 0; > } > > > ------------------------------------------------------------------------ > 以上 > 如有问题,请联系我 > mail zhouyuchen at iauto.com <mailto:zhouyuchen at iauto.com> > tel 1905 > > *发件人:* Jean-Marc Valin <mailto:jmvalin at jmvalin.ca> > *发送时间:* 2019-11-06 01:20 > *收件人:* zhouyuchen at iauto.com <mailto:zhouyuchen at iauto.com>; > speex-dev <mailto:speex-dev at xiph.org> > *抄送:* jean-marc.valin <mailto:jean-marc.valin at usherbrooke.ca> > *主题:* Re: 【SPEEX】 use speex resample make noise > Be aware that inlen is an in/out parameter. It tells you how many > samples the resampler read. That number can be smaller than what you > passed -- in which case it means you need to buffer them and give them > to the resampler again in the next call. > Jean-Marc > On 11/5/19 8:27 AM, zhouyuchen at iauto.com wrote: > > Hello, > > I have encountered some problems. I want to use speex to convert the > > sampling rate (16000->48000). > > When I read 640bytes each time, I found that the sound after the > sound > > conversion is very noisy, > > but if I read 6400bytes each time. The conversion will be much > better, > > the line is my sample code, am I using it incorrectly? please > help confirm? > > > > int main() > > { > > SpeexResamplerState *speex_resampler; > > int err; > > speex_resampler = speex_resampler_init(1, 16000, 48000, 10, > &err); > > FILE *fp = fopen("/data/zhou.wav", "rb+"); > > FILE *fp2 = fopen("/data/zhou2.wav", "ab+"); > > spx_int16_t inbuff[640] = {0}; > > spx_int16_t outbuff[1920] = {0}; > > spx_uint32_t inlen = 640; > > spx_uint32_t outlen = 1920; > > speex_resampler_skip_zeros(speex_resampler); > > while (1) > > { > > int len = fread(inbuff, 2, 320, fp); > > if (len <= 0) > > { > > break; > > } > > int ret = speex_resampler_process_int(speex_resampler, > > 0, > > inbuff, > > &inlen, > > outbuff, > > &outlen); > > printf("ret is %d\n", ret); > > printf("outlen is %d\n",outlen); > > fwrite(outbuff, 1, outlen, fp2); > > } > > > > return 0; > > } > > > > > > > > > ------------------------------------------------------------------------ > > 以上 > > 如有问题,请联系我 > > mail zhouyuchen at iauto.com <mailto:zhouyuchen at iauto.com> > > tel 1905 > > >