protected override void OnLoad(EventArgs e) { base.OnLoad(e); dxSoundDevice = new Microsoft.DirectX.DirectSound.Device(); dxSoundDevice.SetCooperativeLevel(this, CooperativeLevel.Priority); WaveFormat wf = new WaveFormat(); wf.FormatTag = WaveFormatTag.Pcm; wf.BitsPerSample = 8; wf.Channels = 1; wf.BlockAlign = 1; wf.SamplesPerSecond = (int)(dSampleRate); wf.AverageBytesPerSecond = wf.SamplesPerSecond * wf.BlockAlign; // buffer description BufferDescription bd = new BufferDescription(wf); bd.DeferLocation = true; bd.GlobalFocus = true; // play this buffer, even if the app looses focus bd.ControlPan = true; bd.ControlVolume = true; bd.PrimaryBuffer = false; bd.BufferBytes = wave.Length; soundBuffer = new SecondaryBuffer(bd, dxSoundDevice); soundBuffer.Volume = tbVolume.Value; soundBuffer.Pan = 0; if (chkPlay.Checked) { m_ambient.Start(); } }
override public void Dispose(bool disposing) { // If you need thread safety, use a lock around these // operations, as well as in your methods that use the resource. if (!m_disposed) { if (disposing) { if (m_description3d != null) { m_description3d.Dispose(); } if (m_secondaryBuffer != null) { m_secondaryBuffer.Dispose(); } if (m_buffer3d != null) { m_buffer3d.Dispose(); } } m_description3d = null; m_secondaryBuffer = null; m_buffer3d = null; // Indicate that the instance has been disposed. m_disposed = true; } }
private void cmbDone_Click(object sender, System.EventArgs e) { // Gets the GUID of the selected sound device globalSettings.audioDevice = directSoundDevices[cmbDevices.SelectedIndex]; //globalSettings.selectedAudioDevice = cmbDevices.SelectedIndex; globalSettings.aDC.selectedAudioDevice = cmbDevices.SelectedIndex; audioDeviceSave(); if (dsInterface.aSoundCard == null) { // Sets up the DX Audio Interface for the program dsInterface.setupAudio(this); } else { dsInterface.changeAudioDevice(); } // Close it all down testSound = null; testCard = null; AboutTimer = null; this.Close(); }
public void PlayExplosion() { if (ExplosionSound == null) { ExplosionSound = new DirectSound.SecondaryBuffer(GameConfig.Files.SoundExplosion, device); } ExplosionSound.SetCurrentPosition(0); ExplosionSound.Play(0, DirectSound.BufferPlayFlags.Default); }
public void PlayGunShot() { if (GunSound == null) { GunSound = new DirectSound.SecondaryBuffer(GameConfig.Files.SoundGun, device); } GunSound.SetCurrentPosition(0); GunSound.Play(0, DirectSound.BufferPlayFlags.Default); }
public void PlayStep() { if (StepSound == null) { StepSound = new DirectSound.SecondaryBuffer(GameConfig.Files.SoundStep, device); } StepSound.SetCurrentPosition(0); StepSound.Play(0, DirectSound.BufferPlayFlags.Default); }
private void InitializeGraphics() { try { PresentParameters presentParams = new PresentParameters(); presentParams.Windowed = true; presentParams.SwapEffect = SwapEffect.Discard; presentParams.BackBufferFormat = Format.Unknown; presentParams.AutoDepthStencilFormat = DepthFormat.D16; presentParams.EnableAutoDepthStencil = true; // Store the default adapter int adapterOrdinal = D3D.Manager.Adapters.Default.Adapter; CreateFlags flags = CreateFlags.SoftwareVertexProcessing; // Check to see if we can use a pure hardware device D3D.Caps caps = D3D.Manager.GetDeviceCaps(adapterOrdinal, D3D.DeviceType.Hardware); // Do we support hardware vertex processing? if (caps.DeviceCaps.SupportsHardwareTransformAndLight) { // Replace the software vertex processing flags = CreateFlags.HardwareVertexProcessing; } // Do we support a pure device? if (caps.DeviceCaps.SupportsPureDevice) { flags |= CreateFlags.PureDevice; } device = new D3D.Device(0, D3D.DeviceType.Hardware, this, flags, presentParams); device.DeviceReset += new System.EventHandler(this.OnResetDevice); OnResetDevice(device, null); tileSheet = TextureLoader.FromFile(device, MediaUtilities.FindFile("donuts.bmp"), 1024, 1024, 1, 0, Format.A8R8G8B8, Pool.Managed, Filter.Point, Filter.Point, (unchecked ((int)0xff000000))); tileSet = new TileSet(tileSheet, 0, 0, 6, 5, 32, 32); tilePosition = new Rectangle(tileSet.XOrigin, tileSet.YOrigin, tileSet.ExtentX * 2, tileSet.ExtentY * 2); //set up DirectInput keyboard device... kbd = new DI.Device(SystemGuid.Keyboard); kbd.SetCooperativeLevel(this, DI.CooperativeLevelFlags.Background | DI.CooperativeLevelFlags.NonExclusive); kbd.Acquire(); //Set up DirectSound device and buffers snd = new DS.Device(); snd.SetCooperativeLevel(this, DS.CooperativeLevel.Normal); bounce = new DS.SecondaryBuffer(MediaUtilities.FindFile("bounce.wav"), snd); hrt.Start(); } catch (DirectXException) { // Catch any errors and return a failure } }
public ShootingClass(Device d3dDevice, DSound.Device dsoundD) { Hashtable aux = new Hashtable(); Directions = Hashtable.Synchronized(aux); dsoundDevice = dsoundD; dsoundBuffer = new DSound.SecondaryBuffer(@"media\sound\machgun.wav", dsoundDevice); gunshot = new shot(d3dDevice); }
public SoundBuffer(Device soundDevice, string filename, Sounds thisSound, bool looping) { this.thisSound = thisSound; this.looping = looping; try { buffer = new SecondaryBuffer(filename, soundDevice); } catch (Exception e) { throw new Exception(String.Format("Error opening {0}", filename), e); } }
public Sound2d(string file, DirectSound.Device device) { // 2d setup m_description2d = new DirectSound.BufferDescription(); m_description2d.ControlEffects = false; m_description2d.ControlVolume = true; m_description2d.GlobalFocus = true; m_description2d.ControlPositionNotify = true; m_secondaryBuffer = new DirectSound.SecondaryBuffer(file, m_description2d, device); m_notify = new DirectSound.Notify(m_secondaryBuffer); }
private void playSound(String url) { try { Microsoft.DirectX.DirectSound.SecondaryBuffer snd = new Microsoft.DirectX.DirectSound.SecondaryBuffer( url, dev); snd.Play(0, Microsoft.DirectX.DirectSound.BufferPlayFlags.Default); } catch (Exception ex) { ; } }
public MDX1_SoundBuffer(MDX1_Audio audio, Stream inStream) { mAudio = audio; DirectSound.BufferDescription desc = new Microsoft.DirectX.DirectSound.BufferDescription(); desc.PrimaryBuffer = false; desc.ControlVolume = true; desc.ControlFrequency = true; desc.ControlPan = true; desc.ControlEffects = false; desc.LocateInSoftware = true; mBuffer = new DirectSound.SecondaryBuffer(inStream, desc, mAudio.DS_Device); }
private void frmAbout_Load(object sender, System.EventArgs e) { // All this to get the file name where the home directory of the app int fileName = Application.ExecutablePath.Length - Application.ExecutablePath.LastIndexOf("\\") - 1; path = Application.ExecutablePath.Remove(Application.ExecutablePath.Length - fileName, fileName); //MessageBox.Show(path); globalSettings.path = path; // I got sick of waiting while developing ;-) #if (DEBUG) cmbDone.Visible = true; #endif try { testCard = new Microsoft.DirectX.DirectSound.Device(); testCard.SetCooperativeLevel(this, Microsoft.DirectX.DirectSound.CooperativeLevel.Normal); //Microsoft.DirectX.DirectSound.SecondaryBuffer[] aSound = new SecondaryBuffer[256]; testSound = new Microsoft.DirectX.DirectSound.SecondaryBuffer(path + "fire.wav", testCard); } catch (Microsoft.DirectX.DirectSound.SoundException Exc) { MessageBox.Show("There has been an error while seting up your sound card; please review your Direct X settings. :: " + Exc.ErrorString.ToString()); } lblVersion.Text = "Sending Request"; string _webCheck = globalSettings.versionCheckAddress + globalSettings.releaseVersion; try { // Don't need to check if I am running the latest version while // developing it ;-) #if (!DEBUG) lblVersion.Text = httpFunctions.getVersion(_webCheck); #endif } catch { } // Audio device enumeration AudioDeviceEnumeration(); }
} // initGfx().fim // [--- public void inicializarSom() { string som_arquivo = @"c:\gameprog\gdkmedia\som\shoot.wav"; // Cria um dispositivo de som radio = new DirectSound.Device(); // Estabelece o nível de cooperação radio.SetCooperativeLevel(this, DirectSound.CooperativeLevel.Normal); // Cria um objeto SecondaryBuffer que toca o som som = new DirectSound.SecondaryBuffer(som_arquivo, radio); // Toca o som efetivamente som.Play(0, DirectSound.BufferPlayFlags.Default); } // inicializarSom().fim
private bool SoundFX_LoadSoundFile(string name) // try to load sound file { try { ApplicationBuffer = new Microsoft.DirectX.DirectSound.SecondaryBuffer(name, ApplicationDevice); trackBar1.Value = ApplicationBuffer.Frequency; label1.Text = trackBar1.Value.ToString(); } catch (Microsoft.DirectX.DirectSound.SoundException) { MessageBox.Show("Error", "SoundFX_LoadSoundFile() failed, file is missing/corrupted?.", MessageBoxButtons.OK, MessageBoxIcon.Information); return(false); } return(true); }
public Sound3d(string file, DirectSound.Device device) { m_description3d = new DirectSound.BufferDescription(); m_description3d.ControlEffects = false; m_description3d.GlobalFocus = true; m_description3d.Control3D = true; m_description3d.ControlVolume = true; m_description3d.Guid3DAlgorithm = DirectSound.DSoundHelper.Guid3DAlgorithmHrtfFull; m_description3d.ControlPositionNotify = true; m_secondaryBuffer = new DirectSound.SecondaryBuffer(file, m_description3d, device); m_buffer3d = new DirectSound.Buffer3D(m_secondaryBuffer); m_buffer3d.Position = new SoundVector(0, 0, 1); m_buffer3d.Mode = DirectSound.Mode3D.Normal; m_notify = new DirectSound.Notify(m_secondaryBuffer); }
private void killDXOutputBuffer() { if (dxOutputBuffer != null) { try { dxOutputBuffer.Stop(); dxOutputBuffer.Dispose(); } catch { } finally { dxOutputBuffer = null; } } }
public bool createOutputBuffer() { int tries = 0; while (tries < 2) { try { if (dxOutputBuffer == null) { BufferDescription bufDesc = new BufferDescription(); bufDesc.Format = createWaveFormat(Frequency, DX_BITS_PER_SAMPLE, DX_NUM_CHANNELS); bufDesc.BufferBytes = DX_BUFFER_SIZE; bufDesc.ControlFrequency = true; bufDesc.ControlPositionNotify = false; bufDesc.ControlEffects = true; bufDesc.ControlPan = false; bufDesc.ControlVolume = true; bufDesc.GlobalFocus = true; bufDesc.PrimaryBuffer = false; dxOutputBuffer = new Microsoft.DirectX.DirectSound.SecondaryBuffer(bufDesc, device); } else if (dxOutputBuffer.Frequency != frequency) { dxOutputBuffer.Frequency = frequency; } return(true); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.ToString()); tries++; System.Threading.Thread.Sleep(2000); } } return(false); }
} // initGfx().fim // [--- public void inicializarSom() { string som_arquivo = @"c:\gameprog\gdkmedia\som\shoot.wav"; // Cria um dispositivo de som radio = new DirectSound.Device(); // Estabelece o nível de cooperação radio.SetCooperativeLevel(this, DirectSound.CooperativeLevel.Normal); // <b> // Configura descrição do som DirectSound.BufferDescription desc = new DirectSound.BufferDescription(); // Habilita controle de pan desc.ControlPan = true; // Habilita foco global. Efeito sonoro toca mesmo enquanto a aplicação // está em segundo plano desc.GlobalFocus = true; // Cria um objeto SecondaryBuffer que toca o som som = new DirectSound.SecondaryBuffer(som_arquivo, desc, radio); // </b> } // inicializarSom().fim
public WavesReverbEffect(IntPtr lp, SecondaryBuffer source) { throw new NotImplementedException(); }
private void InitializeGraphics() { try { PresentParameters presentParams = new PresentParameters(); presentParams.Windowed = true; presentParams.SwapEffect = SwapEffect.Discard; presentParams.BackBufferFormat = Format.Unknown; presentParams.AutoDepthStencilFormat = DepthFormat.D16; presentParams.EnableAutoDepthStencil = true; // Store the default adapter int adapterOrdinal = D3D.Manager.Adapters.Default.Adapter; CreateFlags flags = CreateFlags.SoftwareVertexProcessing; // Check to see if we can use a pure hardware device D3D.Caps caps = D3D.Manager.GetDeviceCaps(adapterOrdinal, D3D.DeviceType.Hardware); // Do we support hardware vertex processing? if (caps.DeviceCaps.SupportsHardwareTransformAndLight) // Replace the software vertex processing flags = CreateFlags.HardwareVertexProcessing; // Do we support a pure device? if (caps.DeviceCaps.SupportsPureDevice) flags |= CreateFlags.PureDevice; device = new D3D.Device(0, D3D.DeviceType.Hardware, this, flags, presentParams); device.DeviceReset += new System.EventHandler(this.OnResetDevice); OnResetDevice(device, null); tileSheet = TextureLoader.FromFile(device, MediaUtilities.FindFile("donuts.bmp"), 1024, 1024, 1, 0,Format.A8R8G8B8, Pool.Managed, Filter.Point, Filter.Point, (unchecked((int)0xff000000))); tileSet = new TileSet(tileSheet, 0, 0, 6, 5, 32, 32); tilePosition = new Rectangle(tileSet.XOrigin, tileSet.YOrigin,tileSet.ExtentX*2, tileSet.ExtentY*2); //set up DirectInput keyboard device... kbd = new DI.Device(SystemGuid.Keyboard); kbd.SetCooperativeLevel(this, DI.CooperativeLevelFlags.Background | DI.CooperativeLevelFlags.NonExclusive ); kbd.Acquire(); //Set up DirectSound device and buffers snd = new DS.Device(); snd.SetCooperativeLevel(this, DS.CooperativeLevel.Normal); bounce = new DS.SecondaryBuffer(MediaUtilities.FindFile("bounce.wav"), snd); hrt.Start(); } catch (DirectXException) { // Catch any errors and return a failure } }
public GargleEffect(IntPtr lp, SecondaryBuffer source) { throw new NotImplementedException(); }
public MDX1_SoundBufferSession(MDX1_Audio audio, MDX1_SoundBuffer source) { mAudio = audio; mBuffer = source.Buffer.Clone(mAudio.DS_Device); }