/// <summary>
        /// Plays a sound effect.
        /// </summary>
        /// <param name="soundEffect">The sound effect to play.</param>
        /// <param name="volume">A value from 0.0 (silent) to 1.0 (full volume) representing the sound effect's volume.</param>
        /// <param name="pitch">A value from -1.0 (down one octave) to 1.0 (up one octave) indicating the sound effect's pitch adjustment.</param>
        /// <param name="pan">A value from -1.0 (full left) to 1.0 (full right) representing the sound effect's panning position.</param>
        /// <param name="loop">A value indicating whether to loop the sound effect.</param>
        /// <returns>true if the sound effect began playing successfully; otherwise, false.</returns>
        public override Boolean Play(SoundEffect soundEffect, Single volume, Single pitch, Single pan, Boolean loop = false)
        {
            Contract.EnsureNotDisposed(this, Disposed);

            return PlayInternal(soundEffect, volume, pitch, pan, loop);
        }
        /// <summary>
        /// Plays a sound effect.
        /// </summary>
        /// <param name="soundEffect">The sound effect to play.</param>
        /// <param name="loop">A value indicating whether to loop the sound effect.</param>
        /// <returns>true if the sound effect began playing successfully; otherwise, false.</returns>
        public override Boolean Play(SoundEffect soundEffect, Boolean loop = false)
        {
            Contract.EnsureNotDisposed(this, Disposed);

            return PlayInternal(soundEffect, 1f, 0f, 0f, loop);
        }
        /// <summary>
        /// Plays a sound effect.
        /// </summary>
        private Boolean PlayInternal(SoundEffect soundEffect, Single volume, Single pitch, Single pan, Boolean loop = false)
        {
            Contract.EnsureNotDisposed(this, Disposed);

            // Stop any sound that's already playing.
            Stop();

            // Retrieve the sample data from the sound effect.
            Ultraviolet.ValidateResource(soundEffect);
            var bassfx = (BASSSoundEffect)soundEffect;
            var sample = bassfx.GetSampleData(out this.sampleData, out this.sampleInfo);

            // Get a channel on which to play the sample.
            channel = BASSNative.SampleGetChannel(sample, true);
            if (!BASSUtil.IsValidHandle(channel))
            {
                var error = BASSNative.ErrorGetCode();
                if (error == BASSNative.BASS_ERROR_NOCHAN)
                {
                    return false;
                }
                throw new BASSException(error);
            }
            bassfx.SampleFreed += HandleSampleFreed;

            // Set the channel's attributes.
            if (pitch == 0)
            {
                BASSUtil.SetIsLooping(channel, loop);
                BASSUtil.SetVolume(channel, MathUtil.Clamp(volume, 0f, 1f));
                BASSUtil.SetPan(channel, MathUtil.Clamp(pan, -1f, 1f));
            }
            else
            {
                PromoteToStream(volume, MathUtil.Clamp(pitch, -1f, 1f), pan, loop);
            }

            // Play the channel.
            if (!BASSNative.ChannelPlay(channel, true))
                throw new BASSException();
            return true;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Releases any BASS resources being held by the player.
        /// </summary>
        private void Release()
        {
            if (stream != 0)
            {
                if (!BASSNative.StreamFree(stream))
                    throw new BASSException();

                stream = 0;
            }

            if (sample != 0)
            {
                if (!BASSNative.SampleFree(sample))
                    throw new BASSException();

                sample = 0;
            }

            channel = 0;
            promoted = false;
            playing = null;
        }
Exemplo n.º 5
0
 /// <summary>
 /// Plays a <see cref="SoundEffect"/>.
 /// </summary>
 /// <param name="soundEffect">The <see cref="SoundEffect"/> to play.</param>
 /// <param name="volume">A value from 0.0 (silent) to 1.0 (full volume) representing the sound effect's volume.</param>
 /// <param name="pitch">A value from -1.0 (down one octave) to 1.0 (up one octave) indicating the sound effect's pitch adjustment.</param>
 /// <param name="pan">A value from -1.0 (full left) to 1.0 (full right) representing the sound effect's panning position.</param>
 /// <param name="loop">A value indicating whether to loop the sound effect.</param>
 /// <returns><see langword="true"/> if the sound effect began playing successfully; otherwise, <see langword="false"/>.</returns>
 public abstract Boolean Play(SoundEffect soundEffect, Single volume, Single pitch, Single pan, Boolean loop = false);
Exemplo n.º 6
0
 /// <summary>
 /// Plays a <see cref="SoundEffect"/>.
 /// </summary>
 /// <param name="soundEffect">The <see cref="SoundEffect"/> to play.</param>
 /// <param name="loop">A value indicating whether to loop the sound effect.</param>
 /// <returns><see langword="true"/> if the sound effect began playing successfully; otherwise, <see langword="false"/>.</returns>
 public abstract Boolean Play(SoundEffect soundEffect, Boolean loop = false);