Surround sound (again)

I have a set of patches for SDL surround sound, using Alsa
on Linux. Not everything works, but playing 6 channel wave
files works using either loopwave, from the SDL test directory,
or playmus, from SDL_mixer. Also, playing midi files with
playmus using Timidity works (though panning can be improved).

I put the patches and two sample 6 channel wave files up for
ftp:
ftp://ling.lll.hawaii.edu/pub/greg/Surround-SDL.tgz

Greg

I think the idea behind that patch is really cool, but imo when you
start doing complex sound environments, you really want to be using
openal anyhow.On 06-Jun-2004, Greg Lee wrote:

I have a set of patches for SDL surround sound, using Alsa
on Linux. Not everything works, but playing 6 channel wave
files works using either loopwave, from the SDL test directory,
or playmus, from SDL_mixer. Also, playing midi files with
playmus using Timidity works (though panning can be improved).

I put the patches and two sample 6 channel wave files up for
ftp:
ftp://ling.lll.hawaii.edu/pub/greg/Surround-SDL.tgz

Greg


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


Patrick “Diablo-D3” McFarland || unknown at panax.com
"Computer games don’t affect kids; I mean if Pac-Man affected us as kids, we’d
all be running around in darkened rooms, munching magic pills and listening to
repetitive electronic music." – Kristian Wilson, Nintendo, Inc, 1989
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20040606/eb9e0d52/attachment.pgp

Patrick McFarland wrote:

I think the idea behind that patch is really cool, but imo when you
start doing complex sound environments, you really want to be using
openal anyhow.

I gave some careful consideration to that, but decided to proceed with
SDL for several reasons. Not necessarily good ones – I welcome your
opinion – and I’m very much an amateur in audio. But here are my
reasons:

  1. Just because OpenAL has surround (if it does), that’s no reason
    SDL shouldn’t have it, too.

  2. I looked at the OpenAL source for Alsa on linux, and the surround
    stuff is all stubbed. There’s no implementation there yet of surround.

  3. As I interpret the stubs, it doesn’t look as though 5.1 surround at
    16 bits is even in the cards. Much less 24 bits. The surround stuff
    in OpenAI is going to be 8 bits per channel (unless I just don’t
    understand the code – which is possible). That’s not for me.

  4. I’ve updated several times from the OpenAL CVS in the last few
    months. There have been no consequential changes, to my
    disappointment. What’s going on? Is it not really open anymore?
    Has it been abandoned?

  5. I followed references around the web for a while looking for free
    game engines supporting OpenAL, and I couldn’t find any. All
    proprietary.

So, I’m just very dubious and suspicious about OpenAL at this point.
I could fill out some of the missing Alsa support, myself, but if
OpenAL has no future as an open system, I’m not willing to.

Greg

I looked at it about two years ago, while researching for StepMania’s
sound engine. The OpenAL code was some of the worst code I’d ever
seen–conditionals nested something like 12 layers deep. It also
had no way to query the actual hardware play cursor, which is as
fundamental to a “serious” sound abstraction as blitting is to a serious
graphics abstraction.

SDL doesn’t have that, either, but it doesn’t pretend to be a serious
audio abstraction–it’s a very simple, basic audio API, and it doesn’t
try to be more than that. OpenAL does, and–at the time I tried it–
failed badly, at least for my uses.

However, on the same token, it’s not obvious whether things like surround
sound belong in SDL, considering how LCD an API it is.

(FYI, I ended up writing using native sound APIs exclusively; a cross-
platform sound library that fit my needs didn’t exist. In retrospect,
it was the right decision.)On Sun, Jun 06, 2004 at 04:09:49PM -1000, Greg Lee wrote:

So, I’m just very dubious and suspicious about OpenAL at this point.
I could fill out some of the missing Alsa support, myself, but if
OpenAL has no future as an open system, I’m not willing to.


Glenn Maynard

Glenn Maynard wrote:

So, I’m just very dubious and suspicious about OpenAL at this point.
I could fill out some of the missing Alsa support, myself, but if
OpenAL has no future as an open system, I’m not willing to.

