DirectSound - C# Sound Effects

Started by
2 comments, last by slainte 19 years ago
Hello all! I am still trying to get through the Demos in the C# book I'm using . I have not yet solved my previous texture problem (see http://www.gamedev.net/community/forums/topic.asp?topic_id=304969) but have moved on anyway. I am on to DirectSound. The first demo works just fine - sounding an explosion every two seconds. Ok, the second demo is supposed to demonstrate sound effects using DSoundHelper Effect Values. Once again, I can compile the code with no errors. However, at runtime, I get the following error: 2147221008 (CO_E_NOTINITIALIZED) The code from the demo includes the following:

  // load the wave
            DirectSound.BufferDescription desc = new DirectSound.BufferDescription();
            desc.ControlEffects = true;
            desc.GlobalFocus = true;
            wave = new DirectSound.SecondaryBuffer( "explosion1.wav", desc, sound );


            // set a flanger effect
            DirectSound.EffectDescription[] e = new DirectSound.EffectDescription[1];
            e[0].GuidEffectClass = DirectSound.DSoundHelper.StandardFlangerGuid;
            wave.SetEffects( e );

If I comment out this last line of code, the program will run but will not have the sound effects. I don't know if this problem could be related to the texture problem I was having earlier or if it is something entirely different. Any help or suggestions greatly appreciated.
Advertisement
this code work on me computer
u sure ur path is right?

			desc.ControlEffects = true;			desc.GlobalFocus = true;			sound = new DirectSound.SecondaryBuffer(@"sound\" + wav, desc, Device);			DirectSound.EffectDescription[] e = new DirectSound.EffectDescription[1];			e[0].GuidEffectClass = DirectSound.DSoundHelper.StandardFlangerGuid;			sound.SetEffects(e);			sound.Play(0, Microsoft.DirectX.DirectSound.BufferPlayFlags.Default);
Hello again I also try learn C# Manage DirectX9
I stuck on texture so me goto the sound chapter and this what me done so far
My problem is Play() play whole sound then it can play again when its done
the LPlay(string wav) can play same sound many time over it self
so if u can tell me how not to load wave and play sound like ion many channels me be very happy

I made an example program if u intrested me icq is 6891887


#region Using directivesusing System;using System.Collections.Generic;using System.Text;using System.Windows.Forms;using DirectSound = Microsoft.DirectX.DirectSound;#endregionnamespace Game{	public class Noice	{		private DirectSound.Device Device = null;		private DirectSound.SecondaryBuffer sound = null;		private DirectSound.BufferDescription desc = null;		public Noice(Form Frm)		{			Device	= new Microsoft.DirectX.DirectSound.Device();			desc	= new Microsoft.DirectX.DirectSound.BufferDescription();			Device.SetCooperativeLevel(Frm, DirectSound.CooperativeLevel.Normal);		}		public void Play()		{			if (desc.BufferBytes != 0)			{				sound.Play(0, Microsoft.DirectX.DirectSound.BufferPlayFlags.Default);			}		}		public void Load(string wav)		{			sound = new DirectSound.SecondaryBuffer(@"sound\" + wav, desc, Device);		}		public void LPlay(string wav)		{			desc.ControlEffects = true;			desc.GlobalFocus = true;			sound = new DirectSound.SecondaryBuffer(@"sound\" + wav, desc, Device);			DirectSound.EffectDescription[] e = new DirectSound.EffectDescription[1];			e[0].GuidEffectClass = DirectSound.DSoundHelper.StandardFlangerGuid;			sound.SetEffects(e);			sound.Play(0, Microsoft.DirectX.DirectSound.BufferPlayFlags.Default);		}		public int Get()		{			return desc.BufferBytes;		}	}}
Thanks for the response. The path to the sound is definitely ok, because the sound will play without effects when I comment out the effects code.

I am playing the sound like this, which uses a timer to space the playing of the sound to every 2 seconds:

[source lang=c#]                    if( nexttime <= gametimer.Time() )                {                    // play the sound                    wave.Play( 0, DirectSound.BufferPlayFlags.Default );                    // reset the timer                    nexttime += 2;                }



This one has me stumped. Is it possible that DirectX didn't install properly? I am using C# for the first time and just installed all the .net and DirectX components.

This topic is closed to new replies.

Advertisement