Sign in to follow this  

[SlimDX] How to initialize SecondarySoundBuffer?

This topic is 3287 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Solved!

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

Thanks for the quick replies anyhow

Share this post


Link to post
Share on other sites

This topic is 3287 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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

Sign in to follow this