[SlimDX] How to initialize SecondarySoundBuffer?

Started by
4 comments, last by ventuz_ks 15 years, 3 months ago
Hi! I can't manage to initialize a SecondarySoundBuffer in SlimDX. I'm trying to do it like this:

    using DSound = SlimDX.DirectSound;

    public class Sound
    {
        DSound.DirectSound parent = null;
        DSound.SoundBufferDescription description;
        DSound.SecondarySoundBuffer secBuffer = null;

        public Sound(System.Windows.Forms.Form appForm, Guid driverID)
        {
            this.parent = DSoundDeviceManager.GetDevice(driverID, appForm);
            this.description = new DSound.SoundBufferDescription();

            if ( this.parent != null )
            {
                try
                {
                    this.description.Flags =
                        DSound.BufferFlags.ControlVolume |
                        DSound.BufferFlags.ControlPan |
                        DSound.BufferFlags.GlobalFocus;

                    // read in the WAVE file
                    byte[] data;

                    using ( SlimDX.Multimedia.WaveFile file = new SlimDX.Multimedia.WaveFile(@"H:\AudioMono.wav") )
                    {
                        this.description.Format = file.Format;
                        data = new byte[file.Size];
                        file.Read(data, file.Size);
                    }

                    // create new 
                    this.secBuffer = new DSound.SecondarySoundBuffer(this.parent, this.description);
                }
                catch ( Exception ex )
                {
                    Console.WriteLine(ex.Message);
                }
            }
        }
    }

I always get an exception: E_INVALIDARG: An invalid parameter was passed to the returning function (-2147024809) Can't find any examples how to do it correctly. Thank you in advance Karol
Karol Strozynski [VENTUZ]
Advertisement
Do the debug runtimes give you any extra information?
Mike Popoloski | Journal | SlimDX
And what does your wave format look like? How many channels, what format tag, what sample rate, etc.

Quote:Original post by Mike.Popoloski
Do the debug runtimes give you any extra information?
Linky
Hi guys!

Sorry, forgot to mention that:
Debug Runtime gives no further information.
Using the November SlimDX version.

The format of the 'AudioMono.wav' is:
AverageBytesPerSecond: 22050
BitsPerSample: 8
BlockAlignement: 1
Channels: 1
FormatTag: Pcm
SamplesPerSecond: 22050

Tried it with the 'MusicMono.wav' from the SlimDX sample as well - same problems!
Is it currently possible to replace the DirectSound functionality with XAudio2?

Karol Strozynski [VENTUZ]
DirectSound should we usable, just like XAudio2. My only guess right now is that for some reason the flags you are specifying are invalid. I'll try it out on my own to see what I come up with.
Mike Popoloski | Journal | SlimDX
Solved!

Found the problem:
I did not set the SizeInBytes property in the SoundBufferDescription structure.

Thanks for the quick replies anyhow
Karol Strozynski [VENTUZ]

This topic is closed to new replies.

Advertisement