コード例 #1
0
        public static IAudio LoadWave(string filePath)
        {
            if (_disposables.ContainsKey(filePath))
            {
                return((IAudio)_disposables[filePath]);
            }

            IntPtr        device = Alc.OpenDevice(null);
            ContextHandle handle = Alc.CreateContext(device, (int[])null);

            Alc.MakeContextCurrent(handle);

            int buffer = AL.GenBuffer();
            int source = AL.GenSource();

            WaveFileReader reader = new WaveFileReader(filePath);

            byte[] data = new byte[reader.Length];
            reader.Read(data, 0, data.Length);

            AL.BufferData(buffer, GetSoundFormat(reader.WaveFormat.Channels, reader.WaveFormat.BitsPerSample), data,
                          data.Length, reader.WaveFormat.SampleRate);
            AL.Source(source, ALSourcei.Buffer, buffer);

            IAudio audio = new WaveAudio(filePath, source, buffer, handle);

            _disposables.TryAdd(filePath, audio);
            return(audio);
        }
コード例 #2
0
        private OpenALSoundController()
        {
            alcMacOSXMixerOutputRate(PREFERRED_MIX_RATE);
            _device = Alc.OpenDevice(string.Empty);
            CheckALError("Could not open AL device");
            if (_device != IntPtr.Zero)
            {
                int[] attribute = new int[0];
                _context = Alc.CreateContext(_device, attribute);
                CheckALError("Could not open AL context");

                if (_context != ContextHandle.Zero)
                {
                    Alc.MakeContextCurrent(_context);
                    CheckALError("Could not make AL context current");
                }
            }
            else
            {
                return;
            }

            allSourcesArray = new int[MAX_NUMBER_OF_SOURCES];
            AL.GenSources(allSourcesArray);

            availableSourcesCollection = new HashSet <int> ();
            inUseSourcesCollection     = new HashSet <OALSoundBuffer> ();
            playingSourcesCollection   = new HashSet <OALSoundBuffer> ();


            for (int x = 0; x < MAX_NUMBER_OF_SOURCES; x++)
            {
                availableSourcesCollection.Add(allSourcesArray [x]);
            }
        }
コード例 #3
0
 public ALOutput(DataSource data)
 {
     this._source = data;
     this._dev    = Alc.OpenDevice((string)null);
     if (this._dev.Equals((object)IntPtr.Zero))
     {
         throw new AudioException("Failed to init OpenAL");
     }
     Alc.MakeContextCurrent(Alc.CreateContext(this._dev, new int[2]
     {
         4103,
         44100
     }));
     float[] values = new float[6]
     {
         0.0f,
         0.0f,
         1f,
         0.0f,
         1f,
         0.0f
     };
     AL.Listener(ALListener3f.Position, 0.0f, 0.0f, 0.0f);
     AL.Listener(ALListener3f.Velocity, 0.0f, 0.0f, 0.0f);
     AL.Listener(ALListenerfv.Orientation, ref values);
     AL.DistanceModel(ALDistanceModel.None);
     this._sChannels = new ALOutput.Channel[16];
     for (int index = 0; index < this._sChannels.Length; ++index)
     {
         this._sChannels[index].Handle = AL.GenSource();
     }
     ALOutput.Check();
     new Thread(new ThreadStart(this.ThreadProc)).Start();
 }
コード例 #4
0
ファイル: AudioContext.cs プロジェクト: OpenCGSS/SharpAL
 public AudioContext([NotNull] AudioDevice device, [CanBeNull] int[] attribList)
 {
     _context     = Alc.CreateContext(device.NativeDevice, attribList);
     Device       = device;
     _watchThread = new WatchThread(this);
     _watchThread.Start();
 }
コード例 #5
0
        public static void Main(string[] args)
        {
            var device  = Alc.OpenDevice(null);
            var context = Alc.CreateContext(device, null);

            Console.WriteLine(Alc.MakeContextCurrent(context));
        }
