示例#1
0
        public void Process(byte[] buffer, int num)
        {
            for (int pos = 0, td; pos < num; pos += td, bytesLeft -= td)
            {
                while (bytesLeft == 0)
                {
                    if (miv != null)
                    {
                        Dispatch(miv);
                    }

                    if (mr.End)
                    {
                        End       = true;
                        bytesLeft = sampleRate * bytesPerSample;
                    }
                    else
                    {
                        miv       = mr.ReadEvent();
                        bytesLeft = (miv.delta * sampleRate / cmfFile.ticksPerSecond) * bytesPerSample;
                    }
                }

                td = Math.Min(num - pos, bytesLeft);
                adlib.GetSamples(buffer, pos, td);

                time += (double)(td / bytesPerSample) / sampleRate;
            }
        }
示例#2
0
        private void init()
        {
            // read the midi data to determine the duration of the whole song:
            int totalTicks = 0;
            var mr         = new MidiReader(new MemoryStream(cmf.mididata));

            while (!mr.End)
            {
                totalTicks += mr.ReadEvent().delta;
            }

            SecTotal = (double)totalTicks / cmf.ticksPerSecond;

            destination.Open(destination.Info.defaultPeriod, 2, 44100, FormatType.Int16);

            pc = new PlayerCore(destination.SampleRate, cmf);

            thread = new Thread(AudioThread);
            thread.Start();
        }