Exemple #1
0
        private void Dispose(bool manually)
        {
            if (!this.disposed)
            {
                this.disposed              = true;
                DualityApp.AppDataChanged -= this.DualityApp_AppDataChanged;

                // Shut down the streaming thread
                if (this.streamWorker != null)
                {
                    this.streamWorkerEnd = true;
                    if (!this.streamWorker.Join(1000))
                    {
                        this.streamWorker.Abort();
                    }
                    this.streamWorkerQueueEvent.Dispose();
                    this.streamWorkerEnd        = false;
                    this.streamWorkerQueueEvent = null;
                    this.streamWorkerQueue      = null;
                    this.streamWorker           = null;
                }

                try
                {
                    // Clear all playing sounds
                    foreach (SoundInstance inst in this.sounds)
                    {
                        inst.Dispose();
                    }
                    this.sounds.Clear();

                    // Clear all audio related Resources
                    ContentProvider.RemoveAllContent <AudioData>();
                    ContentProvider.RemoveAllContent <Sound>();

                    // Clear OpenAL source pool
                    foreach (int alSource in this.alSourcePool)
                    {
                        AL.DeleteSource(alSource);
                    }

                    // Shut down OpenAL context
                    if (this.context != null)
                    {
                        this.context.Dispose();
                        this.context = null;
                    }

                    AudioLibraryLoader.UnloadAudioLibrary();
                }
                catch (Exception e)
                {
                    Log.Core.WriteError("An error occured while shutting down OpenAL: {0}", Log.Exception(e));
                }
            }
        }
Exemple #2
0
        public SoundDevice()
        {
            Log.Core.Write("Initializing OpenAL...");
            Log.Core.PushIndent();
            try
            {
                AudioLibraryLoader.LoadAudioLibrary();

                Log.Core.Write("Available devices:" + Environment.NewLine + "{0}",
                               AudioContext.AvailableDevices.ToString(d => d == AudioContext.DefaultDevice ? d + " (Default)" : d, "," + Environment.NewLine));

                // Create OpenAL audio context
                this.context = new AudioContext();
                Log.Core.Write("Current device: {0}", this.context.CurrentDevice);

                // Generate OpenAL source pool
                while (true)
                {
                    int newSrc = AL.GenSource();
                    if (!DualityApp.CheckOpenALErrors(true))
                    {
                        this.alSourcePool.Push(newSrc);
                    }
                    else
                    {
                        break;
                    }
                }
                this.maxAlSources = this.alSourcePool.Count;
                Log.Core.Write("{0} sources available", this.alSourcePool.Count);
            }
            catch (Exception e)
            {
                Log.Core.WriteError("An error occured while initializing OpenAL: {0}", Log.Exception(e));
            }
            Log.Core.PopIndent();

            // Set up the streaming thread
            this.streamWorkerEnd           = false;
            this.streamWorkerQueue         = new List <SoundInstance>();
            this.streamWorkerQueueEvent    = new AutoResetEvent(false);
            this.streamWorker              = new Thread(ThreadStreamFunc);
            this.streamWorker.IsBackground = true;
            this.streamWorker.Start();

            DualityApp.AppDataChanged += this.DualityApp_AppDataChanged;
        }
Exemple #3
0
        public SoundDevice()
        {
            Log.Core.Write("Initializing OpenAL...");
            Log.Core.PushIndent();

            try
            {
                AudioLibraryLoader.LoadAudioLibrary();

                Log.Core.Write("Available devices:" + Environment.NewLine + "{0}",
                               AudioContext.AvailableDevices.ToString(d => d == AudioContext.DefaultDevice ? d + " (Default)" : d, "," + Environment.NewLine));

                // Create OpenAL audio context
                this.context = new AudioContext();
                Log.Core.Write("Current device: {0}", this.context.CurrentDevice);

                // Generate OpenAL source pool
                while (true)
                {
                    int newSrc = AL.GenSource();
                    if (!DualityApp.CheckOpenALErrors(true))
                    {
                        this.alSourcePool.Push(newSrc);
                    }
                    else
                    {
                        break;
                    }
                }
                this.maxAlSources = this.alSourcePool.Count;
                Log.Core.Write("{0} sources available", this.alSourcePool.Count);
            }
            catch (Exception e)
            {
                Log.Core.WriteError("An error occured while initializing OpenAL: {0}", Log.Exception(e));
            }

            Log.Core.PopIndent();

            DualityApp.AppDataChanged += this.DualityApp_AppDataChanged;
        }