Unwanted echoes

I have a problem with the sound effects in my SDL program. I’m running
out of ideas, and I’m hoping someone here might recognize the problem.

I have an SDL game with a number of sound effects. (Most of the sound
effects are less than a second long.) The game’s clock ticks 20 times
a second; at each tick, the keyboard is polled and the display is
updated, etc. Since new sound effects can be set off at every tick,
the program uses a fairly small value for the SDL_AudioSpec.samples
field when SDL_OpenAudio() is called.

The sound effects sound just fine on my machine. However, after
getting some bug reports, I discovered that on some machines, my sound
effects are “echoing”. There is a delay of approximately one second
between each sound and its echo. The echo is a little quieter and
tinny-sounding.

Currently my program calls SDL_OpenAudio() requesting freq = 22050,
fmt = AUDIO_S16LSB, and channels = 1. (And, on my test machine, the
obtained SDL_AudioSpec’s field is the same.) The value of the samples
field is calculated from the freq field – for 22050, samples is set
to 512.

One thing I’ve discovered is that changing the requested freq alters
the delay of the echo. (That is, requesting a freq of 11025 seems to
double the echo’s delay time, and requesting a freq of 44100 halves
it.)

Also, on the test machine the sound effects are of poor quality. The
sound is broken-up. It sounds as if it is due to drop-outs. However, I
don’t know if this is related to the echo problem or not. (The
descriptions of the problem that I’ve gotten from my users are
generally a little vague and confused, but I have the impression that
the echoing problem and the poor-quality problem do not always appear
together.)

There doesn’t seem to be a correlation between the “broken-up” sound
and slow machines, however. If anything, it seems to be people with
newer machines that are having problems. The test machine on which I
can reproduce the problem is a Sony Vaio running Windows XP.

Any ideas or suggestions on what might be causing this, or how I
should proceed?

b

The sound effects sound just fine on my machine. However, after
getting some bug reports, I discovered that on some machines, my sound
effects are “echoing”. There is a delay of approximately one second
between each sound and its echo. The echo is a little quieter and
tinny-sounding.

Currently my program calls SDL_OpenAudio() requesting freq = 22050,
fmt = AUDIO_S16LSB, and channels = 1. (And, on my test machine, the
obtained SDL_AudioSpec’s field is the same.) The value of the samples
field is calculated from the freq field – for 22050, samples is set
to 512.

I’ve noticed that with the SDL audio you need to increase your buffer size
to something like 2048. I can’t get a smooth audio stream with anything
less than 1536.

The problem is the audio is playing back and looping and the buffer isn’t
getting updated fast enough.

–>Neil-------------------------------------------------------------------------------
Neil Bradley What are burger lovers saying
Synthcom Systems, Inc. about the new BK Back Porch Griller?
ICQ #29402898 “It tastes like it came off the back porch.” - Me

The sound effects sound just fine on my machine. However, after
getting some bug reports, I discovered that on some machines, my sound
effects are “echoing”. There is a delay of approximately one second
between each sound and its echo. The echo is a little quieter and
tinny-sounding.

Currently my program calls SDL_OpenAudio() requesting freq = 22050,
fmt = AUDIO_S16LSB, and channels = 1. (And, on my test machine, the
obtained SDL_AudioSpec’s field is the same.) The value of the samples
field is calculated from the freq field – for 22050, samples is set
to 512.

I’ve noticed that with the SDL audio you need to increase your buffer size
to something like 2048. I can’t get a smooth audio stream with anything
less than 1536.

The problem is the audio is playing back and looping and the buffer isn’t
getting updated fast enough.

While that might explain the drop-outs, it doesn’t explain the
echoes. At 22050, a buffer size of 512 is less than 1/40 of a second.
No way can that cause an echo with a 1-second delay.

b

I’ve noticed that with the SDL audio you need to increase your buffer size
to something like 2048. I can’t get a smooth audio stream with anything
less than 1536.

The problem is the audio is playing back and looping and the buffer isn’t
getting updated fast enough.

While that might explain the drop-outs, it doesn’t explain the
echoes. At 22050, a buffer size of 512 is less than 1/40 of a second.
No way can that cause an echo with a 1-second delay.

I don’t claim to know how SDL works internally audio-wise. It may use many
buffers - who knows. But I know one thing - increasing the buffer’s size
fixed the problem.

