Audio Pitch question

Hi,

I’m rather new to multimedia programming under Linux and SDL, so
please bear with me if this is a stoopid question.

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?

I’ve looked at the docs and at SDL_mixer.h specifically, but have been
unable to find anything of this sort.

Thanks much in advance for your help,

Uwe–
Uwe Schuerkamp, QuBiz GmbH Phone: +49 5241 80 10 66
An der Autobahn 18, 33311 Guetersloh uwe.schuerkamp at qubiz.com
GnuPG Fingerprint: 2093 20B8 B861 9358 A356 B01A E145 9249 5D27 33EA
PGP Fingerprint: 2E 13 20 22 9A 3F 63 7F 67 6F E9 B1 A8 36 A4 61

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?

nothing supported directly by SDL or SDL_mixer. you have to change
pitch of your samples dynamically before feeding them into SDL (for an
engine sound, pitch change isn’t so hard - naive resampling with
linear interpolation should do)

wow! I asked exactly same question here few weeks ago :slight_smile:
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?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?


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

Hi Jacek,

thanks for your quick reply. I’m working on Ruud van Gaals Racer
in order to add some sound for the Linux version. What are you working
on, and wouldn’t you prefer joining forces with us? ;->

Cheers & all the best,

UweOn Thu, Aug 02, 2001 at 02:52:59PM +0200, Jacek Pop?awski wrote:

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


Uwe Schuerkamp, QuBiz GmbH Phone: +49 5241 80 10 66
An der Autobahn 18, 33311 Guetersloh uwe.schuerkamp at qubiz.com
GnuPG Fingerprint: 2093 20B8 B861 9358 A356 B01A E145 9249 5D27 33EA
PGP Fingerprint: 2E 13 20 22 9A 3F 63 7F 67 6F E9 B1 A8 36 A4 61

thanks for your quick reply. I’m working on Ruud van Gaals Racer

what is it?

What are you working
on, and wouldn’t you prefer joining forces with us? ;->

my project is called deracer, it’s OpenGL/SDL car game, now I have simple track
generator, I can race on that track, I have inside view (with steering wheel
;-), and outside view with car drawed as box, oh, and I have two trees in scenery :slight_smile:

I already submited project on sourceforge, but I need to improve physics a
little and rebuild track generator, it can be done in 1-2 nights, but I need
good time and a lot of coffee :->

I hope I can show it to world real soonOn Thu, Aug 02, 2001 at 04:29:01PM +0200, Uwe Schuerkamp wrote:


Safe in dreams
Away from where they are
Let me be nowhere
Just another star “Feed my head” - Ronnie James Dio

wow! I asked exactly same question here few weeks ago :slight_smile:
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 DevelopmentOn Thu, 02 Aug 2001, Jacek Pop?awski wrote:

I didn’t know why this quality is so bad…
thanks a_lot !On Fri, Aug 03, 2001 at 08:06:49PM +0200, Benno Senoner wrote:

Here is your modified code:


Don’t care which God you follow
Whose promises you swallow
Time and again
We must meet at the end “Lord of the Last Day” - Ronnie James Dio