示例#1
0
 public void DifferentStartPlaying()
 {
     if (_enum10 == AudioStatus.IsCurrentlyPlayingAudio)
     {
         method_0();
         return;
     }
     if (_enum10 == AudioStatus.ShouldStopAudio)
     {
         method_9();
         method_2(5);
         _long0 = 0L;
         _int2  = 0;
         _secondaryBuffer0.SetCurrentPosition(0);
         method_4();
         for (var i = 0; i < 5; i++)
         {
             method_7();
         }
         _secondaryBuffer0.SetCurrentPosition(0);
         _secondaryBuffer0.Volume = 0;
         _secondaryBuffer0.Play(0, BufferPlayFlags.Looping);
         _enum10 = AudioStatus.ShouldStartAudio;
     }
 }
示例#2
0
        /// <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 { }
        }
示例#3
0
		/// <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 { }
		}
示例#4
0
 public OggOutput(GenericAudioStream stream11, Device device1, int int5)
 {
     _stream10 = new Stream4(stream11, 16);
     _int1     = _stream10.vmethod_0().method_0(int5);
     _int1    -= _int1 % 5;
     _int0     = _int1 / 5;
     _double0  = _stream10.vmethod_0().int_0 *(double)_stream10.vmethod_0().short_1 / 1000.0;
     _byte0    = new byte[_int0];
     _device0  = device1;
     if (_device0 == null)
     {
         _device0 = new Device();
         _device0.SetCooperativeLevel(GetDesktopWindow(), CooperativeLevel.Normal);
         _bool0 = true;
     }
     _secondaryBuffer0 = new SecondaryBuffer(new BufferDescription
     {
         BufferBytes           = _int1,
         ControlPositionNotify = true,
         CanGetCurrentPosition = true,
         ControlVolume         = true,
         GlobalFocus           = true,
         StickyFocus           = true,
         Format = smethod_0(_stream10.vmethod_0())
     }, _device0);
     _secondaryBuffer0.SetCurrentPosition(0);
     _int2 = 0;
     _secondaryBuffer0.Volume = 0;
     _autoResetEvent0         = new AutoResetEvent(false);
     _bufferPositionNotify1[0].EventNotifyHandle = _autoResetEvent0.Handle;
     _enum10 = AudioStatus.ShouldStopAudio;
 }
        public StreamingSoundBuffer(Device device, WaveFormat format, ISoundDataProvider provider)
        {
            NextID++;

            this.device   = device;
            this.provider = provider;

            BufferDescription description = new BufferDescription(format);

            description.BufferBytes           = BufferSize;
            description.ControlPositionNotify = true;
            description.CanGetCurrentPosition = true;
            description.ControlVolume         = true;
            description.LocateInHardware      = false;
            description.LocateInSoftware      = true;
            description.GlobalFocus           = false;
            description.StickyFocus           = false;

            try
            {
                buffer = new SecondaryBuffer(description, device);
                buffer.SetCurrentPosition(0);
                buffer.Volume = 0;
            }
            catch (Exception ex)
            {
                if (buffer != null)
                {
                    buffer.Dispose();
                }
                throw new SoundSystemException(ex, "Failed to create SecondaryBuffer ID {0}.", NextID);
            }

            notifier    = new Notify(buffer);
            notifyEvent = new AutoResetEvent(false);
            BufferPositionNotify[] notifications = new BufferPositionNotify[Notifications];
            for (int i = 0; i < Notifications; i++)
            {
                if (notifyEvent.SafeWaitHandle.IsClosed || notifyEvent.SafeWaitHandle.IsInvalid)
                {
                    throw new SoundSystemException("SecondaryBuffer ID {0} notifier handle was closed or invalid.", NextID);
                }
                else
                {
                    notifications[i].EventNotifyHandle = notifyEvent.SafeWaitHandle.DangerousGetHandle();
                    notifications[i].Offset            = SectorSize * i - 1;
                }
            }
            notifier.SetNotificationPositions(notifications, Notifications);

            data = provider.GetNextChunk();
            FillData();
            FillData(); // do this twice, to have a 370 or so ms lead, in case something were to happen

            dataManager          = new Thread(new ThreadStart(DataStream));
            dataManager.Name     = "Prometheus Sound Stream #" + NextID.ToString();
            dataManager.Priority = ThreadPriority.AboveNormal;
            dataManager.Start(); // must lock buffer from now on
        }
 public void Resume()
 {
     if (_buffer != null)
     {
         _buffer.SetCurrentPosition(_currentPosition);
         _buffer.Play(0, BufferPlayFlags.Default);
     }
 }
示例#7
0
 private void play(SecondaryBuffer input, int volume)
 {
     if (input != null)
     {
         input.Stop();
         input.SetCurrentPosition(0);
         input.Volume = volume;
         input.Play(0, BufferPlayFlags.Default);
     }
 }
