Exemple #1
0
        internal static void Init(IntPtr mainWindowHandle)
        {
            if (instance != null)
            {
                Log.Fatal("SoundWorld: Init: The sound system is already initialized.");
            }

            CreateSoundWorldInstance();

            var maxReal2DChannels = EngineSettings.Init.SoundMaxReal2DChannels;
            var maxReal3DChannels = EngineSettings.Init.SoundMaxReal3DChannels;

            if (instance == null || !instance.InitLibrary(mainWindowHandle, maxReal2DChannels, maxReal3DChannels))
            {
                Shutdown();

                instance = new NULLSoundWorld();
                instance.InitLibrary(mainWindowHandle, maxReal2DChannels, maxReal3DChannels);
            }

            if (instance is NULLSoundWorld)
            {
                maxReal2DChannels = 0;
                maxReal3DChannels = 0;
            }

            instance.InitInternal(maxReal2DChannels, maxReal3DChannels);

            if (_Instance != null)
            {
                Log.InvisibleInfo(string.Format("Sound system is initialized (Driver: {0})", _Instance._DriverName));
            }
        }
Exemple #2
0
        public virtual void PlaySound(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                return;
            }

            var   mode  = Transform3D != null ? SoundModes.Mode3D : 0;
            Sound sound = SoundWorld.SoundCreate(name, mode);

            if (sound == null)
            {
                return;
            }

            //!!!!attachedToScene
            var channel = SoundWorld.SoundPlay(null, sound, EngineApp.DefaultSoundChannelGroup, 0.5, true);

            if (channel != null)
            {
                if (Transform3D != null)
                {
                    channel.Position = Transform3D.Position;
                    //channel.Velocity = xxx;
                }
                channel.Pause = false;
            }
        }
Exemple #3
0
 internal static void Shutdown()
 {
     if (instance != null)
     {
         instance.ShutdownInternal();
         instance.ShutdownLibrary();
         instance = null;
     }
 }
Exemple #4
0
        static void CreateSoundWorldInstance()
        {
            if (string.Compare(EngineSettings.Init.SoundSystemDLL, "null", true) != 0)
            {
                string fullPath = "";
                if (!string.IsNullOrEmpty(EngineSettings.Init.SoundSystemDLL))
                {
                    string fullPath2 = Path.Combine(VirtualFileSystem.Directories.Binaries, EngineSettings.Init.SoundSystemDLL);
                    if (File.Exists(fullPath2))
                    {
                        fullPath = fullPath2;
                    }
                }

                if (fullPath != "")
                {
                    try
                    {
                        Assembly assembly = AssemblyUtility.LoadAssemblyByRealFileName(fullPath, false);

                        Type foundType = null;
                        foreach (Type type in assembly.GetTypes())
                        {
                            if (!type.IsAbstract && typeof(SoundWorld).IsAssignableFrom(type))
                            {
                                foundType = type;
                                break;
                            }
                        }

                        if (foundType == null)
                        {
                            Log.Fatal("SoundWorld: CreateSoundWorldInstance: SoundWorld based class is not available in the assembly \'{0}\'.", assembly.FullName);
                        }

                        ConstructorInfo constructor = foundType.GetConstructor(new Type[0] {
                        });
                        instance = (SoundWorld)constructor.Invoke(null);
                    }
                    catch (Exception e)
                    {
                        Log.Fatal("SoundWorld: CreateSoundWorldInstance: Loading assembly failed \'{0}\' ({1}).", fullPath, e.Message);
                    }
                }
                else
                {
                    //if( SystemSettings.CurrentPlatform != SystemSettings.Platform.UWP )
                    //{

                    //default sound system
                    instance = new OpenALSoundSystem.OpenALSoundWorld();

                    //}
                }
            }
        }
Exemple #5
0
            //public Sound Sound
            //{
            //	get { return sound; }
            //}

            //Sound GetSoundByMode( SoundModes mode )
            //{
            //	soundByMode.TryGetValue( mode, out var sound );
            //	return sound;
            //}

            public Sound LoadSoundByMode(SoundModes mode)
            {
                if (!soundByMode.TryGetValue(mode, out var sound))
                {
                    //!!!!threading

                    var v            = owner.LoadFile.Value;
                    var resourceName = v != null ? v.ResourceName : "";

                    if (VirtualFile.Exists(resourceName))
                    {
                        sound = SoundWorld.SoundCreate(resourceName, mode);
                    }

                    soundByMode.Add(mode, sound);
                }
                return(sound);
            }
Exemple #6
0
        public virtual void PlaySound(Component_Sound sound)
        {
            var mode   = Transform3D != null ? SoundModes.Mode3D : 0;
            var sound2 = sound?.Result?.LoadSoundByMode(mode);

            if (sound2 == null)
            {
                return;
            }

            //!!!!attachedToScene
            var channel = SoundWorld.SoundPlay(null, sound2, EngineApp.DefaultSoundChannelGroup, 0.5, true);

            if (channel != null)
            {
                if (Transform3D != null)
                {
                    channel.Position = Transform3D.Position;
                    //channel.Velocity = xxx;
                }
                channel.Pause = false;
            }
        }
        void Play()
        {
            if (playCalling)
            {
                return;
            }
            playCalling = true;

            Stop();

            if (EnabledInHierarchyAndIsNotResource && ParentScene != null)
            {
                var res = ParentRoot?.HierarchyController?.CreatedByResource;
                if (res != null && res.InstanceType == Resource.InstanceType.SeparateInstance)
                {
                    var soundComponent = Sound.Value;
                    if (soundComponent != null && soundComponent.Result != null)
                    {
                        bool streaming = false;

                        switch (Streaming.Value)
                        {
                        case StreamingEnum.Auto:
                        {
                            string fileName = soundComponent.LoadFile.Value.ResourceName;
                            if (!string.IsNullOrEmpty(fileName) && Path.GetExtension(fileName).ToLower() == ".ogg")
                            {
                                long length = 0;
                                try
                                {
                                    length = VirtualFile.GetLength(fileName);
                                }
                                catch { }
                                if (length > 400000)
                                {
                                    streaming = true;
                                }
                            }
                        }
                        break;

                        case StreamingEnum.Enable:
                            streaming = true;
                            break;
                        }

                        SoundModes mode = SoundModes.Mode3D;
                        if (ReplayDelay == 0 || streaming)                         //if( replayDelay == 0 )
                        {
                            mode |= SoundModes.Loop;
                        }
                        if (streaming)
                        {
                            mode |= SoundModes.Stream;
                        }

                        sound = soundComponent.Result.LoadSoundByMode(mode);
                        if (sound != null)
                        {
                            channel = SoundWorld.SoundPlay(ParentScene, sound, EngineApp.DefaultSoundChannelGroup, Priority, true);
                            if (channel != null)
                            {
                                channel.Position = Transform.Value.Position;
                                channel.Volume   = Volume;
                                UpdateChannelRolloffGraph();
                                channel.Pitch = Pitch;

                                OnBeforePlay();
                                BeforePlayEvent?.Invoke(this);

                                channel.Pause = false;

                                lastUpdateEngineTime = EngineApp.EngineTime;
                            }
                        }
                    }
                }
            }

            playCalling = false;
        }