[.net] MDX 2.0 DirectSound PrimaryBuffer

Recommended Posts

Ampaze    122
Hi, has anybody successfully created a primary buffer with DirectSound and MDX 2.0? What I am trying to do is create a primary buffer to create a DS3D Listener with. The problem seems to boil down to the WaveFormat field in the BufferDescription. If it is null, like it should be for a primary buffer, I get System.InvalidOperationException: Nullable object must have a value. If i set it to a WaveFormat on the other hand, then i get System.ArgumentException: Value does not fall within the expected range. and the Debug Version of DirectSound complains DSOUND: Error: Primary buffers must be created with NULL format DSOUND: Error: Invalid buffer description Am I doing something wrong or is this a bug in the betas, that is not checking WaveFormat.HasValue before trying to access it? Or has MDX2 a whole new way of doing this?

Share this post

Share on other sites
Bob Janova    769
My guess is you can't just pass null, you have to pass a pointer that is set to null. I.e. (pseudocode):
D3DCreateBuffer(null); // not this// ... but this:void* pointer = null;D3DCreateBuffer(pointer);

I imagine it's trying to store some value in the parameter (i.e. it's a reference or 'out' parameter), so you have to give it a variable to store it in.

Share this post

Share on other sites
RipTorn    722
I recently converted my code from MDX sound 1.x to 2.0, and didn't actually get this problem... However I've got my own 'createWaveFormat' method tucked away somewhere. I'll see if I can dig it out..