I looked at it about two years ago, while researching for StepMania’s
sound engine. The OpenAL code was some of the worst code I’d ever
seen–conditionals nested something like 12 layers deep. It also
had no way to query the actual hardware play cursor, which is as
fundamental to a “serious” sound abstraction as blitting is to a serious
graphics abstraction.

SDL doesn’t have that, either, but it doesn’t pretend to be a serious
audio abstraction–it’s a very simple, basic audio API, and it doesn’t
try to be more than that. OpenAL does, and–at the time I tried it–
failed badly, at least for my uses.

However, on the same token, it’s not obvious whether things like surround
sound belong in SDL, considering how LCD an API it is.

Hmmm… if SDL provided surround sound support by exposing a
multichannel api, that would at least allow the building of a portable
add-on library for generic 3d sound support (be it 2 channel or 6
channel or whatever).

(FYI, I ended up writing using native sound APIs exclusively; a cross-
platform sound library that fit my needs didn’t exist. In retrospect,
it was the right decision.)

What audio APIs do you use on the platforms you support ?
Is there wide support for the asio api under windows or is it still
something very high-endish ?

Stephnae>On Sun, Jun 06, 2004 at 04:09:49PM -1000, Greg Lee wrote:

That sounds like the way to go.

-bill!On Mon, Jun 07, 2004 at 02:25:33PM +0200, Stephane Marchesin wrote:

Hmmm… if SDL provided surround sound support by exposing a
multichannel api, that would at least allow the building of a portable
add-on library for generic 3d sound support (be it 2 channel or 6
channel or whatever).

DirectSound and WaveOut in Windows, OSS and ALSA in Linux (the OSS code
apparently works in FreeBSD and OpenBSD), and CoreAudio in OSX. QT is
supported in OSX but is being phased out as the CA driver matures. There
are two separate DirectSound and ALSA drivers; one for systems supporting
hardware mixing and resampling, and one for ones without.

I couldn’t get the ASIO SDK without having to fill in some form and wait
for permission, which is unacceptable for an open source game, so I’ve
never tried it.On Mon, Jun 07, 2004 at 02:25:33PM +0200, Stephane Marchesin wrote:

(FYI, I ended up writing using native sound APIs exclusively; a cross-
platform sound library that fit my needs didn’t exist. In retrospect,
it was the right decision.)

What audio APIs do you use on the platforms you support ?
Is there wide support for the asio api under windows or is it still
something very high-endish ?


Glenn Maynard

Glenn Maynard wrote:

However, on the same token, it’s not obvious whether things like surround
sound belong in SDL, considering how LCD an API it is.

What does “LCD” mean?

Well, I’m still coding. I don’t seem to be able to stop, and of course
I hope surround does make it into SDL.

I’ve been working on the BuildCVT function, getting it to work better at
upconverting the number of channels in a stream. In doing so, I’ve run
across a little bug, already there in the SDL_audiocvt.c code. When
frequncy is changed by a multiple of 2, samples are omitted or copied.
But this only works for mono – it should be frames that are omitted or
copied. So I fixed that for the cases of 2, 4, and 6 channels. I’ll
put a new set of patches up in a day or two, after I’ve had a go at
fixing the panning effect for 4 and 6 channel streams.

Greg

Greg Lee wrote:

Glenn Maynard wrote:

However, on the same token, it’s not obvious whether things like
surround
sound belong in SDL, considering how LCD an API it is.

What does “LCD” mean?

Lowest common denominator

Well, I’m still coding. I don’t seem to be able to stop, and of course
I hope surround does make it into SDL.

I’ve been working on the BuildCVT function, getting it to work better at
upconverting the number of channels in a stream. In doing so, I’ve run
across a little bug, already there in the SDL_audiocvt.c code. When
frequncy is changed by a multiple of 2, samples are omitted or copied.

