Exemplo n.º 1
0
 public void Stop(SoundChannel soundChannel, int fadeDuration)
 {
     if(soundChannel != null && soundChannel.Channel != null) {
         // Sound has to be playing for the volume to be set (fmod rule)
         if(fadeDuration != 0 && soundChannel.IsPlaying ) {
             soundChannel.ImmediateFade(fadeDuration);
             soundChannel.WaitOnFade();
             soundChannel.Channel.stop();
             soundChannel.m_ptimer.Stop();
             soundChannel.CancelFades();
         }
     }
 }
Exemplo n.º 2
0
        private void PlaySound(SoundChannel soundChannel, bool paused)
        {
            if(soundChannel == null || soundChannel.Sound == null) return;

            // Wait for any fade on this channel to finish
            soundChannel.WaitOnFade();

            // Has it ever been run?
            Channel channel = null;
            if(soundChannel.Channel == null) {
                // Never run before
                ERRCHECK(m_system.playSound(FMOD.CHANNELINDEX.FREE, soundChannel.Sound, paused, ref channel));
                soundChannel.Channel = channel;
            } else {
                // Has been run before
                // Is the channel paused?
                bool isPaused = false;
                soundChannel.Channel.getPaused(ref isPaused);
                if (isPaused) {
                    // Paused, unpause it
                    if (!paused) {
                        soundChannel.Channel.setPaused(false);
                    }
                } else {
                    // Not paused, channel was stopped
                    ERRCHECK(m_system.playSound(FMOD.CHANNELINDEX.REUSE, soundChannel.Sound, paused, ref channel));
                    soundChannel.Channel = channel;
                }
            }
        }
Exemplo n.º 3
0
 public void ReleaseSound(SoundChannel soundChannel)
 {
     if(soundChannel != null) {
         if(m_channels.Contains(soundChannel)) {
             m_channels.Remove(soundChannel);
         }
         soundChannel.Dispose();
     }
 }
Exemplo n.º 4
0
 public void Stop(SoundChannel soundChannel)
 {
     if(soundChannel != null && soundChannel.Channel != null) {
         soundChannel.Channel.stop();
         soundChannel.m_ptimer.Stop();
         soundChannel.CancelFades();
     }
 }
Exemplo n.º 5
0
 public void Play(SoundChannel soundChannel)
 {
     if(m_system == null) {
         throw new Exception("Cannot play a sound with no valid sound device");
     }
     PlaySound(soundChannel);
 }
Exemplo n.º 6
0
 public void Play(SoundChannel soundChannel, bool paused)
 {
     PlaySound(soundChannel, paused);
 }
Exemplo n.º 7
0
 private void PlaySound(SoundChannel soundChannel, bool paused)
 {
     if ((soundChannel != null) && (soundChannel.Sound != null))
     {
         soundChannel.WaitOnFade();
         Channel channel = null;
         if (soundChannel.Channel == null)
         {
             this.ERRCHECK(this.m_system.playSound(CHANNELINDEX.FREE, soundChannel.Sound, paused, ref channel));
             soundChannel.Channel = channel;
         }
         else
         {
             bool flag = false;
             soundChannel.Channel.getPaused(ref flag);
             if (flag)
             {
                 if (!paused)
                 {
                     soundChannel.Channel.setPaused(false);
                 }
             }
             else
             {
                 this.ERRCHECK(this.m_system.playSound(CHANNELINDEX.REUSE, soundChannel.Sound, paused, ref channel));
                 soundChannel.Channel = channel;
             }
         }
     }
 }