コード例 #6
0
        /// <summary>
        /// Open the sound device, sets up an audio context, and makes the new context
        /// the current context. Note that this method will stop the playback of
        /// music that was running prior to the game start. If any error occurs, then
        /// the state of the controller is reset.
        /// </summary>
        /// <returns>True if the sound controller was setup, and false if not.</returns>
        private bool OpenSoundController()
        {
#if MACOSX || IOS
            alcMacOSXMixerOutputRate(PREFERRED_MIX_RATE);
#endif
            _device = Alc.OpenDevice(string.Empty);
            if (CheckALError("Could not open AL device"))
            {
                return(false);
            }
            if (_device != IntPtr.Zero)
            {
                int[] attribute = new int[0];
                _context = Alc.CreateContext(_device, attribute);
                if (CheckALError("Could not open AL context"))
                {
                    CleanUpOpenAL();
                    return(false);
                }

                if (_context != ContextHandle.Zero)
                {
                    Alc.MakeContextCurrent(_context);
                    if (CheckALError("Could not make AL context current"))
                    {
                        CleanUpOpenAL();
                        return(false);
                    }
                    return(true);
                }
            }
            return(false);
        }
コード例 #7
0
        public static OpenALAudioAdapter TryCreate(PlatformBase _)
        {
            var newCtx = new OpenALAudioAdapter();

            newCtx.AudioDevice = Alc.OpenDevice(null);
            if (newCtx.AudioDevice == IntPtr.Zero)
            {
                Engine.Log.Error("Couldn't find an OpenAL device.", MessageSource.OpenAL);
                return(null);
            }

            var attr = new int[0];

            newCtx.AudioContext = Alc.CreateContext(newCtx.AudioDevice, attr);
            if (newCtx.AudioContext == IntPtr.Zero)
            {
                Engine.Log.Error("Couldn't create OpenAL context.", MessageSource.OpenAL);
                return(null);
            }

            bool success = Alc.MakeContextCurrent(newCtx.AudioContext);

            if (!success)
            {
                Engine.Log.Error("Couldn't make OpenAL context current.", MessageSource.OpenAL);
                return(null);
            }

            return(newCtx);
        }
コード例 #8
0
ファイル: SID_OpenAL.cs プロジェクト: Schniedel2/C64eMullator
 public SID_OpenAL() : base()
 {
     ALDevice = Alc.OpenDevice(null);
     int[] attribs = null;
     context = Alc.CreateContext(ALDevice, attribs);
     Alc.MakeContextCurrent(context);
 }
コード例 #9
0
 public static void InitialSetup()
 {
     // FOR THE LOVE OF GOD PLEASE LET THIS WORK
     AudioDevice = Alc.OpenDevice(null);  // Default device
     if (AudioDevice != null)
     {
         AudioCtx = Alc.CreateContext(AudioDevice, (int[])null);
         if (AudioCtx != ContextHandle.Zero)
         {
             Alc.GetError(AudioDevice);
             if (Alc.MakeContextCurrent(AudioCtx))
             {
                 //LoadWaveFile ("camprespite_loop", "camprespite_loop.wav");
                 LoadWaveFile("last_human_loop", "last_human_loop_limited.wav"); //.DurationAdjust(0.01);
                 LoadWaveFile("induction_loop", "induction_loop.wav");
                 LoadWaveFile("sfx_bullet_impact", "sfx_bullet_impact.wav");
                 LoadWaveFile("sfx_player_land_two_feet", "sfx_player_land_two_feet.wav");
                 LoadWaveFile("sfx_shoot_gun", "sfx_shoot_gun.wav");
                 LoadWaveFile("win", "win.wav");
             }
             else
             {
                 throw new Exception("Failed to set current audio context");
             }
         }
         else
         {
             throw new Exception("Failed to create audio context.");
         }
     }
     else
     {
         throw new Exception("Failed to open default audio device.");
     }
 }
