/// <summary> /// Plays a sound. /// </summary> /// <param name="id">The ChannelId identifing the SoundManger playing the sound and the channel number.</param> /// <param name="buffer">A SecondaryBuffer containing the sound to be playing.</param> /// <param name="frequencymultiplier">The multiplier applied the sound to change its pitch. 1.0f for no change.</param> /// <param name="looping">Whether the sound should loop automatically until stopped.</param> /// <param name="volume">The volume level of the sound.</param> public void Play(ChannelId id, SecondaryBuffer buffer, Single frequencymultiplier, Boolean looping, Int32 volume) { if (buffer == null) { throw new ArgumentNullException("buffer"); } if (volume > (Int32)Volume.Max || volume < (Int32)Volume.Min) { throw new ArgumentOutOfRangeException("volume"); } Stop(); m_usingid = id; m_buffer = buffer; BufferPlayFlags flags = (looping == true) ? BufferPlayFlags.Looping : BufferPlayFlags.Default; m_buffer.Frequency = (Int32)(m_buffer.Frequency * frequencymultiplier); m_buffer.SetCurrentPosition(0); m_buffer.Pan = (Int32)Pan.Center; m_buffer.Volume = volume; m_playflags = flags; try { m_buffer.Play(0, flags); } catch { } }
private void PlaySound() { BufferPlayFlags flags = BufferPlayFlags.Looping; if (RestoreBuffer()) { LoadSoundFile(FileName); applicationBuffer.SetCurrentPosition(0); } applicationBuffer.Play(0, flags); }
public void Play() { if (SB == null) { InitSecondaryBuffer(); } ThreadPool.QueueUserWorkItem(StreamControlThread, ""); //Thread t = new Thread(new ThreadStart(StreamControlThread)); //t.Name = "Event-Raising Sound Buffer Control Thread"; //t.IsBackground = true; //t.Start(); BufferPlayFlags flags = BufferPlayFlags.Looping; //ApplyEffectsInfo(); SB.Play(0, flags); }
private void PlayDXSound(Buffer buffer, int soundVolumeModifier, BufferPlayFlags flags) { if (ProblemWithSound) { return; } try { if (EngineConfig.SoundVolume == 0) { return; } buffer.Play(0, flags); buffer.Volume = System.Math.Min(0, getBaseVolume() + soundVolumeModifier); } catch (Exception) { ProblemWithSound = true; } }
private void buttonPlay_Click(object sender, System.EventArgs e) { bool FocusSticky = radioSticky.Checked; bool FocusGlobal = radioGlobal.Checked; bool MixHardware = radioHardware.Checked; bool MixSoftware = radioSoftware.Checked; if (null != applicationBuffer) { textStatus.Text = "Sound playing."; EnablePlayUI(false); Application.DoEvents(); // Process the Stop click that EnablePlayUI generates. // First we need to 'recreate' the buffer if (null != applicationBuffer) { applicationBuffer.Dispose(); } applicationBuffer = null; BufferDescription desc = new BufferDescription(); desc.ControlFrequency = true; desc.ControlPan = true; desc.ControlVolume = true; if (FocusGlobal) { desc.GlobalFocus = true; } if (FocusSticky) { desc.StickyFocus = true; } if (MixHardware) { desc.LocateInHardware = true; } if (MixSoftware) { desc.LocateInSoftware = true; } try { applicationBuffer = new SecondaryBuffer(ofdFile.FileName, desc, applicationDevice); BufferPlayFlags PlayFlags = checkLoop.Checked ? BufferPlayFlags.Looping : 0; // Before we play, make sure we're using the correct settings tbarFreq_Scroll(tbarFreq, null); tbarPan_Scroll(tbarPan, null); tbarVolume_Scroll(tbarVolume, null); applicationBuffer.Play(0, PlayFlags); } catch { textStatus.Text = "Could not open this file with these settings."; DefaultPlayUI(); } } }
public void playSound(BufferPlayFlags bufPlayFlag) { if (sound != null) { SecondaryBuffer newShotSound = sound.Clone(soundDevice); soundList.Add(newShotSound); sound.Play(0, bufPlayFlag); SoundAffairs(); } }
public static void Begin(string name,BufferPlayFlags playflags=BufferPlayFlags.Looping) { if (!PlaySound) return; if (!BUFFER.ContainsKey(name)) { string s = @"Sound\" + name + ".mp3"; //Mp3FileReader reader = new Mp3FileReader(s); //WaveStream pcmStream = WaveFormatConversionStream.CreatePcmStream(reader); s = s.Replace(".mp3", ".wav"); //WaveFileWriter.CreateWaveFile(s, pcmStream); //reader.Close(); //pcmStream.Close(); byte[] bs; using (FileStream fs = new FileStream(s, FileMode.Open)) { bs = new byte[fs.Length]; fs.Read(bs, 0, bs.Length); } //new FileInfo(s).Delete(); STREAM[name] = new MemoryStream(bs); BUFFER[name] = new SecondaryBuffer(STREAM[name], DEVICE); } BUFFER[name].SetCurrentPosition(0); BUFFER[name].Play(0, playflags); }
public void Play(int priority, BufferPlayFlags flags) { throw new NotImplementedException(); }