Exemple #1
0
 /// <summary>Stops the specified sound source.</summary>
 /// <param name="source">The sound source, or a null reference.</param>
 public void StopSound(SoundSource source)
 {
     if (source != null)
     {
         if (source.State == SoundSourceState.Playing)
         {
             AL.DeleteSources(1, ref source.OpenAlSourceName);
             source.OpenAlSourceName = 0;
         }
         source.State = SoundSourceState.Stopped;
     }
 }
Exemple #2
0
 /// <summary>Plays the sound at the specified pitch and volume</summary>
 /// <param name="pitch">The pitch</param>
 /// <param name="volume">The volume</param>
 /// <param name="Car">The parent car</param>
 /// <param name="looped">Whether the sound is to be played looped</param>
 public void Play(double pitch, double volume, AbstractCar Car, bool looped)
 {
     if (Buffer != null)
     {
         if (SoundsBase.Sources.Length == SoundsBase.SourceCount)
         {
             Array.Resize(ref SoundsBase.Sources, SoundsBase.Sources.Length << 1);
         }
         SoundsBase.Sources[SoundsBase.SourceCount] = new SoundSource(Buffer, Buffer.Radius, pitch, volume, Position, Car, looped);
         this.Source = SoundsBase.Sources[SoundsBase.SourceCount];
         SoundsBase.SourceCount++;
     }
 }
Exemple #3
0
        // --- tests ---

        /// <summary>Checks whether the specified sound is playing or supposed to be playing.</summary>
        /// <param name="Source">The sound source, or a null reference.</param>
        /// <returns>Whether the sound is playing or supposed to be playing.</returns>
        public bool IsPlaying(object Source)
        {
            SoundSource source = Source as SoundSource;

            if (source != null)
            {
                if (source.State == SoundSourceState.PlayPending | source.State == SoundSourceState.Playing)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #4
0
 /// <summary>Plays a sound.</summary>
 /// <param name="buffer">The sound buffer.</param>
 /// <param name="pitch">The pitch change factor.</param>
 /// <param name="volume">The volume change factor.</param>
 /// <param name="position">The position. If a train car is specified, the position is relative to the car, otherwise absolute.</param>
 /// <param name="looped">Whether to play the sound in a loop.</param>
 /// <returns>The sound source.</returns>
 public SoundSource PlaySound(SoundHandle buffer, double pitch, double volume, OpenBveApi.Math.Vector3 position, bool looped)
 {
     if (buffer is SoundBuffer)
     {
         SoundBuffer b = (SoundBuffer)buffer;
         if (Sources.Length == SourceCount)
         {
             Array.Resize(ref Sources, Sources.Length << 1);
         }
         Sources[SourceCount] = new SoundSource(b, b.Radius, pitch, volume, position, null, looped);
         SourceCount++;
         return(Sources[SourceCount - 1]);
     }
     throw new NotSupportedException();
 }
Exemple #5
0
 /// <summary>Creates a new empty car sound</summary>
 public CarSound()
 {
     this.Position = Vector3.Zero;
     this.Source   = null;
     this.Buffer   = null;
 }
Exemple #6
0
 /// <summary>Creates a new car sound</summary>
 /// <param name="buffer">The sound buffer</param>
 /// <param name="Position">The position that the sound is emitted from within the car</param>
 /// <returns>The new car sound</returns>
 public CarSound(SoundBuffer buffer, Vector3 Position)
 {
     this.Position = Position;
     this.Source   = null;
     this.Buffer   = buffer;
 }
Exemple #7
0
 /// <summary>Creates a new car sound</summary>
 /// <param name="handle">The API handle to the sound buffer</param>
 /// <param name="Position">The position that the sound is emitted from within the car</param>
 /// <returns>The new car sound</returns>
 public CarSound(SoundHandle handle, Vector3 Position)
 {
     this.Buffer   = handle as SoundBuffer;
     this.Position = Position;
     this.Source   = null;
 }
Exemple #8
0
 public SoundSourceAttenuation(SoundSource source, double gain, double distance)
 {
     Source   = source;
     Gain     = gain;
     Distance = distance;
 }