Problem with obtained structure in SDL_OpenAudio

Hi all,
I have a problem with an emulator that I work on. It runs it’s internal
timing based on the rate that audio data is consumed by the system audio
hardware.

The sound routines are able to generate sound at an arbitrary frequency,
so I was using the obtained structure from SDL_OpenAudio to tell me what
frequency I should generate samples at for real-time. The emulator
defaults to producing sound at 32KHz, and the call to SDL_OpenAudio
reports that obtained->freq is 32000 as requested.

The code appears to work properly when the esd driver is in use, but
switching to alsa or pcm drivers leaves the emulation running slowly and
the pitch of the sound far too low. On a hunch I forced my call to
SDL_OpenAudio to request a frequency of 48KHz and the emulator to
produce sound at 48KHz and now my code works properly regardless of
which driver is selected.

I assume this happens as my sound card only supports 48KHz natively, and
esd does a rate conversion for me from 32KHz to 48KHz for me, but why
does SDL not tell me that it could only get a 48KHz rate from the card?

Is it a problem with the kernel sound card drivers, or do other SDL
users see the same problem with the obtained->freq return for systems
with fixed-rate audio hardware?

Platform: Fedora Core 3
SDL version: 1.2.7 from libsdl.org and 1.2.7-8 as shipped with FC3
Kernel: 2.6.9-1.681_FC3
Sound driver: ALSA Trident 4DNX (snd_trident.o)

Thanks,
Fred

Fredrick Meunier wrote:

Hi all,
I have a problem with an emulator that I work on. It runs it’s internal
timing based on the rate that audio data is consumed by the system audio
hardware.

The sound routines are able to generate sound at an arbitrary frequency,
so I was using the obtained structure from SDL_OpenAudio to tell me what
frequency I should generate samples at for real-time. The emulator
defaults to producing sound at 32KHz, and the call to SDL_OpenAudio
reports that obtained->freq is 32000 as requested.

The code appears to work properly when the esd driver is in use, but
switching to alsa or pcm drivers leaves the emulation running slowly and
the pitch of the sound far too low. On a hunch I forced my call to
SDL_OpenAudio to request a frequency of 48KHz and the emulator to
produce sound at 48KHz and now my code works properly regardless of
which driver is selected.

I assume this happens as my sound card only supports 48KHz natively, and
esd does a rate conversion for me from 32KHz to 48KHz for me, but why
does SDL not tell me that it could only get a 48KHz rate from the card?

Is it a problem with the kernel sound card drivers, or do other SDL
users see the same problem with the obtained->freq return for systems
with fixed-rate audio hardware?

Platform: Fedora Core 3
SDL version: 1.2.7 from libsdl.org and 1.2.7-8 as shipped with FC3
Kernel: 2.6.9-1.681_FC3
Sound driver: ALSA Trident 4DNX (snd_trident.o)

I guess this is an AC97 chip ?

There are problems with this chip family (I have one and have distorded
sound in many SDL games).
SDL can detect this in some circumstances and print a message, but it
doesn’t work for me.
There is a workaround for the dsp backend :
export SDL_DSP_NOSELECT=1

Stephane

Hi Stephane,
Thanks for the help!

Platform: Fedora Core 3
SDL version: 1.2.7 from libsdl.org and 1.2.7-8 as shipped with FC3
Kernel: 2.6.9-1.681_FC3
Sound driver: ALSA Trident 4DNX (snd_trident.o)

I guess this is an AC97 chip ?

It uses snd_ac97_codec.o so I guess so.

There are problems with this chip family (I have one and have distorted
sound in many SDL games).

Fair enough, though this is the first I’ve heard of trouble with this
card with or without SDL (I have 6 of the Loki titles and ScummVM),
though since I upgraded to FC3 the Alpha Centauri expansion produces
sound with regular odd glitches unless run after the original Alpha
Centauri game. Indeed, I bought the card as the manufacturers had helped
the ALSA team get proper drivers done!

SDL can detect this in some circumstances and print a message, but it
doesn’t work for me.
There is a workaround for the dsp backend :
export SDL_DSP_NOSELECT=1

This doesn’t seem to help with my problem.

However, I’ve just tried using the alternate OSS sound code from the
emulator which has never before failed for me, and it also has new
problems that I’ve not seen before upgrading to FC3. Looks like my
problems may be down to FC3 instead :frowning:

Thanks again,
FredOn Sun, 2004-12-05 at 14:01 +0100, Stephane Marchesin wrote: