Ejemplo n.º 1
0
        //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;
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
0
        //called when data for any output pin is requested
        public void Evaluate(int SpreadMax)
        {
            //1- Copy all the parameters to the settings object
            STimSettings.CloseZoneConstrain = FInCloseZoneConstrain[0];
            STimSettings.InteractionZoneConstrain = FInInteractionZoneConstrain[0];
            STimSettings.NotificationZoneConstrain = FInNotificationZoneConstrain[0];

            STimSettings.BlockPercentBufferSize = FInBlockPercentBufferSize[0];
            STimSettings.BlockDepthPercent = FInBlockDepthPercent[0];

            STimSettings.UploadPeriod = FInUploadPeriod[0];

            STimSettings.ImageFolder = FInImageFolder[0];
            STimSettings.DateTimeFileNameFormat = FInDateTimeFileNameFormat[0];
            STimSettings.DateTimeLogFormat = FInDateTimeLogFormat[0];

            STimSettings.DisplayWidthInMeters = FInDisplayWidthInMeters[0];
            STimSettings.DisplayHeightInMeters = FInDisplayHeightInMeters[0];

            STimSettings.KinectDistanceZ = FInKinectDisplayDistanceZ[0];
            STimSettings.KinectDistanceY = FInKinectDisplayDistanceY[0];

            STimSettings.ScreenGridRows = FInScreenGridRows[0];
            STimSettings.ScreenGridColumns = FInScreenGridColumns[0];

            STimSettings.IncludeStatusRender = FInIncludeStatusRender[0];
            //2- Initialize if it's the first time
            if (!STim.Core.Instance.IsInitialized && FInEnableCore[0])
            {
                log4net.Config.XmlConfigurator.Configure(new FileInfo("logger.xml"));
                log4net.ILog visitLogger = log4net.LogManager.GetLogger("VisitLogger");
                log4net.ILog statusLogger = log4net.LogManager.GetLogger("StatusLogger");
                try
                {
                    STim.Core.Instance.Initialize(Dispatcher.CurrentDispatcher, visitLogger, statusLogger);
                    FOutExcept1[0] = "OK";
                }
                catch (Exception ex)
                {
                    FOutExcept1[0] = ex.Message;
                }
            }

            if (STim.Core.Instance.IsInitialized && !FInEnableCore[0])
            {
                STim.Core.Instance.Shutdown();
            }

            try
            {
                if (STim.Core.Instance.ClosestVisitor != null)
                {
                    FOutHeadLocation[0] = new VVVV.Utils.VMath.Vector3D(STim.Core.Instance.ClosestVisitor.HeadLocation.X, STim.Core.Instance.ClosestVisitor.HeadLocation.Y, STim.Core.Instance.ClosestVisitor.HeadLocation.Z);
                }
                else
                {
                    FOutHeadLocation[0] = new VVVV.Utils.VMath.Vector3D(0, 0, STimSettings.NotificationZoneConstrain);
                }
                FOutExcept2[0] = "OK";
            }
            catch (Exception ex)
            {
                FOutExcept2[0] = ex.Message;
            }
        }