예제 #1
0
        public void Play(bool stopPrevious = false)
        {
            if (SourceEntity == null)
            {
                return;
            }

            if (stopPrevious && SoundInstances.Count > 0)
            {
                SoundInstances.ForEach(x => x.Stop());
            }

            ISound iSound;

            if (Flags.HasFlag(AudioFlags.No3D))
            {
                if (_soundSource == default)
                {
                    iSound = _soundEngine.Play2D(FilePath, Flags.HasFlag(AudioFlags.Loop), true, StreamMode.AutoDetect);
                }
                else
                {
                    iSound = _soundEngine.Play2D(_soundSource, Flags.HasFlag(AudioFlags.Loop), true, false);
                }
            }
            else
            {
                if (_soundSource == default)
                {
                    iSound = _soundEngine.Play3D(FilePath,
                                                 MathUtils.Vector3ToVector3D(Vector3.Zero), Flags.HasFlag(AudioFlags.Loop), true, StreamMode.AutoDetect);
                }
                else
                {
                    iSound = _soundEngine.Play3D(_soundSource, 0, 0, 0, Flags.HasFlag(AudioFlags.Loop), true, false);
                }
            }

            if (iSound == null)
            {
                throw new Exception($"KRAL Engine init failed. File Path: {FilePath}");
            }

            SoundInstances.Add(iSound);
            Last = iSound;

            if (StartFadeIn)
            {
                Last.Volume = 0;

                IsDoingFadeIn = true;
            }

            Last.Paused = false;
        }
예제 #2
0
        public static ISound PlaySound(Vector2 v, string name)
        {
            ISound t = engine.Play3D(name, v.X, 0, v.Y, false, false, StreamMode.AutoDetect, true);

            //t.MaxDistance = 5;
            t.MinDistance = 45;
            t.Volume      = 100;
            //t.SoundEffectControl.EnableI3DL2ReverbSoundEffect(-700,1,0.1f,2.1f,0.2f,-2000,0.01f,250,0.05f,95,99,4900);

            return(t);
        }
예제 #3
0
        public void agAddDemoPoints()
        {
            var             wgs84 = MySceneView.Scene.SpatialReference;
            GraphicsOverlay go    = new GraphicsOverlay();

            go.SceneProperties.SurfacePlacement = SurfacePlacement.Relative;
            var rnd = new System.Random();

            for (int i = 0; i < 50; i++)
            {
                var buoy1Loc   = new MapPoint(-118.2606, 34.0498, 1000, wgs84);
                var buoyMarker = new SimpleMarkerSymbol(SimpleMarkerSymbolStyle.Circle, Colors.Red, 10);
                var buoyTest   = new Graphic(buoy1Loc, buoyMarker);
                go.Graphics.Add(buoyTest);
                Task.Factory.StartNew(async() => {
                    while (true)
                    {
                        buoyTest.Geometry = new MapPoint(-118.2606 + rnd.NextDouble(), 34.0498 + rnd.NextDouble(), rnd.Next(0, 1000));
                        engine.Play3D("../../../../bus.wav", -10.0f, 0, 0, false);

                        await Task.Delay(100);
                    }
                });
            }
            MySceneView.GraphicsOverlays.Add(go);
        }
예제 #4
0
        public void Load(Sound sound)
        {
            sound.iSourceSource = soundEngine.GetSoundSource(sound.FileName, true);

            switch (sound.Is3D)
            {
            case true:
                sound.iSound = soundEngine.Play3D(sound.iSourceSource, sound.Position.x, sound.Position.y, sound.Position.z, sound.Loop, sound.Stopped, false);
                break;

            default:
                sound.iSound = soundEngine.Play2D(sound.iSourceSource, sound.Loop, sound.Stopped, false);
                break;
            }

            StopAllSounds();
        }
예제 #5
0
        public ISound Play3D(string filename, Vector3 position, float volume)
        {
            if (filename != null && filename != "")
            {
                ISound sound = soundEngine.Play3D(filename, position.x, position.y, position.z);
                sound.Volume      = volume;
                sound.MinDistance = 5;
                return(sound);
            }

            return(null);
        }
