コード例 #1
0
        /// <summary>
        /// Creates an audio context
        /// </summary>
        /// <param name="device">Name of the device to use</param>
        /// <returns></returns>
        static public bool Create(string device)
        {
            if (Context != null)
            {
                Release();
            }

            // No context
            if (string.IsNullOrEmpty(device))
            {
                Trace.WriteLine("[AudioManager] Create() : Empty device name.");
                return(false);
            }

            Trace.WriteLine("[AudioManager] : Creating a new context on \"{0}\"", device);


            try
            {
                Context = new OpenTK.Audio.AudioContext(device);
            }
            catch (Exception e)
            {
                Trace.WriteLine("[AudioManager] Create() : " + e.Message);
                return(false);
            }


            IsInit = true;
            Trace.WriteLine("[AudioManager] : Created on device \"{0}\"", Context.CurrentDevice);

            Diagnostic();

            return(true);
        }
コード例 #2
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));
                }
            }
        }
コード例 #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();

            // 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;
        }
コード例 #4
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;
        }
コード例 #5
0
ファイル: SoundDevice.cs プロジェクト: Banbury/duality
        private void Dispose(bool manually)
        {
            if (!this.disposed)
            {
                this.disposed              = true;
                DualityApp.AppDataChanged -= this.DualityApp_AppDataChanged;

                foreach (SoundInstance inst in this.sounds)
                {
                    inst.Dispose();
                }
                this.sounds.Clear();

                ContentProvider.RemoveAllContent <Sound>();

                if (this.context != null)
                {
                    this.context.Dispose();
                    this.context = null;
                }
            }
        }
コード例 #6
0
ファイル: SoundDevice.cs プロジェクト: hbcameleon/duality
        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;
        }
コード例 #7
0
ファイル: SoundDevice.cs プロジェクト: swtrse/duality
		private void Dispose(bool manually)
		{
			if (!this.disposed)
			{
				this.disposed = true;
				DualityApp.AppDataChanged -= this.DualityApp_AppDataChanged;
				
				foreach (SoundInstance inst in this.sounds) inst.Dispose();
				this.sounds.Clear();

				ContentProvider.RemoveAllContent<Sound>();

				try
				{
					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));
				}
			}
		}
コード例 #8
0
 internal AudioContext(string deviceName, int sampleRate, int refresh)
 {
     context         = new OpenTK.Audio.AudioContext(deviceName, sampleRate, refresh);
     resourceManager = new ResourceManager();
 }
コード例 #9
0
ファイル: SoundDevice.cs プロジェクト: Banbury/duality
		private void Dispose(bool manually)
		{
			if (!this.disposed)
			{
				this.disposed = true;
				DualityApp.AppDataChanged -= this.DualityApp_AppDataChanged;
				
				foreach (SoundInstance inst in this.sounds) inst.Dispose();
				this.sounds.Clear();

				ContentProvider.RemoveAllContent<Sound>();

				if (this.context != null)
				{
					this.context.Dispose();
					this.context = null;
				}
			}
		}
コード例 #10
0
ファイル: AudioContext.cs プロジェクト: polytronicgr/audio
 private AudioContext(AudioConfig config)
 {
     this.Config = config;
     this.ctx    = new ALContext();
 }
コード例 #11
0
ファイル: SoundDevice.cs プロジェクト: hbcameleon/duality
        private void Dispose(bool manually)
        {
            if (!this.disposed)
            {
                this.disposed = true;
                DualityApp.AppDataChanged -= this.DualityApp_AppDataChanged;

                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));
                }
            }
        }
コード例 #12
0
		protected virtual void OnDisposed(bool manually)
		{
			foreach (SoundInstance inst in this.sounds) inst.Dispose();
			this.sounds.Clear();

			ContentProvider.UnregisterAllContent<Sound>();

			this.context.Dispose();
			this.context = null;
		}
コード例 #13
0
		public SoundDevice()
		{
			this.context = new AudioContext();

			// 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(
				"OpenAL initialized. {0} sound sources available",
				this.alSourcePool.Count);

			DualityApp.AppDataChanged += this.DualityApp_AppDataChanged;
		}
コード例 #14
0
ファイル: SoundDevice.cs プロジェクト: KSLcom/duality
		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;
		}