NScumm.Core.Audio.Mixer.Read C# (CSharp) Method

Read() public method

public Read ( short samples, int count ) : int
samples short
count int
return int
        public override int Read(short[] samples, int count)
        {
            Debug.Assert(samples != null);

            lock (_gate)
            {
                // we store stereo, 16-bit samples
                Debug.Assert(count % 2 == 0);

                // Since the mixer callback has been called, the mixer must be ready...
                IsReady = true;

                // mix all channels
                int res = 0, tmp;
                for (var i = 0; i != NumChannels; i++)
                    if (_channels[i] != null)
                    {
                        if (_channels[i].IsFinished)
                        {
                            _channels[i] = null;
                        }
                        else if (!_channels[i].IsPaused)
                        {
                            tmp = _channels[i].Mix(samples, count);

                            if (tmp > res)
                                res = tmp;
                        }
                    }

                return res * 2;
            }
        }

Usage Example

Ejemplo n.º 1
0
        public SkyEngine(GameSettings settings, IGraphicsManager gfxManager, IInputManager inputManager, IAudioOutput output, ISaveFileManager saveFileManager, bool debugMode = false)
        {
            _system = new SkySystem(gfxManager, inputManager, saveFileManager);

            _mixer = new Mixer(44100);
            // HACK:
            _mixer.Read(new byte[0], 0);
            output.SetSampleProvider(_mixer);

            var directory = ServiceLocator.FileStorage.GetDirectoryName(settings.Game.Path);
            _skyDisk = new Disk(directory);
            _skySound = new Sound(_mixer, _skyDisk, Mixer.MaxChannelVolume);

            SystemVars.Instance.GameVersion = _skyDisk.DetermineGameVersion();

            // TODO: music
            var dev = MidiDriver.DetectDevice(MusicDriverTypes.AdLib | MusicDriverTypes.Midi /*| MDT_PREFER_MT32*/, settings.AudioDevice);
            if (MidiDriver.GetMusicType(dev) == MusicType.AdLib)
            {
                SystemVars.Instance.SystemFlags |= SystemFlags.Sblaster;
                _skyMusic = new AdLibMusic(_mixer, _skyDisk);
            }
            else
            {
                SystemVars.Instance.SystemFlags |= SystemFlags.Roland;
                if ((MidiDriver.GetMusicType(dev) == MusicType.MT32)/* || ConfMan.getBool("native_mt32")*/)
                    _skyMusic = new Mt32Music((MidiDriver)MidiDriver.CreateMidi(_mixer, dev), _mixer, _skyDisk);
                else
                    _skyMusic = new GmMusic((MidiDriver)MidiDriver.CreateMidi(_mixer, dev), _mixer, _skyDisk);
            }

            if (IsCDVersion)
            {
                // TODO: configuration
                //if (ConfMan.hasKey("nosubtitles"))
                //{
                //    warning("Configuration key 'nosubtitles' is deprecated. Use 'subtitles' instead");
                //    if (!ConfMan.getBool("nosubtitles"))
                //        _systemVars.systemFlags |= SF_ALLOW_TEXT;
                //}

                //if (ConfMan.getBool("subtitles"))
                //    _systemVars.systemFlags |= SF_ALLOW_TEXT;

                //if (!ConfMan.getBool("speech_mute"))
                //    _systemVars.systemFlags |= SF_ALLOW_SPEECH;

            }
            else
                SystemVars.Instance.SystemFlags |= SystemFlags.AllowText;

            SystemVars.Instance.SystemFlags |= SystemFlags.PlayVocs;
            SystemVars.Instance.GameSpeed = 80;

            _skyCompact = new SkyCompact();
            _skyText = new Text(_skyDisk, _skyCompact);
            _skyMouse = new Mouse(_system, _skyDisk, _skyCompact);
            _skyScreen = new Screen(_system, _skyDisk, _skyCompact);

            InitVirgin();
            InitItemList();
            LoadFixedItems();
            _skyLogic = new Logic(_skyCompact, _skyScreen, _skyDisk, _skyText, _skyMusic, _skyMouse, _skySound);
            _skyMouse.Logic = _skyLogic;
            _skyScreen.Logic = _skyLogic;
            _skySound.Logic = _skyLogic;
            _skyText.Logic = _skyLogic;

            _skyControl = new Control(_skyScreen, _skyDisk, _skyMouse, _skyText, _skyMusic, _skyLogic, _skySound, _skyCompact, _system);
            _skyLogic.Control = _skyControl;

            // TODO: language

            // TODO: Setup mixer
            //SyncSoundSettings();

            // TODO: debugger
            //_debugger = new Debugger(_skyLogic, _skyMouse, _skyScreen, _skyCompact);
        }
All Usage Examples Of NScumm.Core.Audio.Mixer::Read