On another note (I don't want to derail the thread), can anyone quickly tell me where Buffer.Write() went? My sound code relied on this so I eventually had to revert back to 1.x code...

		private static WaveFormat CreateWaveFormat(int bitrate, int frequency, int channels)		{			WaveFormat wf = new WaveFormat();			wf.BitsPerSample = (short)bitrate;			wf.SamplesPerSecond = frequency;			wf.Channels = (short)channels;			wf.BlockAlign = (short)(wf.BitsPerSample / 8 * wf.Channels);			wf.AverageBytesPerSecond = wf.SamplesPerSecond * wf.BlockAlign;			return wf;		}

Share this post

Share on other sites
remco    122
I got the exact same problem, I just cannot get a primary buffer working.
Ampaze, how did you enable the debug version, so it outputs the debug information? I enabled the debug DirectSound through the control panel, but I don't get any debug information, even with DebugView. I am using the feb. 2006 release.

One other problem is that I cannot create a 3d buffer from a secondary buffer (effect buffer in the 2.0 version), it gives me an error that a null reference occured, anyone got experience with this?

RipTorn, can you give us the values you used for bitrate, frequency and number of channels.

Hope we can figure this problem out together!

[Edited by - remco on March 13, 2006 1:52:16 PM]

Share this post

Share on other sites
Ampaze    122
Thanks for the replies so far!

I should have give some code, so here it goes using C#.

The following throws System.InvalidOperationException: Nullable object must have a value.

  DirectSound.Buffer primaryBuffer;  DirectSound.BufferDescription primDesc = new DirectSound.BufferDescription();  primDesc.PrimaryBuffer = true;  primDesc.Control3D = true;  primaryBuffer = new DirectSound.Buffer(ManagedSound.SoundDevice, primDesc);

While the next part throws System.ArgumentException: Value does not fall within the expected range. (which is correct as the Waveformat is supposed to be null)

  DirectSound.Buffer primaryBuffer;  DirectSound.BufferDescription primDesc = new DirectSound.BufferDescription();  primDesc.PrimaryBuffer = true;  primDesc.Control3D = true;  DirectSound.WaveFormat waveFormat = new DirectSound.WaveFormat();  // Setting the Format here.  primDesc.WaveFormat = waveFormat;  primaryBuffer = new DirectSound.Buffer(ManagedSound.SoundDevice, primDesc);

I am 99% sure this is indeed a bug in that particular constructor.

About that unmanaged debug, as the DirectX Control didnt allow me to change DirectSound to Debug I replaced the dsound.dll manually with the debug version that comes with the SDK. Which btw. isn't all that easy thanks to Windows File Protection.

For your other question, i never got so far to actually create a Buffer3D. With no listener ...

Share this post

Share on other sites
RipTorn    722
looked something like this:

			BufferDescription desc = new BufferDescription();			desc.PrimaryBuffer = true;			desc.Control3D = true;			desc.ControlVolume = true;			if (bitrate != 0 && frequency != 0)				desc.Format = CreateWaveFormat(bitrate,frequency,0);			else				desc.Format = CreateWaveFormat(16, 22050, 0);			primaryBuffer = new Buffer(desc, device);

Share this post

Share on other sites
Premandrake    175
It does look like there is a bug in the Buffer code (but I'm not sure of the intent). In the ctor(Device, Buffer) it does the following:
// Oops, accessing .Value without having checked .HasValue firstref void modopt(IsExplicitlyDereferenced)  pinned local1 = &description.WaveFormat.Value;if (description.WaveFormat.HasValue){    *((int*) (_dsbufferdescPtr1 + 0x10)) = local1;}int num1 = **(((int*) device.pComPtr))[12](device.pComPtr, _dsbufferdescPtr1, local2, 0);if (description.WaveFormat.HasValue){    memcpy(local1, *((void modopt(IsConst)**) (_dsbufferdescPtr1 + 0x10)), 0x12);}

A related note, Reflector has saved my bacon many times in the past. That's how I got the information above.

Share this post

Share on other sites
remco    122
Did anyone found a way to work around this error, or do we have to wait for a new release of MDX?

Share this post

Share on other sites
Ampaze    122
There is nothing we can do at the moment, only hope that the MDX Team fixes it in the next release... if they even know about it ...

Share this post

Share on other sites
remco    122
To bad, I hope they have implemented the XACT framework by then. For now FMOD is the best alternative I guess, or does anyone has any other ideas on what to use.

Share this post

Share on other sites
DrGUI    402
yea, be sure to report it, I think emailing to directx@microsoft.com is the way but I'm not entirely sure.

I think I should wait a bit longer before switching to MDX 2.0 eh? I only get the loader lock problem if I end my game then debug it again immediately afterwards, luckily.

Share this post

Share on other sites
m0nk3yi3unz    122
Wow, what a bugger :(

I'm attempting to do the same - create a primary buffer. I noticed the buffer -will- be created when Control3D is false, otherwise it fowls up. I've tried using a multitude of wav files of different encodings and bitrates and whatnot, with no success. Along with that, I'm using a wav file that works with just a regular, stereo secondary buffer perfectly fine (not using any 3D sound stuff).

Waiting patiently for a fix/solution/apology from MS, and hoping I won't have to switch to XNA (bleh...)

-Monkey

Share this post

Share on other sites
Promit    13246
Let me know if SlimDX doesn't completely solve this problem for you guys. MDX is thoroughly dead, after all. Also, lolz at the epic necro.

Share this post

Share on other sites
m0nk3yi3unz    122
Hey guys. Hopefully we're all having the same problem, because I found the solution to mine :P

When using buffers to have a 3D sound environment, buffers loaded with wav files intended to be played in 3D space -must- be EXPORTED in mono format (single channel). No, I just tested, you can not create a WaveFormat object and specify it to be single channel when the wav. file is exported in stereo, it just won't work. The Wav file, again, must be EXPORTED in a single channel. Been pulling my hair out for 2 days straight trying to fix this!

Hopefully this helps!

-Monkey

Share this post

Share on other sites
Awesome, thanks! I've been wondering why this doesn't work for ages :)

As for why I'm not just using XNA audio - you can't load arbitary files at runtime and play them. They have to be compiled in at build-time. That just doesn't work for me.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

• 9
• 10
• 9
• 14
• 28