I had this EXACT problem with audio in my emulator until I increased the
size of the buffer. The solution is to increase the size of the playback
buffer. My guess is that, at least under Windows, the DirectX sound
callbacks aren’t being used (which would eliminate this problem). Other
sound systems for the various UNIXen are the awful “push” model that stops
every once in a while and pushes sound out the port. It’s a really lousy
way to do audio on a nonrealtime system.

–>Neil-------------------------------------------------------------------------------
Neil Bradley What are burger lovers saying
Synthcom Systems, Inc. about the new BK Back Porch Griller?
ICQ #29402898 “It tastes like it came off the back porch.” - Me

I’ve noticed that with the SDL audio you need to increase your buffer size
to something like 2048. I can’t get a smooth audio stream with anything
less than 1536.

The problem is the audio is playing back and looping and the buffer isn’t
getting updated fast enough.

While that might explain the drop-outs, it doesn’t explain the
echoes. At 22050, a buffer size of 512 is less than 1/40 of a second.
No way can that cause an echo with a 1-second delay.

I don’t claim to know how SDL works internally audio-wise. It may use many
buffers - who knows. But I know one thing - increasing the buffer’s size
fixed the problem.

Ah, what’s probably happening is that the SDL audio is writing to a DMA buffer,
and it’s not being serviced often enough. Does it happen with the latest CVS
code?

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

Out of curiosity, what happens if you go into the SDL audio code and add
Win32 specific code to raise the priority of the audio thread? I haven’t
seen this problem myself, but I also don’t run Windows XP, and its possible
that the scheduling may be different from that of Windows 98.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

I don’t claim to know how SDL works internally audio-wise. It may use many
buffers - who knows. But I know one thing - increasing the buffer’s size
fixed the problem.

I had this EXACT problem with audio in my emulator until I increased the
size of the buffer. The solution is to increase the size of the playback
buffer.

Very interesting. Thanks – I will test this idea out as soon as I
can. Of course, if I increase the buffer size too much, it will screw
up the timing of the sound effects … not sure what I’ll do in that
case.

My guess is that, at least under Windows, the DirectX sound
callbacks aren’t being used (which would eliminate this problem).
Other sound systems for the various UNIXen are the awful "push"
model that stops every once in a while and pushes sound out the
port. It’s a really lousy way to do audio on a nonrealtime system.

Huh. I’ve never had a problem with my game’s sound on Linux, only on
Windows. (Though admittedly that may just be because there are much
fewer Linux users using my game.)

b

size of the buffer. The solution is to increase the size of the playback
buffer.
Very interesting. Thanks – I will test this idea out as soon as I
can. Of course, if I increase the buffer size too much, it will screw
up the timing of the sound effects … not sure what I’ll do in that
case.

Had that problem, too! :wink: Actually, right now I’m using a 2048 byte
buffer, which puts my sound effects about a 20th of a second behind, or
about 3 frames per game. Tolerable, and noticeable only by the most anal
of emulatorians.

model that stops every once in a while and pushes sound out the
port. It’s a really lousy way to do audio on a nonrealtime system.
Huh. I’ve never had a problem with my game’s sound on Linux, only on
Windows. (Though admittedly that may just be because there are much
fewer Linux users using my game.)

It also depends upon system load, too. If the OS isn’t doing anything
else, then it’ll have time to keep up. The net effect of when it DOES die
under any UNIXen is a complete dropout. That’s why the callback approach
from the sound device is the most desirable - you will not get dropouts.
I’m wondering if some of your Windows users who are experiencing the
echoing are running Set at Home. :wink:

I checked the audio code and it’s not using the DirectX callback features.
It’s a spawned thread that looks like it sets it to the highest priority,
but as I mentioned before, neither Windows nor any UNIXen are realtime
OSes and are susceptible to audio dropouts.

You may want to check out the latest CVS release as Sam suggested. That
might take care of things.

–>Neil-------------------------------------------------------------------------------
Neil Bradley What are burger lovers saying
Synthcom Systems, Inc. about the new BK Back Porch Griller?
ICQ #29402898 “It tastes like it came off the back porch.” - Me

I had the same problem in my game – worked fine in Linux for me and on
Win98 on my wife’s machine, but got random reports of echo problems from
other Windows users. Increasing the buffer fixed the problem, and the added
latency isn’t enough to notice.On Thu, Aug 01, 2002 at 11:47:50PM -0700, Brian Raiter wrote:

Huh. I’ve never had a problem with my game’s sound on Linux, only on
Windows. (Though admittedly that may just be because there are much
fewer Linux users using my game.)


Matthew Miller @Matthew_Miller http://www.mattdm.org/
Boston University Linux ------> http://linux.bu.edu/