internal int GetQueuedSampleCount()
        {
            if (State == MicrophoneState.Stopped || BufferReady == null)
            {
                return(0);
            }

            Span <int> queuedSampleCountBuffer = stackalloc int[1];

            ALC.GetInteger(_captureDevice, ALCGetInteger.CaptureSamples, 1, queuedSampleCountBuffer);
            CheckALCError("Failed to query capture samples.");

            return(queuedSampleCountBuffer[0]);
        }
Esempio n. 2
0
        private unsafe float InitSound(float elapsedSinceLastCall, float elapsedTimeSinceLastFlightLoop, int counter)
        {
            CheckError();

            var oldContext = ALC.GetCurrentContext();

            if (oldContext == default)
            {
                XPlane.Trace.WriteLine("[OpenAL Sample] I found no OpenAL, I will be the first to init.");
                _device = ALC.OpenDevice(null);
                if (_device == null)
                {
                    XPlane.Trace.WriteLine("[OpenAL Sample] Could not open the default OpenAL device.");
                    return(0);
                }

                _context = ALC.CreateContext(_device, new ALContextAttributes());
                if (_context == null)
                {
                    ALC.CloseDevice(_device);
                    _device = default;
                    XPlane.Trace.WriteLine("[OpenAL Sample] Could not open the default OpenAL device.");
                    return(0);
                }

                ALC.MakeContextCurrent(_context);
                XPlane.Trace.WriteLine("[OpenAL Sample] Created the Open AL context.");

                var hardware   = ALC.GetString(_device, AlcGetString.DeviceSpecifier);
                var extensions = ALC.GetString(_device, AlcGetString.Extensions);
                var major      = ALC.GetInteger(_device, AlcGetInteger.MajorVersion);
                var minor      = ALC.GetInteger(_device, AlcGetInteger.MinorVersion);
                XPlane.Trace.WriteLine($"[OpenAL Sample] OpenAL version   : {major}.{minor}");
                XPlane.Trace.WriteLine($"[OpenAL Sample] OpenAL hardware  : {hardware}");
                XPlane.Trace.WriteLine($"[OpenAL Sample] OpenAL extensions: {extensions}");
                CheckError();
            }
            else
            {
                XPlane.Trace.WriteLine($"[OpenAL Sample] I found someone else's context: {(ulong)oldContext.Handle:X8}");
            }

            var path = Path.Combine(Path.GetDirectoryName(PluginInfo.ThisPlugin.FilePath), "sound.wav");

            // Generate 1 source and load a buffer of audio.
            _soundSource = AL.GenSource();

            CheckError();

            _soundBuffer = WavHelper.LoadWav(path);
            XPlane.Trace.WriteLine($"[OpenAL Sample] Loaded {_soundBuffer} from {path}.");

            // Basic initialization code to play a sound: specify the buffer the source is playing, as well as some
            // sound parameters. This doesn't play the sound - it's just one-time initialization.
            AL.Source(_soundSource, ALSourcei.Buffer, _soundBuffer);
            AL.Source(_soundSource, ALSourcef.Pitch, 1f);
            AL.Source(_soundSource, ALSourcef.Gain, 1f);
            AL.Source(_soundSource, ALSourceb.Looping, false);
            AL.Source(_soundSource, ALSource3f.Position, 0f, 0f, 0f);
            AL.Source(_soundSource, ALSource3f.Velocity, 0f, 0f, 0f);
            CheckError();

            return(0);
        }