예제 #6
0
 private void buttonTestSound_Click(object sender, EventArgs e)
 {
     if (string.IsNullOrEmpty(textBoxSoundFile.Text))
     {
         MessageBox.Show("Please select a sound clip","No Sound Clip",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
         textBoxSoundFile.Focus();
         return;
     }
     ISoundEngine engine = new ISoundEngine();
     engine.Default3DSoundMinDistance = 0;
     engine.Default3DSoundMaxDistance = 1;
     engine.SetListenerPosition(0, 0, 0, 0, 0, 1);
     engine.SoundVolume = ((float)trackBarVolume.Value) / 100;
     Vector3D vector = new Vector3D();
     ISound music = engine.Play3D(textBoxSoundFile.Text, (float)soundClipPlacement1.Balance,0, (float)soundClipPlacement1.Fade, false);
 }
예제 #7
0
            public void Play(ISoundEngine soundEngine)
            {
                if (!Stopped && !IsPlaying /*!soundEngine.IsCurrentlyPlaying(Source.Name)*/)
                {
                    IsPlaying = true;
                    switch (Is3D)
                    {
                    case true:
                        soundEngine.Play3D(Source, Position.X, Position.Y, Position.Z, Loop, false, false);
                        break;

                    default:
                        soundEngine.Play2D(Source, Loop, false, false);
                        break;
                    }
                }
            }
예제 #8
0
		static void Main(string[] args)
		{
			// start the sound engine with default parameters
			ISoundEngine engine = new ISoundEngine();

			// Now play some sound stream as music in 3d space, looped.
			// We play it at position (0,0,0) in 3d space

			ISound music = engine.Play3D("../../media/ophelia.mp3",
										 0,0,0, true);

			// the following step isn't necessary, but to adjust the distance where
			// the 3D sound can be heard, we set some nicer minimum distance
			// (the default min distance is 1, for a small object). The minimum
			// distance simply is the distance in which the sound gets played
			// at maximum volume.

			if (music != null)
				music.MinDistance = 5.0f;

			// Print some help text and start the display loop

			Console.Out.Write("\nPlaying streamed sound in 3D.");
			Console.Out.Write("\nPress ESCAPE to quit, any other key to play sound at random position.\n\n");

			Console.Out.Write("+ = Listener position\n");
			Console.Out.Write("o = Playing sound\n");

			Random rand = new Random(); // we need random 3d positions
			const float radius = 5;
			float posOnCircle = 0;

			while(true) // endless loop until user exits
			{
				// Each step we calculate the position of the 3D music.
				// For this example, we let the
				// music position rotate on a circle:

				posOnCircle += 0.04f;
				Vector3D pos3d = new Vector3D(radius * (float)Math.Cos(posOnCircle), 0,
											  radius * (float)Math.Sin(posOnCircle * 0.5f));

				// After we know the positions, we need to let irrKlang know about the
				// listener position (always position (0,0,0), facing forward in this example)
				// and let irrKlang know about our calculated 3D music position

				engine.SetListenerPosition(0,0,0, 0,0,1);

				if (music != null)
					music.Position = pos3d;

				// Now print the position of the sound in a nice way to the console
				// and also print the play position

				string stringForDisplay = "          +         ";
				int charpos = (int)((pos3d.X + radius) / radius * 10.0f);
				if (charpos >= 0 && charpos < 20)
				{
					stringForDisplay = stringForDisplay.Remove(charpos, 1);
					stringForDisplay = stringForDisplay.Insert(charpos, "o");					
				}

				uint playPos = 0;
				if (music != null)
					playPos = music.PlayPosition;

				string output = String.Format("\rx:({0})   3dpos: {1:f} {2:f} {3:f}, playpos:{4}:{5:00}    ",
					stringForDisplay, pos3d.X, pos3d.Y, pos3d.Z,
					playPos/60000, (playPos%60000)/1000);

				Console.Write(output);

				System.Threading.Thread.Sleep(100);

				// Handle user input: Every time the user presses a key in the console,
				// play a random sound or exit the application if he pressed ESCAPE.

				if (_kbhit()!=0)
				{
					int key = _getch();

					if (key == 27)
						break; // user pressed ESCAPE key
					else
					{
						// Play random sound at some random position.

						Vector3D pos = new Vector3D(((float)rand.NextDouble() % radius*2.0f) - radius, 0, 0);

						string filename;

						if (rand.Next()%2 != 0)
							filename = "../../media/bell.wav";
						else
							filename = "../../media/explosion.wav";

						engine.Play3D(filename, pos.X, pos.Y, pos.Z);

						Console.Write("\nplaying {0} at {1:f} {2:f} {3:f}\n",
							filename, pos.X, pos.Y, pos.Z);
					}
				}
			}
		}
예제 #9
0
        //called each frame by vvvv
        public void Evaluate(int SpreadMax)
        {
            bool ChangedSpreadSize = FPreviousSpreadMax == SpreadMax ? false : true;
            bool Reload            = false;

            if (FPlay.IsChanged || ChangedSpreadSize || FFile.IsChanged)
            {
                Reload = true;
            }

            FLength.SliceCount = SpreadMax;

            //tells the Irrklang engine which System Audio Output to use
            #region output devices

            if (FDeviceenum.IsChanged)
            {
                try
                {
                    int id = FDeviceSelect[FDeviceenum[0]];
                    FEngine.StopAllSounds();
                    FEngine = new ISoundEngine(SoundOutputDriver.AutoDetect, SoundEngineOptionFlag.DefaultOptions, FDevice.getDeviceID(id));
                    FEngine.LoadPlugins(Path.Combine(Environment.CurrentDirectory, "plugins"));
                    FDriverUse[0] = FEngine.Name;
                    FMultiT[0]    = FEngine.IsMultiThreaded;
                }
                catch (Exception ex)
                {
                    FLogger.Log(LogType.Error, ex.Message);
                }
            }

            #endregion output devices

            //Sets the MainVoume of the Engine
            #region MainVolume

            if (FMainVolume.IsChanged)
            {
                FEngine.SoundVolume = (float)FMainVolume[0];
            }

            #endregion MainVolume

            //Handles the Reading and Deleting of the Files
            //and Creating the ISoundSource Onject
            #region File IO
            if (FFile.IsChanged || ChangedSpreadSize)
            {
                FilePath.Clear();
                SoundSources.Clear();

                if (FLoadedFiles.Count < SpreadMax)
                {
                    int Diff = SpreadMax - FLoadedFiles.Count;
                    for (int i = FLoadedFiles.Count; i < SpreadMax; i++)
                    {
                        FLoadedFiles.Add("");
                    }
                }


                for (int i = 0; i < SpreadMax; i++)
                {
                    if (!String.IsNullOrEmpty(FFile[i]))
                    {
                        if (FLoadedFiles[i] != FFile[i])
                        {
                            if (FLoadedFiles.Contains(FFile[i]))
                            {
                                int          SourceIndex = FLoadedFiles.IndexOf(FFile[i]);
                                ISoundSource SoundSource;
                                FLoadedSourceFiles.TryGetValue(SourceIndex, out SoundSource);

                                string       FileName       = Path.Combine(Path.GetDirectoryName(FFile[i]), Path.GetFileNameWithoutExtension(FFile[i]) + "D" + i.ToString() + Path.GetExtension(FFile[i]));
                                ISoundSource NewSoundSource = FEngine.AddSoundSourceAlias(SoundSource, FileName);
                                SoundSources.Add(i, NewSoundSource);
                                FilePath.Add(FFile[i]);
                            }
                            else
                            {
                                if (FilePath.Contains(FFile[i]))
                                {
                                    int          SourceIndex = FilePath.IndexOf(FFile[i]);
                                    ISoundSource SoundSource;
                                    SoundSources.TryGetValue(SourceIndex, out SoundSource);

                                    string       FileName       = Path.Combine(Path.GetDirectoryName(FFile[i]), Path.GetFileNameWithoutExtension(FFile[i]) + "D" + i.ToString() + Path.GetExtension(FFile[i]));
                                    ISoundSource NewSoundSource = FEngine.AddSoundSourceAlias(SoundSource, FileName);
                                    SoundSources.Add(i, NewSoundSource);
                                    FilePath.Add(FFile[i]);
                                }
                                else
                                {
                                    ISoundSource SoundSource = FEngine.AddSoundSourceFromFile(FFile[i]);
                                    SoundSources.Add(i, SoundSource);
                                    FilePath.Add(FFile[i]);
                                }
                            }
                        }
                        else
                        {
                            ISoundSource SoundSource;
                            FLoadedSourceFiles.TryGetValue(i, out SoundSource);
                            SoundSources.Add(i, SoundSource);
                            FilePath.Add(FFile[i]);
                        }
                    }
                    else
                    {
                        SoundSources.Add(i, null);
                        FilePath.Add(FFile[i]);
                    }
                }

                DeleteList.Clear();

                if (FLoadedFiles.Count > SpreadMax)
                {
                    for (int i = FLoadedFiles.Count; i > SpreadMax; i--)
                    {
                        int          Index = i - 1;
                        ISoundSource SoundSource;
                        FLoadedSourceFiles.TryGetValue(Index, out SoundSource);
                        if (SoundSource != null)
                        {
                            DeleteList.Add(SoundSource.Name);
                        }
                    }
                }

                int LastFoundIndex = -1;
                foreach (string tFile in FLoadedFiles)
                {
                    if (FilePath.Contains(tFile) == false)
                    {
                        int Index = FLoadedFiles.IndexOf(tFile, LastFoundIndex + 1);
                        if (Index != -1)
                        {
                            ISoundSource SoundSource;
                            FLoadedSourceFiles.TryGetValue(Index, out SoundSource);
                            LastFoundIndex = Index;
                            if (SoundSource != null)
                            {
                                DeleteList.Add(SoundSource.Name);
                            }
                        }
                    }
                }


                foreach (string File in DeleteList)
                {
                    FEngine.RemoveSoundSource(File);
                }


                FLoadedSourceFiles = new Dictionary <int, ISoundSource>(SoundSources);
                FLoadedFiles       = new List <string>(FilePath);
            }



            #endregion FileIO

            //Start and stops the laoded files
            //if a file is started the ISound Object is created
            #region Start / Stop Sounds
            if (FPlay.IsChanged || Reload)
            {
                List <ISound> NewSounds = new List <ISound>();

                for (int i = 0; i < SpreadMax; i++)
                {
                    ISoundSource SoundSource;
                    FLoadedSourceFiles.TryGetValue(i, out SoundSource);
                    FLength[i] = (double)SoundSource.PlayLength / 1000;

                    //checks the Play pin
                    if (FPlay[i])
                    {
                        //Creates the sound onject every frame and adds it to the FSound List
                        //can not just played the sound at the given position or replayed
                        //after Position changed??


                        bool SoundActive = false;

                        try
                        {
                            if (FPlayedSounds[i] != null)
                            {
                                SoundActive = true;
                            }
                        }
                        catch (ArgumentOutOfRangeException)
                        {
                            SoundActive = false;
                        }

                        if (SoundSource != null)
                        {
                            if (SoundActive == false)
                            {
                                if (FPlayMode[0].Name == "3D")
                                {
                                    ISound Sound = FEngine.Play3D(SoundSource, (float)FSoundPosition[i].x, (float)FSoundPosition[i].y, (float)FSoundPosition[i].z, FLoop[i], false, true);
                                    Sound.setSoundStopEventReceiver(this);
                                    NewSounds.Add(Sound);
                                }
                                else
                                {
                                    ISound Sound = FEngine.Play2D(SoundSource, FLoop[i], false, true);
                                    Sound.setSoundStopEventReceiver(this);
                                    NewSounds.Add(Sound);
                                }
                            }
                            else
                            {
                                NewSounds.Add(FPlayedSounds[i]);
                            }
                        }
                        else
                        {
                            FLogger.Log(LogType.Error, "No SoundSource found");
                            NewSounds.Add(null);
                        }
                    }
                    else
                    {
                        try
                        {
                            if (FPlayedSounds[i] != null)
                            {
                                FPlayedSounds[i].Stop();
                                NewSounds.Add(null);
                            }
                            else
                            {
                                NewSounds.Add(null);
                            }
                        }
                        catch (ArgumentOutOfRangeException)
                        {
                            NewSounds.Add(null);
                        }
                        catch (NullReferenceException)
                        {
                            NewSounds.Add(null);
                        }
                    }
                }
                FPlayedSounds = new List <ISound>(NewSounds);
            }

            #endregion Start / Stop Sounds

            //set the Loop Propertie of a ISound Object
            #region Loop

            if (FLoop.IsChanged || Reload)
            {
                for (int i = 0; i < SpreadMax; i++)
                {
                    if (FPlayedSounds[i] != null)
                    {
                        if (FLoop[i] == true)
                        {
                            FPlayedSounds[i].Looped = true;
                        }
                        else
                        {
                            FPlayedSounds[i].Looped = false;
                        }
                    }
                }
            }

            #endregion Loop

            //handles the seeking operation
            #region Seek

            if (FSeek.IsChanged)
            {
                for (int i = 0; i < SpreadMax; i++)
                {
                    if (FPlayedSounds[i] != null)
                    {
                        if (FSeek[i] == true)
                        {
                            FPlayedSounds[i].PlayPosition = (uint)(((UInt32)FSeekPos[i]) * 1000.0);
                        }
                    }
                }
            }

            #endregion Seek

            ////set the Pause Propertie of a ISound Object
            #region Pause

            if (FPause.IsChanged || Reload)
            {
                for (int i = 0; i < SpreadMax; i++)
                {
                    if (FPlayedSounds[i] != null)
                    {
                        if (FPause[i])
                        {
                            FPlayedSounds[i].Paused = true;
                        }
                        else
                        {
                            FPlayedSounds[i].Paused = false;
                        }
                    }
                }
            }

            #endregion Pause

            //set the PlaybackSpeed Propertie of a ISound Object
            #region Speed

            if (FPlaybackSpeed.IsChanged || Reload)
            {
                for (int i = 0; i < SpreadMax; i++)
                {
                    if (FPlayedSounds[i] != null)
                    {
                        FPlayedSounds[i].PlaybackSpeed = FPlaybackSpeed[i];
                    }
                }
            }


            #endregion Speed

            //stops or paused all SoundSource which are playedback with the Irrklangengine
            #region Stop / Pause All

            if (FStopAll.IsChanged)
            {
                if (FStopAll[0])
                {
                    FEngine.StopAllSounds();
                }
            }

            if (FPauseAll.IsChanged)
            {
                if (FPause[0])
                {
                    FEngine.SetAllSoundsPaused(true);
                }
                else
                {
                    FEngine.SetAllSoundsPaused(false);
                }
            }

            #endregion Stop / Pause All

            //sets the Volume Property of a ISound Object
            #region Volume

            if (FVolume.IsChanged || Reload)
            {
                for (int i = 0; i < SpreadMax; i++)
                {
                    if (FPlayedSounds[i] != null)
                    {
                        FPlayedSounds[i].Volume = FVolume[i];
                    }
                }
            }

            #endregion Volume

            //sets the Pan Property of a ISound Object, only works if the sound is plyed pack in 2D Mode
            #region Pan

            if (FPan.IsChanged || Reload)
            {
                for (int i = 0; i < SpreadMax; i++)
                {
                    if (FPlayedSounds[i] != null && FPlayMode[i].Name == "2D")
                    {
                        FPlayedSounds[i].Pan = FPan[i];
                    }
                }
            }

            #endregion Pan

            //Sets the Postion Property of a ISound Object, only works in the 3D Playback mode
            #region Position

            if (FSoundPosition.IsChanged || Reload)
            {
                for (int i = 0; i < SpreadMax; i++)
                {
                    if (FPlayedSounds[i] != null)
                    {
                        Vector3D          Vector    = FSoundPosition[i];
                        IrrKlang.Vector3D IrrVector = new IrrKlang.Vector3D((float)Vector.x, (float)Vector.y, (float)Vector.z);
                        FPlayedSounds[i].Position = IrrVector;
                    }
                }
            }

            #endregion Position

            //Sets the Velocity Property of a ISound Object, only works in the 3D Playback mode
            #region Sound Velocity

            if (FSoundVelocity.IsChanged || Reload)
            {
                for (int i = 0; i < SpreadMax; i++)
                {
                    if (FPlayedSounds[i] != null)
                    {
                        Vector3D          Vector    = FSoundVelocity[i];
                        IrrKlang.Vector3D IrrVector = new IrrKlang.Vector3D((float)Vector.x, (float)Vector.y, (float)Vector.z);
                        FPlayedSounds[i].Velocity = IrrVector;
                    }
                }
            }



            #endregion Sound Velocity

            //sets the MinDistance Propertie of a ISound Object
            #region MinDistance

            if (FMinDist.IsChanged || Reload)
            {
                for (int i = 0; i < SpreadMax; i++)
                {
                    if (FPlayedSounds[i] != null)
                    {
                        FPlayedSounds[i].MinDistance = FMinDist[i];
                    }
                }
            }

            #endregion MinDistance

            //sets the MaxDistance Propertie of a ISound Object
            #region MaxDistance

            if (FMaxDist.IsChanged || Reload)
            {
                for (int i = 0; i < SpreadMax; i++)
                {
                    if (FPlayedSounds[i] != null)
                    {
                        FPlayedSounds[i].MaxDistance = FMinDist[i];
                    }
                }
            }

            #endregion MaxDistance

            //set the Listener Position of the Engine
            #region View Listener

            if (FViewDir.IsChanged || FViewPos.IsChanged || FViewUpVector.IsChanged || FViewVelocity.IsChanged)
            {
                IrrKlang.Vector3D ViewDir      = new IrrKlang.Vector3D((float)FViewDir[0].x, (float)FViewDir[0].y, (float)FViewDir[0].z);
                IrrKlang.Vector3D ViewPos      = new IrrKlang.Vector3D((float)FViewPos[0].x, (float)FViewPos[0].y, (float)FViewPos[0].z);
                IrrKlang.Vector3D ViewVelocity = new IrrKlang.Vector3D((float)FViewVelocity[0].x, (float)FViewVelocity[0].y, (float)FViewVelocity[0].z);
                IrrKlang.Vector3D ViewUp       = new IrrKlang.Vector3D((float)FViewUpVector[0].x, (float)FViewUpVector[0].y, (float)FViewUpVector[0].z);

                FEngine.SetListenerPosition(ViewDir, ViewPos, ViewVelocity, ViewUp);
            }

            #endregion View Listener

            //sets the RollOff effekt of the Engine
            #region RollOff

            if (FRollOff.IsChanged)
            {
                FEngine.SetRolloffFactor(FRollOff[0]);
            }

            #endregion RollOFF

            //sets the DopllerEffekt of the Engine
            #region DopplerEffekt

            if (FDoplerFactor.IsChanged || FDoplerDistanceFactor.IsChanged)
            {
                FEngine.SetDopplerEffectParameters(FDoplerFactor[0], FDoplerDistanceFactor[0]);
            }

            #endregion DopplerEffekt

            #region Effekts

            if (FEnableEffekts[0] == true)
            {
                //Sets the Chorus Effekt of a ISound Object
                #region Chorus

                if (Reload || FEnableChorus.IsChanged || FChorusDelay.IsChanged || FChorusFrequency.IsChanged || FChoruspDepth.IsChanged || FChoruspFeedback.IsChanged || FChorusPhase.IsChanged || FChoruspWetDryMix.IsChanged || FChorusSinusWaveForm.IsChanged)
                {
                    for (int i = 0; i < SpreadMax; i++)
                    {
                        if (FPlayedSounds[i] != null)
                        {
                            ISoundEffectControl Fx = FPlayedSounds[i].SoundEffectControl;

                            if (FEnableChorus[i])
                            {
                                Fx.EnableChorusSoundEffect(FChoruspWetDryMix[i], FChoruspDepth[i], FChoruspFeedback[i], FChorusFrequency[i], FChorusSinusWaveForm[i], FChorusDelay[i], FChorusPhase[i]);
                            }
                            else
                            {
                                Fx.DisableChorusSoundEffect();
                            }
                        }
                    }
                }

                #endregion Chorus

                //Sets the Compresser Effekt of a ISound Object
                #region Compressor

                if (Reload || FEnableComp.IsChanged || FCompAttack.IsChanged || FCompGain.IsChanged || FCompPredelay.IsChanged || FCompRatio.IsChanged || FCompRelease.IsChanged || FCompThreshold.IsChanged)
                {
                    for (int i = 0; i < SpreadMax; i++)
                    {
                        if (FPlayedSounds[i] != null)
                        {
                            ISoundEffectControl Fx = FPlayedSounds[i].SoundEffectControl;

                            if (FEnableComp[i])
                            {
                                Fx.EnableCompressorSoundEffect(FCompGain[i], FCompAttack[i], FCompRelease[i], FCompThreshold[i], FCompRatio[i], FCompPredelay[i]);
                            }
                            else
                            {
                                Fx.DisableCompressorSoundEffect();
                            }
                        }
                    }
                }

                #endregion Compressor

                //Sets the Distortion Effekt of a ISound Object
                #region Disortion

                if (Reload || FEnableDistortion.IsChanged || FDistortionGain.IsChanged || FDistortionBandwidth.IsChanged || FDistortionEdge.IsChanged || FDistortionEQCenterFrequenz.IsChanged || FDistortionLowpassCutoff.IsChanged)
                {
                    for (int i = 0; i < SpreadMax; i++)
                    {
                        if (FPlayedSounds[i] != null)
                        {
                            ISoundEffectControl Fx = FPlayedSounds[i].SoundEffectControl;

                            if (FEnableDistortion[i])
                            {
                                Fx.EnableDistortionSoundEffect(FDistortionGain[i], FDistortionEdge[i], FDistortionEQCenterFrequenz[i], FDistortionBandwidth[i], FDistortionLowpassCutoff[i]);
                            }
                            else
                            {
                                Fx.DisableDistortionSoundEffect();
                            }
                        }
                    }
                }

                #endregion Distortion

                //Sets the Echo Effekt of a ISound Object
                #region Echo

                if (Reload || FEnableEcho.IsChanged || FEchoFeedback.IsChanged || FEchoLeftDelay.IsChanged || FEchoPanDelay.IsChanged || FEchoRightDelay.IsChanged || FEchoWetDryMix.IsChanged)
                {
                    for (int i = 0; i < SpreadMax; i++)
                    {
                        if (FPlayedSounds[i] != null)
                        {
                            ISoundEffectControl Fx = FPlayedSounds[i].SoundEffectControl;

                            if (FEnableEcho[i])
                            {
                                Fx.EnableEchoSoundEffect(FEchoWetDryMix[i], FEchoFeedback[i], FEchoLeftDelay[i], FEchoRightDelay[i], FEchoPanDelay[i]);
                            }
                            else
                            {
                                Fx.DisableEchoSoundEffect();
                            }
                        }
                    }
                }

                #endregion Echo

                //Sets the Flanger Effekt of a ISound Object
                #region Flanger

                if (Reload || FEnableFlanger.IsChanged || FFlangerDelay.IsChanged || FFlangerDepth.IsChanged || FFlangerFeedback.IsChanged || FFlangerFrequency.IsChanged || FFlangerPhase.IsChanged || FFlangerTriangleWaveForm.IsChanged || FFlangerWetDryMix.IsChanged)
                {
                    for (int i = 0; i < SpreadMax; i++)
                    {
                        if (FPlayedSounds[i] != null)
                        {
                            ISoundEffectControl Fx = FPlayedSounds[i].SoundEffectControl;

                            if (FEnableFlanger[i])
                            {
                                Fx.EnableFlangerSoundEffect(FFlangerWetDryMix[i], FFlangerDepth[i], FFlangerFeedback[i], FFlangerFrequency[i], FFlangerTriangleWaveForm[i], FFlangerDelay[i], FFlangerPhase[i]);
                            }
                            else
                            {
                                Fx.DisableFlangerSoundEffect();
                            }
                        }
                    }
                }

                #endregion Flanger

                //Sets the Gargle Effekt of a ISound Object
                #region Gargle

                if (Reload || FEnableGargle.IsChanged || FGargleRateHz.IsChanged || FGargleSinusWaveForm.IsChanged)
                {
                    for (int i = 0; i < SpreadMax; i++)
                    {
                        if (FPlayedSounds[i] != null)
                        {
                            ISoundEffectControl Fx = FPlayedSounds[i].SoundEffectControl;
                            if (FEnableGargle[i])
                            {
                                Fx.EnableGargleSoundEffect(FGargleRateHz[i], FGargleSinusWaveForm[i]);
                            }
                            else
                            {
                                Fx.DisableGargleSoundEffect();
                            }
                        }
                    }
                }

                #endregion Gargle

                //Sets the I3Dl2 Reverb Effekt of a ISound Object
                #region I3Dl2 Reverb

                if (Reload || FEnableI3DL2.IsChanged || FI3DL2DecayHFRatio.IsChanged || FI3DL2DecayTime.IsChanged || FI3DL2Density.IsChanged || FI3DL2Diffusion.IsChanged || FI3DL2HfReference.IsChanged || FI3DL2ReflectionDelay.IsChanged || FI3DL2Reflections.IsChanged || FI3DL2Reverb.IsChanged || FI3DL2ReverbDelay.IsChanged || FI3DL2Room.IsChanged || FI3DL2RoomHF.IsChanged || FI3DL2RoomRollOffFactor.IsChanged)
                {
                    for (int i = 0; i < SpreadMax; i++)
                    {
                        if (FPlayedSounds[i] != null)
                        {
                            ISoundEffectControl Fx = FPlayedSounds[i].SoundEffectControl;

                            if (FEnableI3DL2[i])
                            {
                                Fx.EnableI3DL2ReverbSoundEffect(FI3DL2Room[i], FI3DL2RoomHF[i], FI3DL2RoomRollOffFactor[i], FI3DL2DecayTime[i], FI3DL2DecayHFRatio[i], FI3DL2Reflections[i], FI3DL2ReflectionDelay[i], FI3DL2Reverb[i], FI3DL2ReverbDelay[i], FI3DL2Diffusion[i], FI3DL2Density[i], FI3DL2HfReference[i]);
                            }
                            else
                            {
                                Fx.DisableI3DL2ReverbSoundEffect();
                            }
                        }
                    }
                }

                #endregion I3Dl2 Reverb

                //Sets the Param EQ Effekt of a ISound Objec
                #region Param EQ

                if (Reload || FEnableEq.IsChanged || FEqBandwidth.IsChanged || FEqCenter.IsChanged || FEqGain.IsChanged)
                {
                    for (int i = 0; i < SpreadMax; i++)
                    {
                        if (FPlayedSounds[i] != null)
                        {
                            ISoundEffectControl Fx = FPlayedSounds[i].SoundEffectControl;

                            if (FEnableEq[i])
                            {
                                Fx.EnableParamEqSoundEffect(FEqCenter[i], FEqBandwidth[i], FEqGain[i]);
                            }
                            else
                            {
                                Fx.DisableParamEqSoundEffect();
                            }
                        }
                    }
                }

                #endregion param EQ

                //Sets the Wave Effekt of a ISound Object
                #region Wave Reverb

                if (Reload || FEnableWaveReverb.IsChanged || FWaveReverbFreq.IsChanged || FWaveReverbInGain.IsChanged || FWaveReverbMix.IsChanged || FWaveReverbTime.IsChanged)
                {
                    for (int i = 0; i < SpreadMax; i++)
                    {
                        if (FPlayedSounds[i] != null)
                        {
                            ISoundEffectControl Fx = FPlayedSounds[i].SoundEffectControl;

                            if (FEnableWaveReverb[i])
                            {
                                Fx.EnableWavesReverbSoundEffect(FWaveReverbInGain[i], FWaveReverbMix[i], FWaveReverbTime[i], FWaveReverbFreq[i]);
                            }
                            else
                            {
                                Fx.DisableWavesReverbSoundEffect();
                            }
                        }
                    }
                }

                #endregion Wave Reverb

                //Disables all Effekts
                #region Disable All Effekts

                if (FDisableAllEffekt.IsChanged)
                {
                    for (int i = 0; i < SpreadMax; i++)
                    {
                        if (FPlayedSounds[i] != null)
                        {
                            ISoundEffectControl Fx = FPlayedSounds[i].SoundEffectControl;
                            if (FDisableAllEffekt[i])
                            {
                                Fx.DisableAllEffects();
                            }
                        }
                    }
                }

                #endregion Disabel All Effects
            }

            #endregion Effekts


            //Reads the Output values form the ISound Object
            #region Node Output

            FCurrentPos.SliceCount = SpreadMax;
            FFinish.SliceCount     = SpreadMax;
            FMessage.SliceCount    = SpreadMax;

            //Set the OutputPin values
            for (int i = 0; i < SpreadMax; i++)
            {
                if (FPlayedSounds[i] != null)
                {
                    if (FPlayedSounds[i].Finished)
                    {
                        FCurrentPos[i] = 0.0;
                    }
                    else
                    {
                        FCurrentPos[i] = (double)(FPlayedSounds[i].PlayPosition) / 1000.0;
                    }
                }
                else
                {
                    FCurrentPos[i] = 0;
                }
                FFinish[i] = false;
            }

            foreach (int Index in FFinishedSounds)
            {
                FFinish[Index] = true;
            }

            FFinishedSounds.Clear();

            #endregion NodeOutput

            FPreviousSpreadMax = SpreadMax;
        }
예제 #10
0
 public void Play(ISoundEngine soundEngine)
 {
     if (!Stopped && !IsPlaying /*!soundEngine.IsCurrentlyPlaying(Source.Name)*/)
     {
         IsPlaying = true;
         switch (Is3D)
         {
             case true:
                 soundEngine.Play3D(Source, Position.X, Position.Y, Position.Z, Loop, false, false);
                 break;
             default:
                 soundEngine.Play2D(Source, Loop, false, false);
                 break;
         }
     }
 }
예제 #11
0
파일: Class1.cs 프로젝트: halak/bibim
        static void Main(string[] args)
        {
            // start the sound engine with default parameters
            ISoundEngine engine = new ISoundEngine();

            // Now play some sound stream as music in 3d space, looped.
            // We play it at position (0,0,0) in 3d space

            ISound music = engine.Play3D(@"C:\Development\irrTech\irrKlang\media\speech.wav", 0, 0, 0, true);

            // the following step isn\'t necessary, but to adjust the distance where
            // the 3D sound can be heard, we set some nicer minimum distance
            // (the default min distance is 1, for a small object). The minimum
            // distance simply is the distance in which the sound gets played
            // at maximum volume.

            if (music != null)
            {
                music.MinDistance = 0.5f;
            }

            // Print some help text and start the display loop

            Console.Out.Write("\nPlaying streamed sound in 3D.");
            Console.Out.Write("\\nPress ESCAPE to quit, any other key to play sound at random position.\n\n");

            //Console.Out.Write(\"+ = Listener position\\n\");
            //Console.Out.Write(\"o = Playing sound\\n\");

            Random      rand        = new Random(); // we need random 3d positions
            const float radius      = 5;
            float       posOnCircle = 0;
            float       x           = 20;

            while (true)            // endless loop until user exits
            {
                // Each step we calculate the position of the 3D music.
                // For this example, we let the
                // music position rotate on a circle:

                posOnCircle += 0.04f;
                Vector3D pos3d = new Vector3D(radius * (float)Math.Cos(posOnCircle), 0,
                                              radius * (float)Math.Sin(posOnCircle * 0.5f));


                // After we know the positions, we need to let irrKlang know about the
                // listener position (always position (0,0,0), facing forward in this example)
                // and let irrKlang know about our calculated 3D music position

                engine.SetListenerPosition(x, 0, 0, 0, 0, 1);

                if (music != null)
                {
                    music.Position = pos3d;
                }

                // Now print the position of the sound in a nice way to the console
                // and also print the play position

                string stringForDisplay = "          +         ";
                int    charpos          = (int)((pos3d.X + radius) / radius * 10.0f);
                if (charpos >= 0 && charpos < 20)
                {
                    stringForDisplay = stringForDisplay.Remove(charpos, 1);
                    stringForDisplay = stringForDisplay.Insert(charpos, "o");
                }

                uint playPos = 0;
                if (music != null)
                {
                    playPos = music.PlayPosition;
                }

                string output = String.Format("\rx: {0:f} {1:f} {2:f}    ",
                                              x, 0.0f, 0.0f);

                Console.Write(output);

                System.Threading.Thread.Sleep(100);

                // Handle user input: Every time the user presses a key in the console,
                // play a random sound or exit the application if he pressed ESCAPE.

                if (_kbhit() != 0)
                {
                    int  key        = _getch();
                    bool playasound = false;

                    if (key == 27)
                    {
                        break;                         // user pressed ESCAPE key
                    }
                    else if (key == 'a')
                    {
                        x         -= 1;
                        playasound = true;
                    }
                    else if (key == 's')
                    {
                        x          = 0;
                        playasound = true;
                    }
                    else if (key == 'd')
                    {
                        x         += 1;
                        playasound = true;
                    }
                    else
                    {
                        // Play random sound at some random position.

                        Vector3D pos = new Vector3D(((float)rand.NextDouble() % radius * 2.0f) - radius, 0, 0);

                        string filename;

                        if (rand.Next() % 2 != 0)
                        {
                            filename = @"C:\Development\irrTech\irrKlang\media\bell.wav";
                        }
                        else
                        {
                            filename = @"C:\Development\irrTech\irrKlang\media\explosion.wav";
                        }

                        engine.Play3D(filename, pos.X, pos.Y, pos.Z);

                        //Console.Write(\"\\nplaying {0} at {1:f} {2:f} {3:f}\\n\",
                        //filename, pos.X, pos.Y, pos.Z);
                    }
                    if (playasound)
                    {
                        engine.SetListenerPosition(x, 0, 0, 0, 0, 1);
                        engine.Play3D(@"C:\Development\irrTech\irrKlang\media\impact.wav", x, 0, 0, false);
                    }
                }
            }
        }
예제 #12
0
파일: Irrklang.cs 프로젝트: mechaz/vvvv-sdk
        //called each frame by vvvv
        public void Evaluate(int SpreadMax)
        {
            FCurrentPos.SliceCount          = SpreadMax;
            FLength.SliceCount              = SpreadMax;
            FStreamDataLengthOut.SliceCount = SpreadMax;

            bool ChangedSpreadSize = FPreviousSpreadMax == SpreadMax ? false : true;

            //tells the Irrklang engine which System Audio Output to use
            #region Output devices

            if (FDeviceenum.IsChanged)
            {
                try
                {
                    int id = FDeviceSelect[FDeviceenum[0]];
                    FEngine.StopAllSounds();
                    FEngine       = new ISoundEngine(SoundOutputDriver.AutoDetect, SoundEngineOptionFlag.DefaultOptions, FDevice.getDeviceID(id));
                    FDriverUse[0] = FEngine.Name;
                    FMultiT[0]    = FEngine.IsMultiThreaded;

                    //HACK: Does not init plugins in the construcotr??
                    string PluginPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
                    FEngine.LoadPlugins(Path.GetDirectoryName(PluginPath));
                }
                catch (Exception ex)
                {
                    FLogger.Log(LogType.Error, ex.Message);
                }
            }

            #endregion output devices

            //Sets the MainVoume of the Engine
            #region MainVolume

            if (FMainVolume.IsChanged)
            {
                FEngine.SoundVolume = (float)FMainVolume[0];
            }


            #endregion MainVolume

            //Handles the Reading and Deleting of the Files
            //and Creating the ISoundSource Onject
            #region File IO

            if (ChangedSpreadSize || FFile.IsChanged || FDeviceenum.IsChanged || FPlayMode.IsChanged || FStreamMode.IsChanged || FStreamThreashold.IsChanged)
            {
                FEngine.StopAllSounds();
                FEngine.RemoveAllSoundSources();
                FSoundsources.Clear();
                FSounds.Clear();

                for (int i = 0; i < SpreadMax; i++)
                {
                    ISoundSource Source;
                    int          Index = FFile.IndexOf(FFile[i]);
                    if (Index < i)
                    {
                        Source = FEngine.AddSoundSourceAlias(FSoundsources[Index], FFile[i] + i.ToString());
                    }
                    else
                    {
                        Source = FEngine.AddSoundSourceFromFile(FFile[i]);
                    }

                    string EnumState = Enum.GetName(typeof(StreamMode), FStreamMode[i]);
                    switch (EnumState)
                    {
                    case "AutoDetect":
                        Source.StreamMode = StreamMode.AutoDetect;
                        break;

                    case "NoStreaming":
                        Source.StreamMode = StreamMode.NoStreaming;
                        Source.ForcedStreamingThreshold = 0;
                        break;

                    case "Streaming":
                        Source.StreamMode = StreamMode.Streaming;
                        Source.ForcedStreamingThreshold = FStreamThreashold[i];
                        break;

                    default:
                        FLogger.Log(LogType.Message, "No Streammode set");
                        break;
                    }

                    FSoundsources.Add(Source);
                }
            }

            #endregion File IO


            #region Finished Sounds

            Monitor.Enter(thisLock);
            try
            {
                List <ISound> Temp = new List <ISound>(FFinishedSounds);
                FFinishedSounds.Clear();
                foreach (ISound Sound in Temp)
                {
                    foreach (KeyValuePair <int, List <ISound> > Pair in FSounds)
                    {
                        if (Pair.Value.Contains(Sound))
                        {
                            Pair.Value.Remove(Sound);
                        }
                    }
                }
            }
            finally
            {
                Monitor.Exit(thisLock);
            }


            #endregion Finshed Sounds


            for (int i = 0; i < SpreadMax; i++)
            {
                #region PlayBack

                List <ISound> SoundsPerSlice;
                FSounds.TryGetValue(i, out SoundsPerSlice);

                if (SoundsPerSlice == null)
                {
                    SoundsPerSlice = new List <ISound>();
                    FSounds.Add(i, SoundsPerSlice);
                }


                if (FPlay[i] == true)
                {
                    try
                    {
                        FStreamDataLengthOut[i] = FSoundsources[i].SampleData.Length;
                    }catch
                    {
                        FStreamDataLengthOut[i] = -1;
                    }
                    try
                    {
                        if (FPlayMode[i] == "2D")
                        {
                            ISound Sound = FEngine.Play2D(FSoundsources[i], FLoop[i], true, true);
                            Sound.Volume        = FVolume[i];
                            Sound.Pan           = FPan[i];
                            Sound.PlaybackSpeed = FPlaybackSpeed[i];
                            Sound.Paused        = FPause[i];
                            Sound.setSoundStopEventReceiver(this);
                            SoundsPerSlice.Add(Sound);
                        }
                        else
                        {
                            ISound Sound = FEngine.Play3D(FSoundsources[i], (float)FSoundPosition[i].x, (float)FSoundPosition[i].y, (float)FSoundPosition[i].z, FLoop[i], true, true);
                            Sound.Volume        = FVolume[i];
                            Sound.PlaybackSpeed = FPlaybackSpeed[i];
                            Sound.MaxDistance   = FMaxDist[i];
                            Sound.MinDistance   = FMinDist[i];
                            Vector3D          Vector    = FSoundVelocity[i];
                            IrrKlang.Vector3D IrrVector = new IrrKlang.Vector3D((float)Vector.x, (float)Vector.y, (float)Vector.z);
                            Sound.Velocity = IrrVector;
                            Sound.Paused   = FPause[i];
                            Sound.setSoundStopEventReceiver(this);
                            SoundsPerSlice.Add(Sound);
                        }
                    }catch (NullReferenceException ex)
                    {
                        FLogger.Log(LogType.Error, "File not found in Irrklang");
                        FLogger.Log(LogType.Error, ex.Message);
                    }
                }

                if (FVolume.IsChanged || FPlay.IsChanged)
                {
                    foreach (ISound Sound in SoundsPerSlice)
                    {
                        Sound.Volume = FVolume[i];
                    }
                }


                if (FStop[i] == true)
                {
                    if (SoundsPerSlice.Count > 0)
                    {
                        SoundsPerSlice[SoundsPerSlice.Count - 1].Stop();
                        SoundsPerSlice.RemoveAt(SoundsPerSlice.Count - 1);
                    }
                }


                if (FLoop.IsChanged)
                {
                    if (FLoop[i] == true)
                    {
                        foreach (ISound Sound in SoundsPerSlice)
                        {
                            Sound.Looped = true;
                        }
                    }
                    else
                    {
                        foreach (ISound Sound in SoundsPerSlice)
                        {
                            Sound.Looped = false;
                        }
                    }
                }


                if (FPause.IsChanged)
                {
                    if (FPause[i])
                    {
                        foreach (ISound Sound in SoundsPerSlice)
                        {
                            Sound.Paused = true;
                        }
                    }
                    else
                    {
                        foreach (ISound Sound in SoundsPerSlice)
                        {
                            Sound.Paused = false;
                        }
                    }
                }

                if (FPlaybackSpeed.IsChanged || FPlay.IsChanged)
                {
                    foreach (ISound Sound in SoundsPerSlice)
                    {
                        Sound.PlaybackSpeed = FPlaybackSpeed[i];
                    }
                }



                if (FSeek[i] == true)
                {
                    foreach (ISound Sound in SoundsPerSlice)
                    {
                        Sound.PlayPosition = (uint)(((UInt32)FSeekPos[i]));
                    }
                }



                if (FPan.IsChanged || FPlay.IsChanged)
                {
                    if (FPlayMode[i].Name == "2D")
                    {
                        foreach (ISound Sound in SoundsPerSlice)
                        {
                            Sound.Pan = FPan[i];
                        }
                    }
                }


                if (FSoundPosition.IsChanged)
                {
                    if (FPlayMode[i].Name == "3D")
                    {
                        Vector3D          Vector    = FSoundPosition[i];
                        IrrKlang.Vector3D IrrVector = new IrrKlang.Vector3D((float)Vector.x, (float)Vector.y, (float)Vector.z);
                        foreach (ISound Sound in SoundsPerSlice)
                        {
                            Sound.Position = IrrVector;
                        }
                    }
                }

                if (FSoundVelocity.IsChanged || FPlay.IsChanged)
                {
                    if (FPlayMode[i].Name == "3D")
                    {
                        Vector3D          Vector    = FSoundVelocity[i];
                        IrrKlang.Vector3D IrrVector = new IrrKlang.Vector3D((float)Vector.x, (float)Vector.y, (float)Vector.z);
                        foreach (ISound Sound in SoundsPerSlice)
                        {
                            Sound.Velocity = IrrVector;
                        }
                    }
                }


                if (FMinDist.IsChanged || FPlay.IsChanged)
                {
                    if (FPlayMode[i].Name == "3D")
                    {
                        foreach (ISound Sound in SoundsPerSlice)
                        {
                            Sound.MinDistance = FMinDist[i];
                        }
                    }
                }

                if (FMaxDist.IsChanged || FPlay.IsChanged)
                {
                    if (FPlayMode[i].Name == "3D")
                    {
                        foreach (ISound Sound in SoundsPerSlice)
                        {
                            Sound.MaxDistance = FMinDist[i];
                        }
                    }
                }

                #endregion Playback


                #region Node Output

                //Set the OutputPin values
                FCurrentPos[i].SliceCount = SoundsPerSlice.Count;
                FLength[i] = FSoundsources[i].PlayLength;
                int Counter = 0;
                foreach (ISound Sound in SoundsPerSlice)
                {
                    if (!Sound.Finished)
                    {
                        FCurrentPos[i][Counter] = (double)(Sound.PlayPosition);
                    }
                    else
                    {
                        FCurrentPos[i][Counter] = 0;
                    }
                    Counter++;
                }


                #endregion NodeOutput


                #region Effekts



                //Sets the Chorus Effekt of a ISound Object
                #region Chorus

                if (FPlay.IsChanged || FEnableChorus.IsChanged || FChorusDelay.IsChanged || FChorusFrequency.IsChanged || FChoruspDepth.IsChanged || FChoruspFeedback.IsChanged || FChorusPhase.IsChanged || FChoruspWetDryMix.IsChanged || FChorusSinusWaveForm.IsChanged)
                {
                    foreach (ISound Sound in SoundsPerSlice)
                    {
                        ISoundEffectControl Fx = Sound.SoundEffectControl;

                        if (FEnableChorus[i])
                        {
                            Fx.EnableChorusSoundEffect(FChoruspWetDryMix[i], FChoruspDepth[i], FChoruspFeedback[i], FChorusFrequency[i], FChorusSinusWaveForm[i], FChorusDelay[i], FChorusPhase[i]);
                        }
                        else if (Fx != null)
                        {
                            Fx.DisableChorusSoundEffect();
                        }
                    }
                }

                #endregion Chorus

                //Sets the Compresser Effekt of a ISound Object
                #region Compressor

                if (FPlay.IsChanged || FEnableComp.IsChanged || FCompAttack.IsChanged || FCompGain.IsChanged || FCompPredelay.IsChanged || FCompRatio.IsChanged || FCompRelease.IsChanged || FCompThreshold.IsChanged)
                {
                    foreach (ISound Sound in SoundsPerSlice)
                    {
                        ISoundEffectControl Fx = Sound.SoundEffectControl;

                        if (FEnableComp[i])
                        {
                            Fx.EnableCompressorSoundEffect(FCompGain[i], FCompAttack[i], FCompRelease[i], FCompThreshold[i], FCompRatio[i], FCompPredelay[i]);
                        }
                        else if (Fx != null)
                        {
                            Fx.DisableCompressorSoundEffect();
                        }
                    }
                }

                #endregion Compressor

                //Sets the Distortion Effekt of a ISound Object
                #region Disortion

                if (FPlay.IsChanged || FEnableDistortion.IsChanged || FDistortionGain.IsChanged || FDistortionBandwidth.IsChanged || FDistortionEdge.IsChanged || FDistortionEQCenterFrequenz.IsChanged || FDistortionLowpassCutoff.IsChanged)
                {
                    foreach (ISound Sound in SoundsPerSlice)
                    {
                        ISoundEffectControl Fx = Sound.SoundEffectControl;

                        if (FEnableDistortion[i])
                        {
                            Fx.EnableDistortionSoundEffect(FDistortionGain[i], FDistortionEdge[i], FDistortionEQCenterFrequenz[i], FDistortionBandwidth[i], FDistortionLowpassCutoff[i]);
                        }
                        else if (Fx != null)
                        {
                            Fx.DisableDistortionSoundEffect();
                        }
                    }
                }

                #endregion Distortion

                //Sets the Echo Effekt of a ISound Object
                #region Echo

                if (FPlay.IsChanged || FEnableEcho.IsChanged || FEchoFeedback.IsChanged || FEchoLeftDelay.IsChanged || FEchoPanDelay.IsChanged || FEchoRightDelay.IsChanged || FEchoWetDryMix.IsChanged)
                {
                    foreach (ISound Sound in SoundsPerSlice)
                    {
                        ISoundEffectControl Fx = Sound.SoundEffectControl;

                        if (FEnableEcho[i])
                        {
                            Fx.EnableEchoSoundEffect(FEchoWetDryMix[i], FEchoFeedback[i], FEchoLeftDelay[i], FEchoRightDelay[i], FEchoPanDelay[i]);
                        }
                        else if (Fx != null)
                        {
                            Fx.DisableEchoSoundEffect();
                        }
                    }
                }

                #endregion Echo

                //Sets the Flanger Effekt of a ISound Object
                #region Flanger

                if (FPlay.IsChanged || FEnableFlanger.IsChanged || FFlangerDelay.IsChanged || FFlangerDepth.IsChanged || FFlangerFeedback.IsChanged || FFlangerFrequency.IsChanged || FFlangerPhase.IsChanged || FFlangerTriangleWaveForm.IsChanged || FFlangerWetDryMix.IsChanged)
                {
                    foreach (ISound Sound in SoundsPerSlice)
                    {
                        ISoundEffectControl Fx = Sound.SoundEffectControl;

                        if (FEnableFlanger[i])
                        {
                            Fx.EnableFlangerSoundEffect(FFlangerWetDryMix[i], FFlangerDepth[i], FFlangerFeedback[i], FFlangerFrequency[i], FFlangerTriangleWaveForm[i], FFlangerDelay[i], FFlangerPhase[i]);
                        }
                        else if (Fx != null)
                        {
                            Fx.DisableFlangerSoundEffect();
                        }
                    }
                }

                #endregion Flanger

                //Sets the Gargle Effekt of a ISound Object
                #region Gargle

                if (FPlay.IsChanged || FEnableGargle.IsChanged || FGargleRateHz.IsChanged || FGargleSinusWaveForm.IsChanged)
                {
                    foreach (ISound Sound in SoundsPerSlice)
                    {
                        ISoundEffectControl Fx = Sound.SoundEffectControl;
                        if (FEnableGargle[i])
                        {
                            Fx.EnableGargleSoundEffect(FGargleRateHz[i], FGargleSinusWaveForm[i]);
                        }
                        else if (Fx != null)
                        {
                            Fx.DisableGargleSoundEffect();
                        }
                    }
                }

                #endregion Gargle

                //Sets the I3Dl2 Reverb Effekt of a ISound Object
                #region I3Dl2 Reverb

                if (FPlay.IsChanged || FEnableI3DL2.IsChanged || FI3DL2DecayHFRatio.IsChanged || FI3DL2DecayTime.IsChanged || FI3DL2Density.IsChanged || FI3DL2Diffusion.IsChanged || FI3DL2HfReference.IsChanged || FI3DL2ReflectionDelay.IsChanged || FI3DL2Reflections.IsChanged || FI3DL2Reverb.IsChanged || FI3DL2ReverbDelay.IsChanged || FI3DL2Room.IsChanged || FI3DL2RoomHF.IsChanged || FI3DL2RoomRollOffFactor.IsChanged)
                {
                    foreach (ISound Sound in SoundsPerSlice)
                    {
                        ISoundEffectControl Fx = Sound.SoundEffectControl;

                        if (FEnableI3DL2[i])
                        {
                            Fx.EnableI3DL2ReverbSoundEffect(FI3DL2Room[i], FI3DL2RoomHF[i], FI3DL2RoomRollOffFactor[i], FI3DL2DecayTime[i], FI3DL2DecayHFRatio[i], FI3DL2Reflections[i], FI3DL2ReflectionDelay[i], FI3DL2Reverb[i], FI3DL2ReverbDelay[i], FI3DL2Diffusion[i], FI3DL2Density[i], FI3DL2HfReference[i]);
                        }
                        else if (Fx != null)
                        {
                            Fx.DisableI3DL2ReverbSoundEffect();
                        }
                    }
                }

                #endregion I3Dl2 Reverb

                //Sets the Param EQ Effekt of a ISound Objec
                #region Param EQ

                if (FPlay.IsChanged || FEnableEq.IsChanged || FEqBandwidth.IsChanged || FEqCenter.IsChanged || FEqGain.IsChanged)
                {
                    foreach (ISound Sound in SoundsPerSlice)
                    {
                        ISoundEffectControl Fx = Sound.SoundEffectControl;
                        if (FEnableEq[i])
                        {
                            Fx.EnableParamEqSoundEffect(FEqCenter[i], FEqBandwidth[i], FEqGain[i]);
                        }
                        else if (Fx != null)
                        {
                            Fx.DisableParamEqSoundEffect();
                        }
                    }
                }

                #endregion param EQ

                //Sets the Wave Effekt of a ISound Object
                #region Wave Reverb

                if (FPlay.IsChanged || FEnableWaveReverb.IsChanged || FWaveReverbFreq.IsChanged || FWaveReverbInGain.IsChanged || FWaveReverbMix.IsChanged || FWaveReverbTime.IsChanged)
                {
                    foreach (ISound Sound in SoundsPerSlice)
                    {
                        ISoundEffectControl Fx = Sound.SoundEffectControl;

                        if (FEnableWaveReverb[i])
                        {
                            Fx.EnableWavesReverbSoundEffect(FWaveReverbInGain[i], FWaveReverbMix[i], FWaveReverbTime[i], FWaveReverbFreq[i]);
                        }
                        else if (Fx != null)
                        {
                            Fx.DisableWavesReverbSoundEffect();
                        }
                    }
                }

                #endregion Wave Reverb

                //Disables all Effekts
                #region Disable All Effekts

                if (FDisableAllEffekt.IsChanged)
                {
                    foreach (ISound Sound in SoundsPerSlice)
                    {
                        ISoundEffectControl Fx = Sound.SoundEffectControl;
                        if (FDisableAllEffekt[i])
                        {
                            Fx.DisableAllEffects();
                        }
                    }
                }

                #endregion Disabel All Effects

                #endregion Effekts
            }

            //stops or paused all SoundSource which are playedback with the Irrklangengine
            #region Stop / Pause All

            if (FStopAll.IsChanged)
            {
                if (FStopAll[0])
                {
                    FEngine.StopAllSounds();
                }
            }

            if (FPauseAll.IsChanged)
            {
                if (FPause[0])
                {
                    FEngine.SetAllSoundsPaused(true);
                }
                else
                {
                    FEngine.SetAllSoundsPaused(false);
                }
            }

            #endregion Stop / Pause All

            //set the Listener Position of the Engine
            #region View Listener

            if (FViewDir.IsChanged || FViewPos.IsChanged || FViewUpVector.IsChanged || FViewVelocity.IsChanged)
            {
                IrrKlang.Vector3D ViewDir      = new IrrKlang.Vector3D((float)FViewDir[0].x, (float)FViewDir[0].y, (float)FViewDir[0].z);
                IrrKlang.Vector3D ViewPos      = new IrrKlang.Vector3D((float)FViewPos[0].x, (float)FViewPos[0].y, (float)FViewPos[0].z);
                IrrKlang.Vector3D ViewVelocity = new IrrKlang.Vector3D((float)FViewVelocity[0].x, (float)FViewVelocity[0].y, (float)FViewVelocity[0].z);
                IrrKlang.Vector3D ViewUp       = new IrrKlang.Vector3D((float)FViewUpVector[0].x, (float)FViewUpVector[0].y, (float)FViewUpVector[0].z);
                FEngine.SetListenerPosition(ViewDir, ViewPos, ViewVelocity, ViewUp);
            }

            #endregion View Listener

            //sets the RollOff effekt of the Engine
            #region RollOff

            if (FRollOff.IsChanged)
            {
                FEngine.SetRolloffFactor(FRollOff[0]);
            }

            #endregion RollOFF

            //sets the DopllerEffekt of the Engine
            #region DopplerEffekt

            if (FDoplerFactor.IsChanged || FDoplerDistanceFactor.IsChanged)
            {
                FEngine.SetDopplerEffectParameters(FDoplerFactor[0], FDoplerDistanceFactor[0]);
            }

            #endregion DopplerEffekt

            FPreviousSpreadMax = SpreadMax;
        }
예제 #13
0
        public void PlaySFX(string sound, Vector2 position)
        {
            Vector2 source = (Game as MainGame).Camera.GetTargetPosition() - position;

            bgmEngine.Play3D($"content/audio/sfx/{sound}.ogg", source.X, 0, source.Y, false);
        }