[SDL] Audio Pitch question

Benno Senoner sbenno at gardena.net
Fri Aug 3 10:01:01 PDT 2001


On Thu, 02 Aug 2001, Jacek Pop³awski wrote:

> wow! I asked exactly same question here few weeks ago :-)
> now I solved that problem:
> 
> for (i=0;i<len;i++)
>  {
>   pos=(int)wav_position;
>   assert(pos>=0);
>   assert(pos<=wav_length);
>   my_sample[i]=wav_buffer[pos];
>   wav_position=wav_position+speed;
>   while (wav_position>=wav_length)
>     wav_position=wav_position-wav_length;
>  }
> 

Argh ! You use zero order resampling !
The audio quality is bad compared to linear interpolation.
linear interpolation uses only one single multiplication and offers a much
better sound quality.

Here is your modified code:

you should do:

float fract_pos;
float wav_position;

 for (i=0;i<len;i++)
  {
   pos=(int)wav_position;
   fract_pos=wav_position - pos;
   assert(pos>=0);
   assert(pos<=wav_length);
   my_sample[i]=wav_buffer[pos] + fract_pos*(wav_buffer[pos+1]-wav_buffer[pos]);
   wav_position=wav_position+speed;
   while (wav_position>=wav_length)
   wav_position=wav_position-wav_length;
  }
 

cheers,
Benno.

http://www.linuxaudiodev.org The Home of Linux Audio Development





More information about the SDL mailing list