Exemplo n.º 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();
        }
Exemplo n.º 2
0
        protected virtual void MixData()
        {
            string ms = " channels " + module.numberOfChannels + " ";

            for (int pos = 0; pos < ModuleConst.MIX_LEN; pos++)
            {
                float mixValueR = 0;
                float mixValueL = 0;
                float mixValue  = 0;
                for (int ch = 0; ch < module.numberOfChannels; ch++)
                {
                    ModuleMixerChannel mc = mixChannels[ch];
                    //if (ch != 1) mc.muted = true;
                    if (!mc.muted)
                    {
                        mixValue += GetSampleValue(mc);

                        //if (ModuleConst.MIX_CHANNELS == ModuleConst.STEREO) {
                        //    mixValueL += (((ch & 0x03) == 0) || ((ch & 0x03) == 3)) ? mixValue * 0.75f : mixValue * 0.25f;
                        //    mixValueR += (((ch & 0x03) == 1) || ((ch & 0x03) == 2)) ? mixValue * 0.75f : mixValue * 0.25f;
                        //}
                    }
                    mc.instrumentPosition += mc.periodInc;
                }
                if (ModuleConst.MIX_CHANNELS != ModuleConst.STEREO)
                {
                    mixValue /= module.numberOfChannels;
                }
                //else {
                //    mixValueL /= (module.numberOfChannels << 1);
                //    mixValueR /= (module.numberOfChannels << 1);
                //}

                if (ModuleConst.MIX_CHANNELS != ModuleConst.STEREO)
                {
                    waveStream.Write((short)mixValue);
                }
                //else {
                //    waveStream.Write((short)mixValueL);
                //    waveStream.Write((short)mixValueR);
                //}

                mixerPosition++;
                if (mixerPosition >= samplesPerTick)
                {
                    SetBPM();
                    UpdateBPM();
                }
            }
        }