示例#8
0
        public void Explosion()
        {
            if (explosion == null)
            {
                return;
            }

            explosion.SetCurrentPosition(0);
            explosion.Play(0, BufferPlayFlags.Default);
        }
示例#9
0
 private void buttonStop_Click(object sender, System.EventArgs e)
 {
     if (null != applicationBuffer)
     {
         textStatus.Text = "Sound stopped.";
         EnablePlayUI(true);
         applicationBuffer.Stop();
         applicationBuffer.SetCurrentPosition(0);
     }
 }
示例#10
0
 public bool Resume()
 {
     // returns if resume action was successful
     if (buffer != null)
     {
         buffer.SetCurrentPosition(m_lastPlayingPosition);
         buffer.Play(0, BufferPlayFlags.Looping);
         return(true);
     }
     return(false);
 }
示例#11
0
        public void SoundDeath()
        {
            if (soundDeath == null)
            {
                return;
            }

            if (!soundDeath.Status.Playing)
            {
                soundDeath.SetCurrentPosition(0);
                soundDeath.Play(0, BufferPlayFlags.Default);
            }
        }
        private void LoadSoundFile()
        {
            BufferDescription description = new BufferDescription();

            description.Guid3DAlgorithm  = DSoundHelper.Guid3DAlgorithmHrtfLight;
            description.Control3D        = true;
            description.ControlFrequency = true;
            description.ControlVolume    = true;

            if (null != soundBuffer)
            {
                soundBuffer.Stop();
                soundBuffer.SetCurrentPosition(0);
            }

            // Load the wave file into a DirectSound buffer
            try
            {
                soundBuffer   = new SecondaryBuffer(m_FileName, description, Listener.Device);
                soundBuffer3D = new Buffer3D(soundBuffer);
            }
            catch (Exception e)
            {
                GameEngine.Console.AddLine("Exception on loading " + m_FileName + ". Ensure file is Mono");
                GameEngine.Console.AddLine(e.Message);
            }

            if (WaveFormatTag.Pcm != (WaveFormatTag.Pcm & description.Format.FormatTag))
            {
                GameEngine.Console.AddLine("Wave file must be PCM for 3D control.");
                if (null != soundBuffer)
                {
                    soundBuffer.Dispose();
                }
                soundBuffer = null;
            }
        }
示例#13
0
 /// <summary>Plays a sound from the sound bank.</summary>
 /// <param name="track">Sound to play.</param>
 public void PlayAudioTrack(AudioTrack track)
 {
     if (device != null && !(audioProperties.MuteAll || audioProperties.MuteSoundEffects))
     {
         SecondaryBuffer buffer = secondaryBuffers[(int)track - 1];
         try {
             if (buffer.Status.BufferLost)
             {
                 restoreSoundBuffers();
                 buffer = secondaryBuffers[(int)track - 1];
             }
             buffer.SetCurrentPosition(0);
             buffer.Play(0, BufferPlayFlags.Default);
         } catch (Exception) {}
     }
 }
示例#14
0
        private void button1_Click(object sender, System.EventArgs e)
        {
            if (spc != null || snd != null)
            {
                Device            dev  = getDev();
                BufferDescription desc = new BufferDescription(WavFile.getFormat());
                desc.ControlVolume = true;
                desc.Flags         = BufferDescriptionFlags.ControlVolume;
                byte[] raw = snd == null?spc.getWave().rawBytes() : snd.getWave().rawBytes();

                desc.BufferBytes = raw.Length;
                SecondaryBuffer buf = new SecondaryBuffer(desc, dev);
                buf.Write(0, raw, LockFlag.EntireBuffer);
                buf.SetCurrentPosition(0);
                buf.Volume = 0;
                buf.Play(0, BufferPlayFlags.Default);
            }
        }
