Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Sdl2Player"/> class.
        /// </summary>
        public Sdl2Player()
        {
            var inputDriver    = new Sdl2InputDriver();
            var graphicsDriver = new Sdl2GraphicsDriver();
            var soundDriver    = new PcmSoundDriver(new Sdl2SoundPcmDriver());

            this.interpreter = new AgiInterpreter(inputDriver, graphicsDriver, soundDriver);

            inputDriver.SetInterpreter(this.interpreter);
            soundDriver.SetInterpreter(this.interpreter);
        }
Esempio n. 2
0
    private int TonePcmCallback(ToneChannel ch, short[] buffer, int count)
    {
        int result = -1;
        int index  = 0;

        while (count > 0)
        {
            if (ch.NoteCount <= 0)
            {
                // Get new tone data
                Tone tone = new Tone();
                tone.FrequencyCount = 0;
                tone.Attenuation    = 0x0f;
                tone.Type           = GenerateTone;

                if (ch.Avail != 0 && this.interpreter.SoundManager.FillChannel(ch.AgiChannel, tone) == 0)
                {
                    ch.Attenuation = tone.Attenuation;
                    ch.FreqCount   = tone.FrequencyCount;
                    ch.GenType     = tone.Type;

                    // setup counters 'n stuff
                    // 44100 samples per sec.. tone changes 60 times per sec
                    ch.NoteCount = 44100 / 60;

                    result = 0;
                }
                else
                {
                    ch.GenType   = GenerateSilence;
                    ch.NoteCount = count;
                    ch.Avail     = 0;
                }
            }

            // Write nothing
            if (ch.FreqCount == 0 || ch.Attenuation == 0x0f)
            {
                ch.GenType = GenerateSilence;
            }

            // Find which is smaller, the buffer or the note count
            int fillSize = ch.NoteCount < count ? ch.NoteCount : count;

            switch (ch.GenType)
            {
            case GenerateTone:
                fillSize = PcmSoundDriver.SquareFill(ch, buffer, index, fillSize);
                break;

            case GeneratePeriod:
            case GenerateWhite:
                fillSize = PcmSoundDriver.NoiseFill(ch, buffer, index, fillSize);
                break;

            case GenerateSilence:
            default:
                fillSize = PcmSoundDriver.SilenceFill(buffer, index, fillSize);
                break;
            }

            ch.NoteCount -= fillSize;
            count        -= fillSize;
            index        += fillSize;
        }

        return(result);
    }