示例#1
0
            protected override bool OnGetData(out short[] samples)
            {
                if (reserved != current)
                {
                    synthesizer.NoteOffAll(true);
                    synthesizer.ResetSynthControls();
                    current = reserved;
                }

                var a = 32768 * (6.0F * config.audio_musicvolume / parent.MaxVolume);

                //
                // Due to a design error, this implementation makes the music
                // playback speed a bit slower.
                // The slowdown is around 1 sec per minute, so I hope no one
                // will notice.
                //

                var t = 0;

                for (var i = 0; i < stepCount; i++)
                {
                    current.FillBuffer(synthesizer);
                    var buffer = synthesizer.sampleBuffer;
                    for (var j = 0; j < buffer.Length; j++)
                    {
                        var sample = (int)(a * buffer[j]);
                        if (sample < short.MinValue)
                        {
                            sample = short.MinValue;
                        }
                        else if (sample > short.MaxValue)
                        {
                            sample = short.MaxValue;
                        }
                        batch[t++] = (short)sample;
                    }
                }

                samples = batch;

                return(true);
            }