コード例 #10
0
        private bool INTERNAL_initSoundController()
        {
#if IOS
            alcMacOSXMixerOutputRate(44100);
#endif
            try
            {
                _device = Alc.OpenDevice(string.Empty);
            }
            catch
            {
                return(false);
            }
            if (CheckALCError("Could not open AL device") || _device == IntPtr.Zero)
            {
                return(false);
            }

            int[] attribute = new int[0];
            _context = Alc.CreateContext(_device, attribute);
            if (CheckALCError("Could not create OpenAL context") || _context == ContextHandle.Zero)
            {
                Dispose(true);
                return(false);
            }

            Alc.MakeContextCurrent(_context);
            if (CheckALCError("Could not make OpenAL context current"))
            {
                Dispose(true);
                return(false);
            }

            return(true);
        }
コード例 #11
0
        public AccelerometerMusicBuffer()
        {
            _sampleRate = 44100;
            _device     = Alc.OpenDevice(null);
            _context    = Alc.CreateContext(_device, (int *)null);
            Alc.MakeContextCurrent(_context);
            //AL.GenBuffers(1, out uint buffers);
            _buffers = AL.GenBuffers(8);
            AL.GenBuffer(out uint bassABuffer);
            //_buffers = buffers;
            AL.GenSource(out _sourceOne);
            AL.GenSource(out _sourceTwo);
            AL.GenSource(out _sourceThree);
            AL.GenSource(out _sourceFour);
            AL.GenSource(out _sourceFive);
            var bassWave = ResolveSineWave(0.25 * short.MaxValue, 110);

            AL.BufferData((int)bassABuffer, ALFormat.Mono16, bassWave, bassWave.Length, _sampleRate);
            AL.Source(_sourceFive, ALSourceb.Looping, true);

            AL.SourceQueueBuffer((int)_sourceFive, (int)bassABuffer);
            AL.SourcePlay(_sourceFive);
            _leftHandData  = new List <int>();
            _rightHandData = new List <int>();
        }
コード例 #12
0
        private static void TryInitAudio()
        {
            int tries = 0;

            while (mAudioOn == false && tries < 10)
            {
                try
                {
                    mDeviceID = Alc.OpenDevice(null);
                    KWLogger.Log("Initializing OpenAL (Attempt #" + tries + ")", "GLAudioEngine::TryInitAudio");
                    Console.WriteLine("Initializing audio engine OpenAL (Attempt #" + tries + ")... ");
                    int[] attributes = new int[0];
                    mContext = Alc.CreateContext(mDeviceID, attributes);
                    Alc.MakeContextCurrent(mContext);
                    var version = AL.Get(ALGetString.Version);
                    var vendor  = AL.Get(ALGetString.Vendor);

                    if (version == null)
                    {
                        KWLogger.Log("No Audio devices found.", "GLAudioEngine::TryInitAudio", LogLevel.Error);
                        throw new Exception("No Audio devices found.");
                    }

                    Console.Write('\t' + version + " " + vendor);
                    Console.WriteLine(" Init complete.");
                    KWLogger.Log("Audio initialized: " + version + " " + vendor, "GLAudioEngine::TryInitAudio");
                    mAudioOn = true;
                }

                catch (Exception)
                {
                    mAudioOn = false;
                }

                if (mAudioOn == false)
                {
                    tries++;
                    Thread.Sleep(500);
                }
            }
            IsInitializing = false;

            if (mAudioOn)
            {
                for (int i = 0; i < mChannels; i++)
                {
                    GLAudioSource s = new GLAudioSource();
                    mSources.Add(s);
                }
            }
            else
            {
                Console.WriteLine("\t\t(Giving up on initializing the audio engine. Sorry.)");
                KWLogger.Log("Giving up on initializing the audio engine. Sorry.", "GLAudioEngine::TryInitAudio", LogLevel.Error);
            }
        }