示例#15
0
文件: Sounds.cs 项目: uotools/PlayUO
 public void PlaySound(int SoundID, int X, int Y, int Z, float Volume)
 {
     if ((m_Device != null) && this.m_Enabled)
     {
         SoundID &= 0xfff;
         SoundCache cache = m_Cache[SoundID];
         if (cache == null)
         {
             cache = m_Cache[SoundID] = new SoundCache(SoundID);
         }
         try
         {
             SecondaryBuffer buffer = cache.GetBuffer(this);
             if (buffer != null)
             {
                 Mobile player = World.Player;
                 if ((((X == -1) && (Y == -1)) && (Z == -1)) || (player == null))
                 {
                     try
                     {
                         buffer.set_Pan(0);
                     }
                     catch
                     {
                     }
                     try
                     {
                         buffer.set_Volume(-10000 + (this.ScaledVolume * 100));
                     }
                     catch
                     {
                     }
                 }
                 else
                 {
                     int num  = Math.Abs((int)((X - player.X) * 11));
                     int num2 = Math.Abs((int)((Y - player.Y) * 11));
                     int num3 = Math.Abs((int)(Z - player.Z));
                     int num4 = (int)Math.Sqrt((double)(((num * num) + (num2 * num2)) + (num3 * num3)));
                     int num5 = (X - Y) - (player.X - player.Y);
                     num5 *= 350;
                     num4 *= 10;
                     num4  = -num4;
                     num4 -= (int)(5000f * (1f - Volume));
                     int scaledVolume = this.ScaledVolume;
                     num4 = ((-10000 * (100 - scaledVolume)) + (num4 * scaledVolume)) / 100;
                     if (num4 > 0)
                     {
                         num4 = 0;
                     }
                     else if (num4 < -10000)
                     {
                         num4 = -10000;
                     }
                     if (num5 > 0x2710)
                     {
                         num5 = 0x2710;
                     }
                     else if (num5 < -10000)
                     {
                         num5 = -10000;
                     }
                     try
                     {
                         buffer.set_Pan(num5);
                     }
                     catch
                     {
                     }
                     try
                     {
                         buffer.set_Volume(num4);
                     }
                     catch
                     {
                     }
                 }
                 buffer.SetCurrentPosition(0);
                 buffer.Play(0, 0);
             }
         }
         catch (Exception exception)
         {
             Debug.Error(exception);
         }
     }
 }
示例#16
0
 public void Play(byte[] buffer, int pos)
 {
     SetBuffer(buffer);
     _sound.SetCurrentPosition(pos);
     _sound.Play(0, BufferPlayFlags.Default);
 }
示例#17
0
 public void Stop()
 {
     _buffer.Stop();
     _buffer.SetCurrentPosition(0);
     Engine.Audio.Unregister3dSound(this);
 }
示例#18
0
        public PlayerClass(AudioBookConverterMain Caller, string filename)
        {
            if (GetSourceExt(filename) != "mp3")
            {
                return;
            }
            file   = filename;
            Parent = Caller;
            Microsoft.DirectX.DirectSound.WaveFormat format = new Microsoft.DirectX.DirectSound.WaveFormat();

            WmaStream wmastr = new WmaStream(filename);

            format.BlockAlign            = wmastr.Format.nBlockAlign;
            format.Channels              = wmastr.Format.nChannels;
            format.SamplesPerSecond      = wmastr.Format.nSamplesPerSec;
            format.BitsPerSample         = wmastr.Format.wBitsPerSample;
            format.AverageBytesPerSecond = format.BlockAlign * format.SamplesPerSecond;
            wmastr.Dispose();

            BufferDescription desc = new BufferDescription(format);

            desc.ControlPan            = true;
            desc.GlobalFocus           = true;
            desc.BufferBytes           = 262144;
            desc.ControlPositionNotify = true;
            desc.CanGetCurrentPosition = true;
            desc.ControlVolume         = true;
            desc.StickyFocus           = true;
            desc.LocateInSoftware      = true;
            desc.ControlEffects        = false;
            desc.LocateInHardware      = false;
            desc.Control3D             = false;
            //MemoryStream bufferstream = new MemoryStream(262144);

            Device device = new Device();

            device.SetCooperativeLevel(Parent, CooperativeLevel.Priority);

            sound = new SecondaryBuffer(desc, device);
            sound.SetCurrentPosition(1);
            sound.Volume = 0;
            sound.Pan    = 0;

            BufferNotificationEvent = new AutoResetEvent(false);
            BufferNotify            = new Notify(sound);

            BufferPositionNotify[] BufferPositions = new BufferPositionNotify[2];

            BufferPositions[0].Offset            = 0;
            BufferPositions[0].EventNotifyHandle = BufferNotificationEvent.Handle;
            BufferPositions[1].Offset            = (desc.BufferBytes / 2);
            BufferPositions[1].EventNotifyHandle = BufferNotificationEvent.Handle;


            BufferNotify.SetNotificationPositions(BufferPositions);

            DataTransferThread = new Thread(new ThreadStart(WMDataFill));
            //if (GetSourceExt(filename) =="mp4") DataTransferThread = new Thread(new ThreadStart(FaadDataFill));
            //if (GetSourceExt(filename) =="flac") DataTransferThread = new Thread(new ThreadStart(FlacDataFill));
            //if (GetSourceExt(filename) =="ogg") DataTransferThread = new Thread(new ThreadStart(OggDataFill));
            DataTransferThread.Name     = "BufferFill";
            DataTransferThread.Priority = ThreadPriority.Highest;
            DataTransferThread.Start();
        }
