Beispiel #1
0
        public override void PlayInstrument(uint instrumentNumber = 0)
        {
            PlayBackWaveProvider waveStream = new PlayBackWaveProvider(ModuleConst.SOUNDFREQUENCY, ModuleConst.MIX_CHANNELS == ModuleConst.STEREO);

            XM_Sample sample = ((XM_Instrument)Instruments[(int)instrumentNumber - 1]).sample;

            string mes = "\n\n\nSample number : " + sample.orderNumber;

            float period    = 7680.0f - (48 + sample.relativeNoteNumber) * 64.0f;
            float frequency = (float)(8363 * Math.Pow(2, (4608.0f - period) * 0.001302083f));
            float periodInc = (period != 0) ? frequency * 2 / ModuleConst.SOUNDFREQUENCY : 1.0f;
            float pos       = 0;

            mes += " freq : " + period;
            DebugMes(mes);

            while (pos < sample.length * 4 - 1)
            {
                waveStream.Write((short)sample[(int)pos]);
                pos += periodInc;
            }

            WaveOutEvent waveOut = new WaveOutEvent();

            waveOut.Init(waveStream);
            waveOut.Play();
        }
Beispiel #2
0
        public virtual void PlayModule(uint startPosition = 0)
        {
            playing = false;
            InitModule(startPosition);

            waveOut?.Stop();
            MixingTask?.Wait();

            waveStream?.Dispose();
            waveOut?.Dispose();
            MixingTask?.Dispose();

            waveStream = new PlayBackWaveProvider(ModuleConst.SOUNDFREQUENCY /* module.numberOfChannels*/, ModuleConst.MIX_CHANNELS == ModuleConst.STEREO);
            playing    = true;

            MixingTask = Task.Factory.StartNew(() => {
                while ((!moduleEnd) && playing)
                {
                    MixData();
                    while (waveStream.QueueLength > ModuleConst.MIX_WAIT && playing)
                    {
                        Thread.Sleep(100);
                    }
                    //DebugMes("Play position - " + waveOut.GetPosition() + " queue length - " + waveStream.QueueLength);
                }
                while (waveStream.QueueLength > 0 && playing)
                {
                    Thread.Sleep(100);
                    //DebugMes("Play position - " + waveOut.GetPosition() + " queue length - " + waveStream.QueueLength);
                }
            });

            waveOut = new WaveOutEvent();
            waveOut.Init(waveStream);
            waveOut.Play();
        }