コード例 #13
0
ファイル: ContextManager.cs プロジェクト: nsglover/Bronze
        static ContextManager()
        {
            var device = Alc.OpenDevice(null);

            if (device != IntPtr.Zero)
            {
                AudioContext = Alc.CreateContext(device, null);
                Alc.MakeContextCurrent(AudioContext);
            }
        }
コード例 #14
0
        public static void Init()
        {
            var deviceName = Alc.GetString(IntPtr.Zero, AlcGetString.DefaultAllDevicesSpecifier);

            Console.WriteLine(deviceName);
            _device  = Alc.OpenDevice(deviceName);
            _context = Alc.CreateContext(_device, (int[])null);
            Alc.MakeContextCurrent(_context);
            CheckError();
        }
コード例 #15
0
        public AudioDevice(string device = null)
        {
            if (device == null)
            {
                device = Alc.GetString(IntPtr.Zero, AlcGetString.DefaultDeviceSpecifier);
            }

            deviceId      = Alc.OpenDevice(device);
            contextHandle = Alc.CreateContext(deviceId, new int[] { });
            this.Use();
        }
コード例 #16
0
        public AlPlayer(IMusicPlayer player, int rate)
        {
            _player = player;
            _rate   = rate;

            _device  = Alc.OpenDevice(null);
            _context = Alc.CreateContext(_device, null);

            Console.WriteLine(Alc.GetString(IntPtr.Zero, Alc.AllDevicesSpecifier));

            Alc.MakeContextCurrent(_context);
        }
コード例 #17
0
        static int[] Initialize(out IntPtr device, out ContextHandle context, out int source)
        {
            device  = Alc.OpenDevice(null);
            context = Alc.CreateContext(device, (int[])null);
            Alc.MakeContextCurrent(context);

            var buffers = AL.GenBuffers(BuffersCount);

            AL.GenSources(1, out source);

            return(buffers);
        }
コード例 #18
0
ファイル: SoundSource.cs プロジェクト: TodesBrot/Mekanik
        private static void _CreateAudioContext()
        {
            IntPtr d = Alc.OpenDevice(OpenTK.Audio.AudioContext.DefaultDevice);

            OpenTK.ContextHandle c = Alc.CreateContext(d, new int[0]);
            Alc.MakeContextCurrent(c);

            AL.Listener(ALListener3f.Position, 0, 0, 0);
            AL.Listener(ALListener3f.Velocity, 0, 0, 0);
            float[] vs = new float[] { 0, 0, -1, 0, 1, 0 };
            AL.Listener(ALListenerfv.Orientation, ref vs);
        }
コード例 #19
0
        // --- initialization and deinitialization ---

        /// <summary>Initializes audio. A call to Deinitialize must be made when terminating the program.</summary>
        /// <returns>Whether initializing audio was successful.</returns>
        internal static bool Initialize()
        {
            Deinitialize();
            switch (Options.Current.SoundRange)
            {
            case SoundRange.Low:
                OuterRadiusFactorMinimum      = 2.0;
                OuterRadiusFactorMaximum      = 8.0;
                OuterRadiusFactorMaximumSpeed = 1.0;
                break;

            case SoundRange.Medium:
                OuterRadiusFactorMinimum      = 4.0;
                OuterRadiusFactorMaximum      = 16.0;
                OuterRadiusFactorMaximumSpeed = 2.0;
                break;

            case SoundRange.High:
                OuterRadiusFactorMinimum      = 6.0;
                OuterRadiusFactorMaximum      = 24.0;
                OuterRadiusFactorMaximumSpeed = 3.0;
                break;
            }
            OuterRadiusFactor      = Math.Sqrt(OuterRadiusFactorMinimum * OuterRadiusFactorMaximum);
            OuterRadiusFactorSpeed = 0.0;
            OpenAlDevice           = Alc.OpenDevice(null);
            if (OpenAlDevice != IntPtr.Zero)
            {
                OpenAlContext = Alc.CreateContext(OpenAlDevice, new int[0]);
                if (OpenAlContext != ContextHandle.Zero)
                {
                    Alc.MakeContextCurrent(OpenAlContext);
                    try {
                        AL.SpeedOfSound(343.0f);
                    } catch {
                        Debug.AddMessage(Debug.MessageType.Error, false, "OpenAL 1.1 is required. You seem to have OpenAL 1.0.");
                    }
                    AL.DistanceModel(ALDistanceModel.None);
                    return(true);
                }
                AlcError error = Alc.GetError(OpenAlDevice);
                Alc.CloseDevice(OpenAlDevice);
                OpenAlDevice = IntPtr.Zero;
                Debug.AddMessage(Debug.MessageType.Error, false, "The OpenAL context could not be created: " + error);
                return(false);
            }
            ALError devError = AL.GetError();

            OpenAlContext = ContextHandle.Zero;
            Debug.AddMessage(Debug.MessageType.Error, false, "The OpenAL sound device could not be opened: " + AL.GetErrorString(devError));
            return(false);
        }