I’m not sure I understant what you mean here. Are you thinking about this ?
/* The problem with this is that if the input
buffer is
say 1K, and the conversion rate is say 1.1,
then the
output buffer is 1.1K, which may not be an
acceptable
buffer size for the audio driver (not a power
of 2)
*/

Stephane

Stephane Marchesin wrote:

Greg Lee wrote:

across a little bug, already there in the SDL_audiocvt.c code. When
frequncy is changed by a multiple of 2, samples are omitted or copied.

I’m not sure I understant what you mean here. Are you thinking about this ?

No, something else. A 2-channel stream is organized:

      frame1            frame2            frame3             ...
   left     right    left     right    left     right
 sample1  sample2  sample3  sample4  sample5  sample6   ...

To get a stereo signal at twice the frequency we want to omit the even
frames, leaving sample1 sample2 sample5 sample6 … But what is
done now is omit the even samples, leaving sample1 sample3
sample5 … In other words, the entire right channel is lost,
and it’s now a mono signal.

The problem is much more obvious to the ear when the mistaken
algorithm is applied to a 6 channel surround signal.

Greg

OpenAL is still being worked on. The problem on Linux is related to the
main Linux maintainer has a full-time unrelated job in the gaming
industry (which we all know computes to way more than 40 hours a week)
and a baby. People have suggested to him that he should work on OpenAL
full-time. He has also suggested he could write an extension to support
the querying of the “play cursor”

OTOH, Apple has been patching the bejeezus out of the version for OSX.

Another thing is that this was one of the first tries at a 3D API.
There are issues. They know there are issues. They just need to get
people together to make a 1.1 spec. (Not to mention, figure out who the
people they need to get together are.)

I’m also looking to start my own version of OpenAL written from scratch,
so it can be licensed under something other than LGPL. I just have to
get the go ahead from my job on it.–
Joe Tennies

Hello, Greg!

GL> I put the patches and two sample 6 channel wave files up for
GL> ftp:
GL> ftp://ling.lll.hawaii.edu/pub/greg/Surround-SDL.tgz

Good work. But you need to patch SDL more accurately:

I.e.:

SDL_audio.c.diff:

you left, SDL_SetError(“1 (mono) and 2 (stereo) channels supported”); which
is not adequate now.

SDL_alsa_audio.c.diff:

status = SDL_NAME(snd_pcm_open)(&handle, get_audio_device(2),
SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);

Why you changed get_audio_device() to get_audio_device(2) ?

playmus.c.diff: you need to add a command line option to play 4/6 channel
sound, but not to specify directly 6 channels. and sample rate.

Btw, where you found these 6ch .wav files ? :wink: I’ve googled for them some
time ago, but have not found anything, so I have used ac3 stream (liba52) to
play surround sound to test my c-media driver under QNX. If this patch will
be applied, I will add surround sound support to QNX6 too. :slight_smile:

With best regards, Mike Gorchak. E-mail: @Mike_Gorchak

OpenAL is still being worked on. The problem on Linux is related to the
main Linux maintainer has a full-time unrelated job in the gaming
industry (which we all know computes to way more than 40 hours a week)
and a baby. People have suggested to him that he should work on OpenAL
full-time. He has also suggested he could write an extension to support
the querying of the “play cursor”

Heh, is there only one Linux coder now? I thought there were a few of
them now.

OTOH, Apple has been patching the bejeezus out of the version for OSX.

Don’t forget that Creative also has been patching the bejeezus out of
their version (hardware acceleration in OpenAl … oooOOOoooh)

Another thing is that this was one of the first tries at a 3D API.
There are issues. They know there are issues. They just need to get
people together to make a 1.1 spec. (Not to mention, figure out who the
people they need to get together are.)

Yeah, but it came out quite well. I think whats partially wrong is too
many people are used to coding through SDL’s API, or through APIs like
DirectSound3D. They are sometimes quite disimilar (like how OpenGL and
Direct3D are different) and this confuses people to no end.

I’m also looking to start my own version of OpenAL written from scratch,
so it can be licensed under something other than LGPL. I just have to
get the go ahead from my job on it.

