Пример #1
0
        public Sound(IntPtr mainWindowHandle, Config config, Func <double> getCoreVsyncRateCallback)
        {
            BlockAlign = BytesPerSample * ChannelCount;

            _getCoreVsyncRateCallback = getCoreVsyncRateCallback;
            _outputProvider           = new SoundOutputProvider(_getCoreVsyncRateCallback);
            Config = config;

            if (OSTailoredCode.IsUnixHost)
            {
                // if DirectSound or XAudio is chosen, use OpenAL, otherwise comply with the user's choice
                _outputDevice = config.SoundOutputMethod == ESoundOutputMethod.Dummy
                                        ? (ISoundOutput) new DummySoundOutput(this)
                                        : new OpenALSoundOutput(this, config.SoundDevice);
            }
            else
            {
                _outputDevice = config.SoundOutputMethod switch
                {
                    ESoundOutputMethod.DirectSound => new DirectSoundSoundOutput(this, mainWindowHandle, config.SoundDevice),
                    ESoundOutputMethod.XAudio2 => new XAudio2SoundOutput(this, config.SoundDevice),
                    ESoundOutputMethod.OpenAL => new OpenALSoundOutput(this, config.SoundDevice),
                    _ => new DummySoundOutput(this)
                };
            }
        }
Пример #2
0
        public void StartSound()
        {
            if (_disposed)
            {
                return;
            }
            if (!Global.Config.SoundEnabled)
            {
                return;
            }
            if (IsStarted)
            {
                return;
            }

            _soundOutput.StartSound();

            _outputProvider = new SoundOutputProvider();
            _outputProvider.MaxSamplesDeficit = _soundOutput.MaxSamplesDeficit;
            _outputProvider.BaseSoundProvider = _syncSoundProvider;

            Global.SoundMaxBufferDeficitMs = (int)Math.Ceiling(SamplesToMilliseconds(_soundOutput.MaxSamplesDeficit));

            IsStarted = true;

            //ApplyVolumeSettings();

            //LogUnderruns = true;
            //_outputProvider.LogDebug = true;
        }
Пример #3
0
 public SyncToAsyncProvider(Func <double> getCoreVsyncRateCallback, ISoundProvider baseProvider)
 {
     _outputProvider = new SoundOutputProvider(getCoreVsyncRateCallback, standaloneMode: true)
     {
         BaseSoundProvider = baseProvider
     };
 }
Пример #4
0
        public void StopSound()
        {
            if (!IsStarted)
            {
                return;
            }

            _soundOutput.StopSound();

            _outputProvider = null;

            Global.SoundMaxBufferDeficitMs = 0;

            IsStarted = false;
        }