[Speex-dev] 【SPEEX】 use speex resample make noise

Jean-Marc Valin jmvalin at jmvalin.ca
Tue Nov 5 17:20:20 UTC 2019


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
> 


More information about the Speex-dev mailing list