public override Sound SoundCreate(VirtualFileStream stream, bool closeStreamAfterReading,
                                          SoundType soundType, SoundMode mode)
        {
            criticalSection.Enter();

            DirectSound sound;
            bool        initialized;

            if ((int)(mode & SoundMode.Stream) == 0)
            {
                sound = new DirectSampleSound(stream, soundType, null, mode, out initialized);
                if (closeStreamAfterReading)
                {
                    stream.Close();
                }
            }
            else
            {
                sound = new DirectFileStreamSound(stream, closeStreamAfterReading, soundType, null,
                                                  mode, out initialized);
            }

            if (!initialized)
            {
                sound.Dispose();
                sound = null;
            }

            criticalSection.Leave();

            return(sound);
        }
Exemple #2
0
        public void Dispose()
        {
            streamGCHandle.Free();

            if (needCloseStream && stream != null)
            {
                stream.Close();
                needCloseStream = false;
            }
            stream = null;
        }
        public override Sound SoundCreate(string name, SoundMode mode)
        {
            criticalSection.Enter();

            DirectSound sound;

            sound = (DirectSound)base.SoundCreate(name, mode);
            if (sound != null)
            {
                criticalSection.Leave();
                return(sound);
            }

            VirtualFileStream stream = CreateFileStream(name);

            if (stream == null)
            {
                criticalSection.Leave();
                DirectSoundWorld.Warning(string.Format("Creating sound \"{0}\" failed.", name));
                return(null);
            }

            bool initialized;

            if ((int)(mode & SoundMode.Stream) == 0)
            {
                sound = new DirectSampleSound(stream, SoundType.Unknown, name,
                                              mode, out initialized);
                stream.Close();
            }
            else
            {
                sound = new DirectFileStreamSound(stream, true, SoundType.Unknown,
                                                  name, mode, out initialized);
            }

            if (!initialized)
            {
                sound.Dispose();
                sound = null;
            }

            criticalSection.Leave();

            return(sound);
        }
Exemple #4
0
		public override Sound SoundCreate( VirtualFileStream stream, bool closeStreamAfterReading,
			SoundType soundType, SoundMode mode )
		{
			criticalSection.Enter();

			DirectSound sound;
			bool initialized;

			if( (int)( mode & SoundMode.Stream ) == 0 )
			{
				sound = new DirectSampleSound( stream, soundType, null, mode, out initialized );
				if( closeStreamAfterReading )
					stream.Close();
			}
			else
			{
				sound = new DirectFileStreamSound( stream, closeStreamAfterReading, soundType, null,
					mode, out initialized );
			}

			if( !initialized )
			{
				sound.Dispose();
				sound = null;
			}

			criticalSection.Leave();

			return sound;
		}