示例#19
0
    bool OpenSoundFile()
    {
        //-----------------------------------------------------------------------------
        // Name: OnOpenSoundFile()
        // Desc: Called when the user requests to open a sound file
        //-----------------------------------------------------------------------------

        OpenFileDialog ofd             = new OpenFileDialog();
        Guid           guid3DAlgorithm = Guid.Empty;

        // Get the default media path (something like C:\WINDOWS\MEDIA)
        if (string.Empty == Path)
        {
            Path = Environment.SystemDirectory.Substring(0, Environment.SystemDirectory.LastIndexOf("\\")) + "\\media";
        }

        ofd.DefaultExt       = ".wav";
        ofd.Filter           = "Wave Files|*.wav|All Files|*.*";
        ofd.FileName         = FileName;
        ofd.InitialDirectory = Path;

        if (null != applicationBuffer)
        {
            applicationBuffer.Stop();
            applicationBuffer.SetCurrentPosition(0);
        }

        // Update the UI controls to show the sound as loading a file
        buttonPlay.Enabled = buttonStop.Enabled = false;
        labelStatus.Text   = "Loading file...";

        // Display the OpenFileName dialog. Then, try to load the specified file
        if (DialogResult.Cancel == ofd.ShowDialog(this))
        {
            labelStatus.Text      = "Load aborted.";
            timerMovement.Enabled = true;
            return(false);
        }
        FileName = ofd.FileName;
        Path     = ofd.FileName.Substring(0, ofd.FileName.LastIndexOf("\\"));

        // Free any previous sound, and make a new one
        if (null != applicationBuffer)
        {
            applicationBuffer.Dispose();
            applicationBuffer = null;
        }

        // Get the software DirectSound3D emulation algorithm to use
        // Ask the user for this sample, so display the algorithm dialog box.
        AlgorithmForm frm = new AlgorithmForm();

        if (DialogResult.Cancel == frm.ShowDialog(this))
        {
            // User canceled dialog box
            labelStatus.Text   = "Load aborted.";
            labelFilename.Text = string.Empty;
            return(false);
        }

        LoadSoundFile(ofd.FileName);
        if (null == applicationBuffer)
        {
            return(false);
        }

        // Get the 3D buffer from the secondary buffer
        try
        {
            applicationBuffer3D = new Buffer3D(applicationBuffer);
        }
        catch (DirectXException)
        {
            labelStatus.Text   = "Could not get 3D buffer.";
            labelFilename.Text = string.Empty;
            return(false);
        }

        // Get the 3D buffer parameters
        application3DSettings = applicationBuffer3D.AllParameters;

        // Set new 3D buffer parameters
        application3DSettings.Mode        = Mode3D.HeadRelative;
        applicationBuffer3D.AllParameters = application3DSettings;

        if (true == applicationBuffer.Caps.LocateInHardware)
        {
            labelStatus.Text = "File loaded using hardware mixing.";
        }
        else
        {
            labelStatus.Text = "File loaded using software mixing.";
        }

        // Update the UI controls to show the sound as the file is loaded
        labelFilename.Text = FileName;
        EnablePlayUI(true);

        // Remember the file for next time
        if (null != applicationBuffer3D)
        {
            FileName = ofd.FileName;
        }
        Path = FileName.Substring(0, FileName.LastIndexOf("\\"));

        // Set the slider positions
        SetSlidersPos(0.0f, 0.0f, maxOrbitRadius, maxOrbitRadius * 2.0f);
        SliderChanged();
        return(true);
    }
示例#20
0
 public static void Play(string name)
 {
     if (!PlaySound) return;
     /*BUFFER[name].Stop();
     BUFFER[name].SetCurrentPosition(0);
     BUFFER[name].Play(0, BufferPlayFlags.Default);*/
     STREAM[name].Position = 0;
     SecondaryBuffer buffer = new SecondaryBuffer(STREAM[name], DEVICE);
     buffer.Stop();
     buffer.SetCurrentPosition(0);
     buffer.Play(0, BufferPlayFlags.Default);
     BUFFER_POOL.Add(new MyBuffer(buffer));
 }
示例#21
0
 private void button1_Click(object sender, System.EventArgs e)
 {
     if (spc != null || snd!=null)
     {
         Device dev = getDev();
         BufferDescription desc = new BufferDescription(WavFile.getFormat());
         desc.ControlVolume = true;
         desc.Flags = BufferDescriptionFlags.ControlVolume;
         byte[] raw = snd==null?spc.getWave().rawBytes():snd.getWave().rawBytes();
         desc.BufferBytes = raw.Length;
         SecondaryBuffer buf = new SecondaryBuffer(desc, dev);
         buf.Write(0, raw, LockFlag.EntireBuffer);
         buf.SetCurrentPosition(0);
         buf.Volume = 0;
         buf.Play(0, BufferPlayFlags.Default);
     }
 }