I’m not sure a non-LGPL version would help anyone. What we need is
hardware acceleration backends, or API driven implementations. The only
reason, say, a BSD version would do well is if you wanted companies to
pick it up for their drivers, which wouldn’t help much: the
implementation needs to be glued to the API and not the hardware, and as
such, ALSA (or the now quite dead as a parrot in a monty python skit
OSS) would act as a hardware access layer to OpenAL.

So, instead of hardware manufacturers picking up your OpenAL implementation,
you really want hardware manufacturers to add their drivers to ALSA. Of
course, this requires the OpenAl equivelent to DRI/DRM (which Mesa uses as
hardware access layer)On 07-Jun-2004, Joe Tennies wrote:

Joe Tennies


Patrick “Diablo-D3” McFarland || unknown at panax.com
"Computer games don’t affect kids; I mean if Pac-Man affected us as kids, we’d
all be running around in darkened rooms, munching magic pills and listening to
repetitive electronic music." – Kristian Wilson, Nintendo, Inc, 1989
-------------- next part --------------
A non-text attachment was scrubbed…
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: http://lists.libsdl.org/pipermail/sdl-libsdl.org/attachments/20040608/ba4205d9/attachment.pgp

Mike Gorchak wrote:

SDL_audio.c.diff:

you left, SDL_SetError(“1 (mono) and 2 (stereo) channels supported”); which
is not adequate now.
Right.

SDL_alsa_audio.c.diff:

status = SDL_NAME(snd_pcm_open)(&handle, get_audio_device(2),
SND_PCM_STREAM_PLAYBACK, SND_PCM_NONBLOCK);

Why you changed get_audio_device() to get_audio_device(2) ?

Because now this function takes number of channels as argument. So
I had to supply some number.

playmus.c.diff: you need to add a command line option to play 4/6 channel
sound, but not to specify directly 6 channels. and sample rate.

Right.

Btw, where you found these 6ch .wav files ? :wink: I’ve googled for them some
time ago, but have not found anything, so I have used ac3 stream (liba52) to
play surround sound to test my c-media driver under QNX. If this patch will
be applied, I will add surround sound support to QNX6 too. :slight_smile:

I looked far and wide for 6 channel wave files, but all I’ve found are
these speaker setup things, so I had to make some. I did find some
4 channel demos that come in two pieces – two stereo wave files that
are to be played simultaneously. I wrote a little program based on
libsndfile to piece together a 6 channel file from two such stereo
files (the center and lfe channels are faked). You’ll find the
program, “weave”, and references for the demo wave files on my ftp
site:
ftp://ling.lll.hawaii.edu/pub/greg/surround-utils-0.0.1.tar.gz

Greg

Greg Lee wrote:

… I’ll
put a new set of patches up in a day or two, after I’ve had a go at
fixing the panning effect for 4 and 6 channel streams.

There is now a revised set of patches in:

ftp://ling.lll.hawaii.edu/pub/greg/Surround-SDL.tgz

There are further revisions for channel and rate up/down
conversions, Panning/Setposition are generatlized,
and Timidity channel separation is slightly improved.

Greg

There is now a revised set of patches in:

ftp://ling.lll.hawaii.edu/pub/greg/Surround-SDL.tgz

There are further revisions for channel and rate up/down
conversions, Panning/Setposition are generatlized,
and Timidity channel separation is slightly improved.

Thanks! I’ll take a look at them when I get time!
Ryan, do you have any comments on these?

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

Sam Lantinga wrote:

There is now a revised set of patches in:

ftp://ling.lll.hawaii.edu/pub/greg/Surround-SDL.tgz

There are further revisions for channel and rate up/down
conversions, Panning/Setposition are generatlized,
and Timidity channel separation is slightly improved.

Thanks! I’ll take a look at them when I get time!
Ryan, do you have any comments on these?

Good. When you do look at them, please use a recent
download of Surround-SDL.tgz, since I’ve improved the
patches, from time to time. I just put in a version of
SetPosition that rotates the channels, as well as
attenuating some of them. Sounds much better.

Greg