Esempio n. 1
0
        public void PlaySound(int channel, ResourceSound sound, float volume)
        {
            if (channel == 0)   //First available channel
            {
                for (int i = 0; i < _channels.Length; i++)
                {
                    if (_channels[i] == null)
                    {
                        channel = i;
                        break;
                    }
                }

                if (channel == 0)
                {
                    return;
                }
            }

            StopChannel(channel);

            ISampleProvider sampleProvider = sound.Play(volume);

            _channels[channel - 1] = new DreamSoundChannel(sound, sampleProvider);
        }
Esempio n. 2
0
        public void PlaySound(int channel, ResourceSound sound, float volume)
        {
            if (channel == 0)
            {
                //First available channel
                for (int i = 0; i < _channels.Length; i++)
                {
                    if (_channels[i] == null || !_channels[i].Source.IsPlaying)
                    {
                        _channels[i]?.Dispose();
                        channel = i + 1;
                        break;
                    }
                }

                if (channel == 0)
                {
                    return;
                }
            }

            StopChannel(channel);

            // convert from DM volume (0-100) to OpenAL volume (db)
            IClydeAudioSource source = sound.Play(AudioParams.Default.WithVolume(20 * MathF.Log10(volume)));

            _channels[channel - 1] = new DreamSoundChannel(source);
        }
Esempio n. 3
0
 public void StopChannel(int channel)
 {
     if (_channels[channel - 1] != null)
     {
         ref DreamSoundChannel ch = ref _channels[channel - 1];
         ch.Dispose();
         // This will null the corresponding index in the array.
         ch = null;
     }