예제 #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);
        }
예제 #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);
        }
예제 #3
0
        public void PlaySound(int channel, ResourceSound sound)
        {
            NAudioSoundEngineData nAudioData = CreateSoundEngineData(sound) as NAudioSoundEngineData;

            if (nAudioData != null)
            {
                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);

                _channels[channel - 1] = nAudioData;
                nAudioData.WaveReader.Seek(0, System.IO.SeekOrigin.Begin);
                nAudioData.OutputDevice.Play();
            }
        }
예제 #4
0
 private NAudioSoundEngineData CreateSoundEngineData(ResourceSound sound)
 {
     return(new NAudioSoundEngineData(sound.Data));
 }