コード例 #1
0
        private void PlatformPlay()
        {
            SourceId    = 0;
            HasSourceId = false;
            SourceId    = controller.ReserveSource();
            HasSourceId = true;

            int bufferId = _effect.SoundBuffer.OpenALDataBuffer;

            AL.Source(SourceId, ALSourcei.Buffer, bufferId);
            ALHelper.CheckError("Failed to bind buffer to source.");

            // Send the position, gain, looping, pitch, and distance model to the OpenAL driver.
            if (!HasSourceId)
            {
                return;
            }

            AL.Source(SourceId, ALSourcei.SourceRelative, 1);
            ALHelper.CheckError("Failed set source relative.");
            // Distance Model
            AL.DistanceModel(ALDistanceModel.InverseDistanceClamped);
            ALHelper.CheckError("Failed set source distance.");
            // Pan
            AL.Source(SourceId, ALSource3f.Position, _pan, 0f, 0f);
            ALHelper.CheckError("Failed to set source pan.");
            // Velocity
            AL.Source(SourceId, ALSource3f.Velocity, 0f, 0f, 0f);
            ALHelper.CheckError("Failed to set source pan.");
            // Volume
            AL.Source(SourceId, ALSourcef.Gain, _alVolume);
            ALHelper.CheckError("Failed to set source volume.");
            // Looping
            AL.Source(SourceId, ALSourceb.Looping, IsLooped);
            ALHelper.CheckError("Failed to set source loop state.");
            // Pitch
            AL.Source(SourceId, ALSourcef.Pitch, XnaPitchToAlPitch(_pitch));
            ALHelper.CheckError("Failed to set source pitch.");

            ApplyReverb();
            ApplyFilter();

            AL.SourcePlay(SourceId);
            ALHelper.CheckError("Failed to play source.");

            SoundState = SoundState.Playing;
        }
コード例 #2
0
        public virtual void Play()
        {
            int bufferId = soundBuffer.OpenALDataBuffer;

            if (hasSourceId)
            {
                return;
            }
            bool isSourceAvailable = controller.ReserveSource(soundBuffer);

            if (!isSourceAvailable)
            {
                return;
            }

            AL.Source(soundBuffer.SourceId, ALSourcei.Buffer, bufferId);
            ApplyState();

            controller.PlaySound(soundBuffer);
            //Console.WriteLine ("playing: " + sourceId + " : " + soundEffect.Name);
            soundState = SoundState.Playing;
        }
コード例 #3
0
        private void PlatformPlay()
        {
            if (hasSourceId)
            {
                return;
            }

            bool isSourceAvailable = controller.ReserveSource(soundBuffer);

            if (!isSourceAvailable)
            {
                throw new InstancePlayLimitException();
            }

            int bufferId = soundBuffer.OpenALDataBuffer;

            AL.Source(soundBuffer.SourceId, ALSourcei.Buffer, bufferId);

            // Send the position, gain, looping, pitch, and distance model to the OpenAL driver.
            if (!hasSourceId)
            {
                return;
            }

            // Distance Model
            AL.DistanceModel(ALDistanceModel.InverseDistanceClamped);
            // Pan
            AL.Source(sourceId, ALSource3f.Position, _pan, 0, 0.1f);
            // Volume
            AL.Source(sourceId, ALSourcef.Gain, _volume * SoundEffect.MasterVolume);
            // Looping
            AL.Source(sourceId, ALSourceb.Looping, IsLooped);
            // Pitch
            AL.Source(sourceId, ALSourcef.Pitch, XnaPitchToAlPitch(_pitch));

            controller.PlaySound(soundBuffer);
            //Console.WriteLine ("playing: " + sourceId + " : " + soundEffect.Name);
            soundState = SoundState.Playing;
        }
コード例 #4
0
        private void PlatformPlay()
        {
            SourceId    = 0;
            HasSourceId = false;
            SourceId    = controller.ReserveSource();
            HasSourceId = true;

            int bufferId = _effect.SoundBuffer.OpenALDataBuffer;

            AL.Source(SourceId, ALSourcei.Buffer, bufferId);
            ALHelper.CheckError("Failed to bind buffer to source.");

            // Send the position, gain, looping, pitch, and distance model to the OpenAL driver.
            if (!HasSourceId)
            {
                return;
            }

            // Distance Model
            AL.DistanceModel(ALDistanceModel.InverseDistanceClamped);
            ALHelper.CheckError("Failed set source distance.");
            // Pan
            AL.Source(SourceId, ALSource3f.Position, _pan, 0, 0.1f);
            ALHelper.CheckError("Failed to set source pan.");
            // Volume
            AL.Source(SourceId, ALSourcef.Gain, _alVolume);
            ALHelper.CheckError("Failed to set source volume.");
            // Looping
            AL.Source(SourceId, ALSourceb.Looping, IsLooped);
            ALHelper.CheckError("Failed to set source loop state.");
            // Pitch
            AL.Source(SourceId, ALSourcef.Pitch, XnaPitchToAlPitch(_pitch));
            ALHelper.CheckError("Failed to set source pitch.");

            controller.PlaySound(this);
            //Console.WriteLine ("playing: " + sourceId + " : " + soundEffect.Name);
            SoundState = SoundState.Playing;
        }
コード例 #5
0
        /// <summary>
        /// Internal implementation of Play that returns false on failure. See comments on Play for workings.
        /// </summary>
        internal bool TryPlay()
        {
            if (hasSourceId)
            {
                return(true);
            }
            bool isSourceAvailable = controller.ReserveSource(soundBuffer);

            if (!isSourceAvailable)
            {
                return(false);
            }

            int bufferId = soundBuffer.OpenALDataBuffer;

            AL.Source(soundBuffer.SourceId, ALSourcei.Buffer, bufferId);
            ApplyState();

            controller.PlaySound(soundBuffer);
            //Console.WriteLine ("playing: " + sourceId + " : " + soundEffect.Name);
            soundState = SoundState.Playing;

            return(true);
        }