Exemplo n.º 8
0
 private Audio LoadAudio(string fileName)
 {
     if (fileName == string.Empty) {
         return null;
     }
     try {
         _soundChannel = _fmod.LoadSound(Path.Combine(Paths.AudioPath, fileName), _soundChannel);
     }
     catch (Exception exception) {
         MessageBox.Show(Resources.ErrorLoadingAudio + exception.Message, Vendor.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         return null;
     }
     if (_soundChannel == null) {
         return null;
     }
     _audioFilename = fileName;
     labelAudioFileName.Text = Path.GetFileName(_audioFilename);
     var audio = new Audio {FileName = labelAudioFileName.Text, Name = _soundChannel.SoundName, Duration = (int) _soundChannel.SoundLength};
     labelAudioLength.Text = audio.Duration.FormatFull();
     labelAudioName.Text = string.Format("\"{0}\"", audio.Name);
     UpdateAudioButtons();
     return audio;
 }
Exemplo n.º 9
0
 public void Stop(SoundChannel soundChannel, int fadeDuration)
 {
     if (((soundChannel != null) && (soundChannel.Channel != null)) && ((fadeDuration != 0) && soundChannel.IsPlaying))
     {
         soundChannel.ImmediateFade(fadeDuration);
         soundChannel.WaitOnFade();
         soundChannel.Channel.stop();
         soundChannel.CancelFades();
     }
 }
Exemplo n.º 10
0
 private void PlaySound(SoundChannel soundChannel)
 {
     if (soundChannel.Sound != null)
     {
         soundChannel.WaitOnFade();
         Channel channel = null;
         if (soundChannel.Channel == null)
         {
             this.ERRCHECK(this.m_system.playSound(CHANNELINDEX.FREE, soundChannel.Sound, false, ref channel));
             soundChannel.Channel = channel;
         }
         else if (soundChannel.Paused)
         {
             soundChannel.Paused = false;
         }
         else
         {
             this.ERRCHECK(this.m_system.playSound(CHANNELINDEX.REUSE, soundChannel.Sound, false, ref channel));
             soundChannel.Channel = channel;
         }
     }
 }
Exemplo n.º 11
0
 public void Stop(SoundChannel soundChannel)
 {
     if ((soundChannel != null) && (soundChannel.Channel != null))
     {
         soundChannel.Channel.stop();
         soundChannel.CancelFades();
     }
 }
Exemplo n.º 12
0
 public SoundChannel LoadSound(string fileName, SoundChannel existingChannel)
 {
     if (this.m_system == null)
     {
         return null;
     }
     if (!((fileName != null) && File.Exists(fileName)))
     {
         return null;
     }
     Sound sound = null;
     this.ERRCHECK(this.m_system.createSound(fileName, MODE.ACCURATETIME | MODE._2D | MODE.HARDWARE | MODE.CREATESTREAM,
                                             ref sound));
     if (existingChannel == null)
     {
         existingChannel = new SoundChannel(sound);
         this.m_channels.Add(existingChannel);
     }
     else
     {
         existingChannel.Sound = sound;
     }
     return existingChannel;
 }
Exemplo n.º 13
0
 public void Play(SoundChannel soundChannel, bool paused)
 {
     PlaySound(soundChannel, paused);
 }
Exemplo n.º 14
0
 public void Load(string fileName)
 {
     if (_channel != null && _channel.IsPlaying) {
         Stop();
     }
     _channel = _audioSystem.LoadSound(fileName, _channel);
     if (_channel == null) {
         Logging.Warn("Audio: can't load file '" + fileName + "' for playback. Does it exist?");
     }
     _startTime = TimeSpan.Zero;
 }
Exemplo n.º 15
0
        public SoundChannel LoadSound(string fileName, SoundChannel existingChannel)
        {
            if(m_system == null) return null;

            if(fileName == null || !File.Exists(fileName)) {
                return null;
            }

            Sound sound = null;

            ERRCHECK(m_system.createSound(fileName, (FMOD.MODE._2D | FMOD.MODE.HARDWARE | FMOD.MODE.CREATESTREAM | MODE.ACCURATETIME), ref sound));
            if(existingChannel == null) {
                existingChannel = new SoundChannel(sound);
                m_channels.Add(existingChannel);
            } else {
                existingChannel.Sound = sound;
            }

            return existingChannel;
        }
Exemplo n.º 16
0
        public void LoadAsSample(string fileName)
        {
            //Adapted this code from the fmod wrappers loadsound method. Changed mode to CREATESAMPLE
            if (_channel != null && _channel.IsPlaying) {
                Stop();
            }
            if (_audioSystem == null) return;

            if (fileName == null || !File.Exists(fileName)) {
                return;
            }

            Sound sound = null;
            checkErrors(_audioSystem.SystemObject.createSound(fileName,
                                                              (FMOD.MODE._2D | FMOD.MODE.HARDWARE | FMOD.MODE.CREATESAMPLE |
                                                               MODE.ACCURATETIME), ref sound));
            if (_channel == null) {
                _channel = new SoundChannel(sound);
            }
            else {
                _channel.Sound = sound;
            }
        }
Exemplo n.º 17
0
 private void ClearAudio()
 {
     _eventSequence.Audio = null;
     labelAudioFileName.Text = Resources.NoAudioAssigned;
     labelAudioLength.Text = string.Empty;
     labelAudioName.Text = string.Empty;
     _soundChannel = null;
 }