コード例 #20
0
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            var device  = Alc.OpenDevice(null);
            var context = Alc.CreateContext(device, (int[])null);

            Alc.MakeContextCurrent(context);
            Application.Run(new MainWindow());
            Alc.MakeContextCurrent(OpenTK.ContextHandle.Zero);
            Alc.DestroyContext(context);
            Alc.CloseDevice(device);
        }
コード例 #21
0
ファイル: AudioManager.cs プロジェクト: shff/gk3tools
        public static void Init()
        {
            _device  = Alc.OpenDevice(null);
            _context = Alc.CreateContext(_device, (int[])null);
            Alc.MakeContextCurrent(_context);
            AL.DistanceModel(ALDistanceModel.InverseDistanceClamped);

            for (int i = 0; i < _maxSources; i++)
            {
                _sources[i].Source = new AudioSource();
                _sources[i].Owner  = null;
            }
        }
コード例 #22
0
ファイル: Sounds.cs プロジェクト: piotrulos/OpenBVE
        // --- initialization and deinitialization ---

        /// <summary>Initializes audio. A call to Deinitialize must be made when terminating the program.</summary>
        /// <returns>Whether initializing audio was successful.</returns>
        internal static void Initialize()
        {
            Deinitialize();
            switch (Interface.CurrentOptions.SoundRange)
            {
            case Interface.SoundRange.Low:
                OuterRadiusFactorMinimum      = 2.0;
                OuterRadiusFactorMaximum      = 8.0;
                OuterRadiusFactorMaximumSpeed = 1.0;
                break;

            case Interface.SoundRange.Medium:
                OuterRadiusFactorMinimum      = 4.0;
                OuterRadiusFactorMaximum      = 16.0;
                OuterRadiusFactorMaximumSpeed = 2.0;
                break;

            case Interface.SoundRange.High:
                OuterRadiusFactorMinimum      = 6.0;
                OuterRadiusFactorMaximum      = 24.0;
                OuterRadiusFactorMaximumSpeed = 3.0;
                break;
            }
            OuterRadiusFactor      = Math.Sqrt(OuterRadiusFactorMinimum * OuterRadiusFactorMaximum);
            OuterRadiusFactorSpeed = 0.0;
            OpenAlDevice           = Alc.OpenDevice(null);
            if (OpenAlDevice != IntPtr.Zero)
            {
                OpenAlContext = Alc.CreateContext(OpenAlDevice, (int[])null);
                if (OpenAlContext != ContextHandle.Zero)
                {
                    Alc.MakeContextCurrent(OpenAlContext);
                    try
                    {
                        AL.SpeedOfSound(343.0f);
                    }
                    catch
                    {
                        //MessageBox.Show(Interface.GetInterfaceString("errors_sound_openal_version"), Interface.GetInterfaceString("program_title"), MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    }
                    AL.DistanceModel(ALDistanceModel.None);
                    return;
                }
                Alc.CloseDevice(OpenAlDevice);
                OpenAlDevice = IntPtr.Zero;
                //MessageBox.Show(Interface.GetInterfaceString("errors_sound_openal_context"), Interface.GetInterfaceString("program_title"), MessageBoxButtons.OK, MessageBoxIcon.Hand);
                return;
            }
            OpenAlContext = ContextHandle.Zero;
            //MessageBox.Show(Interface.GetInterfaceString("errors_sound_openal_device"), Interface.GetInterfaceString("program_title"), MessageBoxButtons.OK, MessageBoxIcon.Hand);
        }
コード例 #23
0
        public void ChangeAudioDevice(string DeviceName)
        {
            this.Device = Alc.OpenDevice(DeviceName);

            this.AudioContext = Alc.CreateContext(Device, (int[])null);
            Alc.MakeContextCurrent(AudioContext);

            Alc.GetInteger(Device, AlcGetInteger.AttributesSize, 1, out int size);
            int[] data = new int[size];
            Alc.GetInteger(Device, AlcGetInteger.AllAttributes, size, data);
            this.MaxSourceCount = data[Alc.GetEnumValue(Device, "ALC_MONO_SOURCES")];//ここあやしい

            Sources = AL.GenSources(MaxSourceCount);
        }
コード例 #24
0
        public static void Initialize()
        {
            IntPtr        device  = Alc.OpenDevice("");
            ContextHandle context = Alc.CreateContext(device, new int[0]);

            Alc.MakeContextCurrent(context);

#if DEBUG
            GlobalEvent.EndStep += () =>
            {
                _Audio.ErrorCheck();
            };
#endif
        }
コード例 #25
0
        public OpenAlSoundEngine()
        {
            Console.WriteLine("Using OpenAL sound engine");

            if (Game.Settings.Sound.Device != null)
            {
                Console.WriteLine("Using device `{0}`", Game.Settings.Sound.Device);
            }
            else
            {
                Console.WriteLine("Using default device");
            }

            var dev = Alc.OpenDevice(Game.Settings.Sound.Device);

            if (dev == IntPtr.Zero)
            {
                Console.WriteLine("Failed to open device. Falling back to default");
                dev = Alc.OpenDevice(null);
                if (dev == IntPtr.Zero)
                {
                    throw new InvalidOperationException("Can't create OpenAL device");
                }
            }

            var ctx = Alc.CreateContext(dev, (int[])null);

            if (ctx == ContextHandle.Zero)
            {
                throw new InvalidOperationException("Can't create OpenAL context");
            }
            Alc.MakeContextCurrent(ctx);

            for (var i = 0; i < PoolSize; i++)
            {
                var source = 0;
                AL.GenSources(1, out source);
                if (0 != AL.GetError())
                {
                    Log.Write("sound", "Failed generating OpenAL source {0}", i);
                    return;
                }

                sourcePool.Add(source, new PoolSlot()
                {
                    IsActive = false
                });
            }
        }
コード例 #26
0
ファイル: AudioDevice.cs プロジェクト: aiv01/aiv-audio
        public AudioDevice(string device = null)
        {
            if (device == null)
            {
                device = Alc.GetString(IntPtr.Zero, AlcGetString.DefaultDeviceSpecifier);
            }

            deviceId = Alc.OpenDevice(device);
            if (deviceId == IntPtr.Zero)
            {
                throw new Exception("unable to open the specified audio device");
            }
            contextHandle = Alc.CreateContext(deviceId, new int[] { });
            this.Use();
        }
コード例 #27
0
ファイル: OpenALDevice.cs プロジェクト: lovelife/MonoGame
        public OpenALDevice()
        {
            if (Instance != null)
            {
                throw new Exception("OpenALDevice already created!");
            }

            alDevice = Alc.OpenDevice(string.Empty);
            if (CheckALCError("Could not open AL device") || alDevice == IntPtr.Zero)
            {
                throw new Exception("Could not open AL device!");
            }

            int[] attribute = new int[0];
            alContext = Alc.CreateContext(alDevice, attribute);
            if (CheckALCError("Could not create OpenAL context") || alContext == ContextHandle.Zero)
            {
                Dispose();
                throw new Exception("Could not create OpenAL context");
            }

            Alc.MakeContextCurrent(alContext);
            if (CheckALCError("Could not make OpenAL context current"))
            {
                Dispose();
                throw new Exception("Could not make OpenAL context current");
            }

            EFX = new EffectsExtension();

            float[] ori = new float[]
            {
                0.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f
            };
            AL.Listener(ALListenerfv.Orientation, ref ori);
            AL.Listener(ALListener3f.Position, 0.0f, 0.0f, 0.0f);
            AL.Listener(ALListener3f.Velocity, 0.0f, 0.0f, 0.0f);
            AL.Listener(ALListenerf.Gain, 1.0f);

            // We do NOT use automatic attenuation! XNA does not do this!
            AL.DistanceModel(ALDistanceModel.None);

            instancePool        = new List <SoundEffectInstance>();
            dynamicInstancePool = new List <DynamicSoundEffectInstance>();

            Instance = this;
        }
コード例 #28
0
ファイル: MAudioListener2.cs プロジェクト: BigFun123/Massive
        public MAudioListener2(string inname) : base(EType.AudioListener, inname)
        {
            _instance = this;

            transform = new MTransform();

            device = Alc.OpenDevice(null);
            unsafe
            {
                context = Alc.CreateContext(device, (int *)null);
            }

            Alc.MakeContextCurrent(context);


            //Console.ReadKey();
        }
コード例 #29
0
        // initialize
        internal static void Initialize()
        {
            // openal
            OpenAlDevice = Alc.OpenDevice(null);
            if (OpenAlDevice != IntPtr.Zero)
            {
                OpenAlContext = Alc.CreateContext(OpenAlDevice, (int[])null);
                if (OpenAlContext != ContextHandle.Zero)
                {
                    Alc.MakeContextCurrent(OpenAlContext);
                    AL.SpeedOfSound(343.0f);
                    AL.DistanceModel(ALDistanceModel.None);
                }
                else
                {
                    Alc.CloseDevice(OpenAlDevice);
                    OpenAlDevice = IntPtr.Zero;
                    System.Windows.Forms.MessageBox.Show("The sound device could be opened, but the sound context could not be created.", "openBVE", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
                }
            }
            else
            {
                OpenAlContext = ContextHandle.Zero;
                System.Windows.Forms.MessageBox.Show("The sound device could not be opened.", "openBVE", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Hand);
            }
            // outer radius
            switch (Interface.CurrentOptions.SoundRange)
            {
            case Interface.SoundRange.Low:
                OuterRadiusFactorMinimum = 2.0;
                OuterRadiusFactorMaximum = 8.0;
                break;

            case Interface.SoundRange.Medium:
                OuterRadiusFactorMinimum = 4.0;
                OuterRadiusFactorMaximum = 16.0;
                break;

            case Interface.SoundRange.High:
                OuterRadiusFactorMinimum = 8.0;
                OuterRadiusFactorMaximum = 32.0;
                break;
            }
            OuterRadiusFactor = OuterRadiusFactorMaximum;
        }
コード例 #30
0
        private void _audioCreateContext()
        {
            unsafe
            {
                _openALContext = Alc.CreateContext(_openALDevice, (int *)0);
            }
            Alc.MakeContextCurrent(_openALContext);
            _checkAlcError(_openALDevice);
            _checkAlError();

            // Load up AL context extensions.
            foreach (var extension in AL.Get(ALGetString.Extensions).Split(' '))
            {
                _alContextExtensions.Add(extension);
            }

            Logger.DebugS("oal", "OpenAL Vendor: {0}", AL.Get(ALGetString.Vendor));
            Logger.DebugS("oal", "OpenAL Renderer: {0}", AL.Get(ALGetString.Renderer));
            Logger.DebugS("oal", "OpenAL Version: {0}", AL.Get(ALGetString.Version));
        }