[SDL] Audio Pitch question

Jacek Popławski jpopl at interia.pl
Thu Aug 2 05:47:00 PDT 2001


On Thu, Aug 02, 2001 at 09:28:25AM +0200, Uwe Schuerkamp wrote:
> I use SDL_mixer to load a wav-type engine sample, and it plays back
> fine at 11khz. Is there an easy way to change the engine sound pitch
> of the sample being played using SDL dynamically, so I can simulate
> higher and lower RPM's?

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;
 }

 SDL_MixAudio(stream,my_sample,len,SDL_MIX_MAXVOLUME/4);


I hope that helps
BTW are you creating car simulator, like me?

-- 
Well it's a cold world  And I'm in the middle
Caught in the in-between  I don't belong here  
So I'm writing to you  It's wrong here                     "Letters From Earth" 
Where I'm sending you some  Letters from Earth              - Ronnie James Dio 




More information about the SDL mailing list