Beispiel #1
0
		/// <summary>
		/// SubSound constructor
		/// </summary>
		/// <param name="parentSound">The parent Sound of this SubSound</param>
		internal Sound(Sound parentSound)
		{
			if (parentSound != null)
			{
				this.soundSystem = parentSound.SoundSystem;
				this.parentSound = parentSound;
			}
		}
		/// <summary>
		/// Records from audio input to the given sound
		/// </summary>
		/// <param name="sound">The sound to store input audio data to</param>
		/// <param name="loop">Indicates whether or not to loop recording to the beginning of the sound once the end of the sound is reached</param>
		internal void RecordStart(Sound sound, bool loop)
		{
			if (sound != null)
			{
				currentResult = NativeMethods.FMOD_System_RecordStart(handle, sound.Handle, loop);
			}
		}
		internal void PlaySound(ChannelIndex channelId, Sound sound, bool paused, ref Channel channel)
		{
			if (sound != null)
			{
				currentResult = Result.Ok;
				IntPtr channelHandle;			

				bool wasMuted = false;

				if (channel != null)
				{
					channelHandle = channel.Handle;
					wasMuted = channel.Mute;
				}
				else
				{
					channel = new Channel();
					channelHandle = new IntPtr();
				}

				try
				{
					currentResult = NativeMethods.FMOD_System_PlaySound(handle, channelId, sound.Handle, paused, ref channelHandle);
				}
				catch (System.Runtime.InteropServices.ExternalException)
				{
					currentResult = Result.InvalidParameterError;
				}
				
				if (currentResult == Result.Ok)
				{
					channel.Handle = channelHandle;
					
					if (wasMuted)
					{
						channel.Mute = true;
					}
				}
				else
				{
					channel = null;
				}
			}
		}
		internal void CreateStream(Sound sound, string filePath, Modes mode)
		{
			if (sound != null)
			{
				currentResult = Result.Ok;
				IntPtr soundHandle = new IntPtr();

				try
				{
					currentResult = NativeMethods.FMOD_System_CreateStream(handle, filePath, mode, 0, ref soundHandle);
				}
				catch (System.Runtime.InteropServices.ExternalException)
				{
					currentResult = Result.InvalidParameterError;
				}

				if (currentResult == Result.Ok)
				{					
					sound.Handle = soundHandle;
					sound.SoundSystem = this;
				}
				else throw new ApplicationException("could not create stream: " + currentResult.ToString());
			}
			else throw new ArgumentNullException("sound");
		}
		internal Sound CreateStream(string filePath, Modes mode)
		{
			currentResult = Result.Ok;
			IntPtr soundHandle = new IntPtr();
			Sound sound = null;

			try
			{
				currentResult = NativeMethods.FMOD_System_CreateStream(handle, filePath, mode, 0, ref soundHandle);
			}
			catch (System.Runtime.InteropServices.ExternalException)
			{
				currentResult = Result.InvalidParameterError;
			}
			
			if (currentResult == Result.Ok)
			{
				sound = new Sound(this, new Uri(filePath));
				sound.Handle = soundHandle;
				sound.SoundSystem = this;
			}
			else throw new ApplicationException("could not create stream: " + currentResult.ToString());

			return sound;
		}
		internal Sound CreateStream(Sound sound, byte[] data, Modes mode, ref CreateSoundExtendedInfo info)
		{
			if (sound != null)
			{
				currentResult = Result.Ok;
				IntPtr soundHandle = new IntPtr();				

				try
				{
					currentResult = NativeMethods.FMOD_System_CreateStream(handle, data, mode, ref info, ref soundHandle);
				}
				catch (System.Runtime.InteropServices.ExternalException)
				{
					currentResult = Result.InvalidParameterError;
				}
				
				if (currentResult == Result.Ok)
				{					
					sound.Handle = soundHandle;				
					sound.SoundSystem = this;
				}
				else throw new ApplicationException("could not create stream: " + currentResult.ToString());

				return sound;
			}
			else throw new ArgumentNullException("sound");
		}
		internal Sound CreateSound(string path)
		{
			if (!string.IsNullOrEmpty(path))
			{
				currentResult = Result.Ok;
				IntPtr soundHandle = new IntPtr();
				Sound sound = null;

				try
				{
					currentResult = NativeMethods.FMOD_System_CreateSound(handle, path, (Modes.Hardware | Modes.Fmod2D | Modes.CreateStream | Modes.OpenOnly | Modes.IgnoreTags), 0, ref soundHandle);
					//currentResult = FMOD_System_CreateSound(handle, driveName, (Mode.Hardware | Mode.Fmod2D | Mode.IgnoreTags), 0, ref soundHandle);
				}
				catch (System.Runtime.InteropServices.ExternalException)
				{
					currentResult = Result.InvalidParameterError;
				}

				if (currentResult == Result.Ok)
				{
					sound = new Sound(this, path);
					sound.Handle = soundHandle;
				}
				else throw new ApplicationException("could not create compact disc sound: " + currentResult.ToString());

				return sound;
			}
			else throw new ArgumentNullException("path");
		}
Beispiel #8
0
		private void SelectSubSound(int index)
		{
			currentSubSoundIndex = index;
			IntPtr subSoundHandle = new IntPtr();
			Result result = NativeMethods.FMOD_Sound_GetSubSound(handle, index, ref subSoundHandle);
			if (result == Result.Ok)
			{
				currentSubSound = new Sound(this);
				currentSubSound.Handle = subSoundHandle;
			}
			else throw new ApplicationException(string.Format("Could not get sub-sound {0}", index));
		}
		internal ProxyCompactDiscTrack(Sound parentSound, int index) : base(parentSound)
		{
		}