音频重采样函数

经验证,在ARMV4上32000/44100转8000hz采样率  效率不错.

 

/* contributed by paul flinders */

 

void _x_audio_out_resample_mono(int16_t* input_samples, uint32_t in_samples,
    int16_t* output_samples, uint32_t out_samples)
{
  int osample;
  /* 16+16 fixed point math */
  uint32_t isample = 0;
  uint32_t istep = ((in_samples-2) << 16)/(out_samples-2);

#ifdef VERBOSE
  printf ("Audio : resample %d samples to %d/n",
          in_samples, out_samples);
#endif

  for (osample = 0; osample < out_samples - 1; osample++) {
    int  s1;
    int  s2;
    int16_t  os;
    uint32_t t = isample&0xffff;
   
    /* don't "optimize" the (isample >> 16)*2 to (isample >> 15) */
    s1 = input_samples[(isample >> 16)];
    s2 = input_samples[(isample >> 16)+1];
   
    os = (s1 * (0x10000-t)+ s2 * t) >> 16;
    output_samples[osample] = os;

    isample += istep;
  }
  output_samples[out_samples-1] = input_samples[in_samples-1];
}

你可能感兴趣的:(Math,OS,input,audio,output)