コード例 #1
0
ファイル: AudioEngine.cs プロジェクト: SpectrumLib/Spectrum
        public static void Initialize()
        {
            // Populate the device lists
            PlaybackDevice.PopulateDeviceList();
            if (PlaybackDevice.Devices.Count == 0)
            {
                throw new AudioException("There are no audio playback devices available");
            }
            LDEBUG("Available audio playback devices:");
            foreach (var dev in PlaybackDevice.Devices)
            {
                LDEBUG($"   {dev.Identifier}");
            }

            // Open the default playback device
            Device = ALC10.alcOpenDevice(PlaybackDevice.Devices[0].Identifier);
            ALUtils.CheckALCError();
            if (Device == IntPtr.Zero)
            {
                throw new AudioException("Unable to open default audio playback device");
            }

            // Create the al context and set it as active
            Context = ALC10.alcCreateContext(Device, new int[2] {
                0, 0
            });                                                                        // Two 0s tell OpenAL no special attribs
            ALUtils.CheckALCError();
            if (Context == IntPtr.Zero)
            {
                throw new AudioException("Unable to create audio context");
            }
            ALC10.alcMakeContextCurrent(Context);
            ALUtils.CheckALCError();

            // Generate audio sources
            AL10.alGenSources(MAX_SOURCE_COUNT, s_allSources);
            ALUtils.CheckALError("unable to generate audio sources");
            foreach (var src in s_allSources)
            {
                s_availableSources.Push(src);
            }

            // Report
            LINFO("Started OpenAL audio engine.");
            LINFO($"    Device: {PlaybackDevice.Devices[0].Identifier}.");
        }
コード例 #2
0
ファイル: AudioEngine.cs プロジェクト: SpectrumLib/Spectrum
        public static void Shutdown()
        {
            // Destroy the sources
            AL10.alDeleteSources(MAX_SOURCE_COUNT, s_allSources);
            ALUtils.CheckALError("unable to free audio sources");
            s_availableSources.Clear();
            s_usedSources.Clear();

            // Destroy the context, and then close the device
            ALC10.alcMakeContextCurrent(IntPtr.Zero);
            ALUtils.CheckALCError();
            ALC10.alcDestroyContext(Context);
            ALUtils.CheckALCError();
            Context = IntPtr.Zero;
            ALC10.alcCloseDevice(Device);
            ALUtils.CheckALCError();
            Device = IntPtr.Zero;

            IsShutdown = true;

            // Report
            LINFO("Shutdown OpenAL audio engine.");
        }