jcornwall's picture

OpenAL stuttering

So, I've integrated OpenGL through OpenTK very nicely into my application. It's beautifully fast and sitting at about a third of the CPU consumption of an equivalent native application, thanks to OpenGL shaders.

I have begun to integrate OpenAL as well and I think I have the streaming playback structure correct. However, I'm getting severe stuttering effects and some very odd behaviour on Vista 64-bit with a Realtek ALC850 audio processor - e.g. on some runs I call alSourcePlay() with a full set of queued buffers and the source reports that it is playing for a long time before processing even a single buffer.

I thought I had done something wrong but here's the kicker: the example Playback.cs (from 0.9.1 and SVN) stutters severely as well. A similar native playback example from the OpenAL SDK plays without any problems. Has anyone run into this?

I will try porting the OpenAL SDK example line by line next because it's so simple that there can't be that many things going wrong in the C# layer.

Edit: Er, oh. This problem goes away (in both the example and my application) if I use Alut.Init() instead of an AudioContext object. Well that works for now!


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

I've also experienced this stuttering on Vista x64 with an ALC889 audio processor. I've always written this off as a bug in the OpenAL SI (the one available on Creative's site), as OpenAL Soft does not suffer from this, but it looks like I'm doing something wrong in AudioContext.

As far as I know, alutInit() just calls Alc.CreateContext(Alc.OpenDevice(null)) (the AudioContext tries to do a little more than that by enumerating all devices before opening the one).

Can you please try replacing Alut.Init() with the above functions? Does the stutter still occur?

jcornwall's picture

I've shone a little light on this.

This works for me:

int[] attribs = new int[0];
IntPtr device = Alc.OpenDevice(null);
IntPtr context = Alc.CreateContext(device, attribs);

However, AudioContext has a guard that prevents null from being passed to Alc.OpenDevice(). Instead it calls this, which reproduces randomly stuttering audio:

Alc.OpenDevice(Alc.GetString(IntPtr.Zero, AlcGetString.DefaultDeviceSpecifier));

The string is "Generic Software". So I presume that letting null through selects a different device?

the Fiddler's picture

Looks like it, although I can't figure out why it would work like this. ALC does have gray areas like this...

In any case, I'll shuffle the code so that Alc.OpenDevice(null) takes precedence over the default device. Should improve compatibility a little.

mwetherill's picture

wrong place sorry