/// <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); } // 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(); } this.playing = soundEffect; return(true); }
/// <summary> /// Gets the exception message for the current error code. /// </summary> /// <returns>The exception message for the current error code.</returns> private static String GetExceptionMessage() { return(GetExceptionMessage(BASSNative.ErrorGetCode())); }