Example #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);
        }
Example #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);
        }