Mixer help?

I’ve got a quick sound file that needs to be played quite a bit.
in an effort to keep it from getting monotonous, i want to have
the sound play at a different frequency every time.

can anyone point me to code that does this? if it hasn’t been
done, can someone rough draft an outline of how it would
theoretically work?

i’ll also want the sound being mixed a couple (3 at the most?)
times. it’d be great if mixer supports this type of stuff, but
my initial glance didn’t turn up much luck.

i suppose worst case would be to make several copies of the
sound data and have each one at a different frequency. then
when i need to play one, just pick one of them that isn’t
already playing and start it up.

the first place i really noticed this and loved it was in
DOOM. all the monsters “pain sounds” were played with the
frequency adjusted slightly changed. love it! that’s just
what i want!

thanks

I’ve got a quick sound file that needs to be played quite a bit.
in an effort to keep it from getting monotonous, i want to have
the sound play at a different frequency every time.

can anyone point me to code that does this? if it hasn’t been
done, can someone rough draft an outline of how it would
theoretically work?

That’d be very useful to me, too. :slight_smile: Well, it would have been.
When making Mad Bomber, I needed different pitches of the "splash"
noise. I couldn’t make it easily myself because I don’t know of
any good Linux sound editing tools. (We need GSMP - GNU Sound Manip Prog :wink: )

Anyway, I had to have a Windows-using friend tweak the file for me and
e-mail them back.

I felt so dirty. :wink:

-bill!

I’ve got a quick sound file that needs to be played quite a bit.
in an effort to keep it from getting monotonous, i want to have
the sound play at a different frequency every time.

This is called resampling. Doing it right is both mathematically tricky
and computationally intensive. But you may do with just cheap linear
interpolation; it will be noisy and eat a lot of high frequencies,
but might be good enough for a game.
Pseudocode example:

sample_rate=22050
new_rate=sample_rate + random(-5000…5000)
for(x = 0, i = 0; x < num_samples; x += sample_rate / new_rate) {
p = x - int(x)
new_samples[i++] = (1-p) * samples[int(x)] + p * samples[int(x) + 1]
}

Of course, in a real program you can optimise a lot of this (get rid of
floating point calculations etc).

the first place i really noticed this and loved it was in
DOOM. all the monsters “pain sounds” were played with the
frequency adjusted slightly changed. love it! that’s just
what i want!

It’s one of the small details that can add a lot of life to a game.
You may also use it for doppler effects

This is called resampling. Doing it right is both mathematically tricky
and computationally intensive. But you may do with just cheap linear
interpolation; it will be noisy and eat a lot of high frequencies,
but might be good enough for a game.
Pseudocode example:

sample_rate=22050
new_rate=sample_rate + random(-5000…5000)
for(x = 0, i = 0; x < num_samples; x += sample_rate / new_rate) {
p = x - int(x)
new_samples[i++] = (1-p) * samples[int(x)] + p * samples[int(x) + 1]
}

Well that works but its not exactly the most accurate method, and I know
how much you like accuracy:) Anyway, all that does is compress the sample
in time, which works fine for simple sounds but anything longer than 5
seconds would just sound stupid. WHat you really want to do is increase
the pitch of the sample itself, but this involves all kinds of FFT black
magic and other wonders. However, you’d need to be mad to bother:)

MartinOn Mon, 11 Sep 2000, Mattias Engdegard wrote:

Bother! said Pooh, as he was butchered for his paws and liver.

Well that works but its not exactly the most accurate method, and I know
how much you like accuracy:) Anyway, all that does is compress the sample
in time, which works fine for simple sounds but anything longer than 5
seconds would just sound stupid.

Resampling changes both the pitch and play time of course. For small
variations in pitch the change in sample length should not be
noticeable. (Note that for Doppler shifts the “sample” length is
actually changed in reality as well)

WHat you really want to do is increase
the pitch of the sample itself, but this involves all kinds of FFT black
magic and other wonders. However, you’d need to be mad to bother:)

I am quite mad to bother, as you know. Some kind of granular resynthesis
could be used, or a windowed FFT. With the appropriate preprocessing the
runtime cost might be brought within reasonable limits

Well that works but its not exactly the most accurate method, and I know
how much you like accuracy:) Anyway, all that does is compress the sample
in time, which works fine for simple sounds but anything longer than 5
seconds would just sound stupid.

Resampling changes both the pitch and play time of course. For small
variations in pitch the change in sample length should not be
noticeable. (Note that for Doppler shifts the “sample” length is
actually changed in reality as well)

WHat you really want to do is increase
the pitch of the sample itself, but this involves all kinds of FFT black
magic and other wonders. However, you’d need to be mad to bother:)

I am quite mad to bother, as you know. Some kind of granular resynthesis
could be used, or a windowed FFT. With the appropriate preprocessing the
runtime cost might be brought within reasonable limits

Joe Valenzuela implemented this in OpenAL. Check that out for a sample
implementation: http://www.openal.org/

See ya,
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Joe Valenzuela implemented this in OpenAL. Check that out for a sample
implementation: http://www.openal.org/

from al_filter.c:

/*

  • FIXME:*
  • I give up. I can’t get the pitch filter right and I don’t know
  • what I’m doing wrong. I’m going to wait until I have a better
  • info to do this, and stick with tpitch for now.
    */

:wink:

Seriously, the openAL code looks very good, and I have no doubt that
Joe will crush the remaining problems. But his code is more generic
and might not be the optimum for the simple case of playing back a
fixed sample with varying pitch

“Martin Donlon” wrote

This is called resampling. Doing it right is both mathematically tricky
and computationally intensive. But you may do with just cheap linear
interpolation; it will be noisy and eat a lot of high frequencies,
but might be good enough for a game.

whew, i wasn’t looking to change the actual sound data,
just cue SDL_mixer to mix the samples in a little quicker
or slower depending on my desires. unfortunately openAL
isn’t the best choice for me. it looks like i’m going
with the ‘make 5-8 sound files route’. lucky for me, i’m
already on windows (thus, already feel quite dirty) :]

the other part if my question the, (and this one’s easy)
can SDL_mixer play the same sound data on two different
streams?

the other part if my question the, (and this one’s easy)
can SDL_mixer play the same sound data on two different
streams?

Yes. :slight_smile:

See ya!
-Sam Lantinga, Lead Programmer, Loki Entertainment Software

Joe Valenzuela implemented this in OpenAL. Check that out for a sample
implementation: http://www.openal.org/

from al_filter.c:

/*

  • FIXME:
  • I give up. I can’t get the pitch filter right and I don’t know
  • what I’m doing wrong. I’m going to wait until I have a better
  • info to do this, and stick with tpitch for now.
    */

:wink:

Heh. The good mojo happens in alf_tpitch (in al_filter.c), which mirrors
the previous discussion (resampling in time domain). The comment brings
to mind the frustration which trying to fit an fft-based implementation
into a real-time simulation can give rise to.

Seriously, the openAL code looks very good, and I have no doubt that
Joe will crush the remaining problems. But his code is more generic
and might not be the optimum for the simple case of playing back a
fixed sample with varying pitch

No question.On Mon, Sep 11, 2000 at 07:01:49PM +0200, Mattias Engdeg?rd wrote:


J. Valenzuela – tsaotsao at lokigames.com