Exemple #1
0
        public override bool SetNumVoices()
        {
            int t;

            if ((m_VcSoftChannel = ModDriver.SoftChn) == 0)
            {
                return(true);
            }

            if (m_VoiceInfos != null)
            {
                m_VoiceInfos = null;
            }

            m_VoiceInfos = new VirtualDriver1VoiceInfo[m_VcSoftChannel];

            for (t = 0; t < m_VcSoftChannel; t++)
            {
                m_VoiceInfos[t] = new VirtualDriver1VoiceInfo();

                m_VoiceInfos[t].Frequency = 10000;
                m_VoiceInfos[t].Panning   = (t & 1) == 1 ? SharpMikCommon.PAN_LEFT : SharpMikCommon.PAN_RIGHT;
            }

            return(false);
        }
Exemple #2
0
        uint VC_WriteSamples(sbyte[] buf, uint todo)
        {
            int left, portion = 0, count;
            int t, pan, vol;

            uint bufferPlace = 0;
            uint bufPlace    = 0;

            uint total = todo;

            if (todo > buf.Length)
            {
                throw new Exception("Asked for more then the dest buffer.");
            }

            while (todo != 0)
            {
                if (m_TickLeft == 0)
                {
                    if ((m_VcMode & SharpMikCommon.DMODE_SOFT_MUSIC) == SharpMikCommon.DMODE_SOFT_MUSIC)
                    {
                        ModPlayer.Player_HandleTick();
                    }

                    m_TickLeft = (ModDriver.MixFreq * 125) / (ModDriver.Bpm * 50);
                }

                left = (int)Math.Min(m_TickLeft, todo);

                bufferPlace = bufPlace;
                m_TickLeft -= left;
                todo       -= (uint)left;
                bufPlace   += samples2bytes((uint)left);

                while (left != 0)
                {
                    portion = (int)Math.Min(left, m_SamplesThatFit);
                    count   = m_IsStereo ? (portion << 1) : portion;

                    Array.Clear(m_VcTickBuf, 0, TICKLSIZE);

                    for (t = 0; t < m_VcSoftChannel; t++)
                    {
                        m_CurrentVoiceInfo = m_VoiceInfos[t];

                        if (m_CurrentVoiceInfo.Kick != 0)
                        {
                            m_CurrentVoiceInfo.CurrentSampleIndex = ((long)m_CurrentVoiceInfo.Start) << FRACBITS;
                            m_CurrentVoiceInfo.Kick   = 0;
                            m_CurrentVoiceInfo.Active = 1;
                        }

                        if (m_CurrentVoiceInfo.Frequency == 0)
                        {
                            m_CurrentVoiceInfo.Active = 0;
                        }

                        if (m_CurrentVoiceInfo.Active != 0)
                        {
                            m_CurrentVoiceInfo.CurrentIncrement = ((long)(m_CurrentVoiceInfo.Frequency << FRACBITS)) / ModDriver.MixFreq;

                            if ((m_CurrentVoiceInfo.Flags & SharpMikCommon.SF_REVERSE) != 0)
                            {
                                m_CurrentVoiceInfo.CurrentIncrement = -m_CurrentVoiceInfo.CurrentIncrement;
                            }

                            vol = m_CurrentVoiceInfo.Volume;
                            pan = m_CurrentVoiceInfo.Panning;

                            m_CurrentVoiceInfo.LeftVolumeOld  = m_CurrentVoiceInfo.LeftVolumeFactor;
                            m_CurrentVoiceInfo.RightVolumeOld = m_CurrentVoiceInfo.RightVolumeFactor;

                            if (m_IsStereo)
                            {
                                if (pan != SharpMikCommon.PAN_SURROUND)
                                {
                                    m_CurrentVoiceInfo.LeftVolumeFactor  = (vol * (SharpMikCommon.PAN_RIGHT - pan)) >> 8;
                                    m_CurrentVoiceInfo.RightVolumeFactor = (vol * pan) >> 8;
                                }
                                else
                                {
                                    m_CurrentVoiceInfo.LeftVolumeFactor = m_CurrentVoiceInfo.RightVolumeFactor = vol / 2;
                                }
                            }
                            else
                            {
                                m_CurrentVoiceInfo.LeftVolumeFactor = vol;
                            }

                            m_IdxSize = (m_CurrentVoiceInfo.Size != 0) ? ((long)m_CurrentVoiceInfo.Size << FRACBITS) - 1 : 0;
                            m_IdxlEnd = (m_CurrentVoiceInfo.RepeatEndPosition != 0) ? ((long)m_CurrentVoiceInfo.RepeatEndPosition << FRACBITS) - 1 : 0;

                            m_IdxlPos = (long)m_CurrentVoiceInfo.RepeatStartPosition << FRACBITS;

                            if (s_TestModeOn && t == s_TestChannel)
                            {
                                Console.Write("here");
                            }

                            AddChannel(m_VcTickBuf, portion);

                            if (s_TestModeOn)
                            {
                                Debug.WriteLine("{0}\t{1}", t, m_VcTickBuf[s_TestPlace]);
                            }
                        }
                    }

                    if (ModDriver.Reverb != 0)
                    {
                        if (m_IsStereo)
                        {
                            MixReverb_Stereo(portion);
                        }
                        else
                        {
                            MixReverb_Mono(portion);
                        }
                    }

                    if ((m_VcMode & SharpMikCommon.DMODE_16BITS) == SharpMikCommon.DMODE_16BITS)
                    {
                        Mix32To16(buf, m_VcTickBuf, count, (int)bufferPlace);
                    }
                    else
                    {
                        Mix32To8(buf, m_VcTickBuf, count, (int)bufferPlace);
                    }

                    bufferPlace += samples2bytes((uint)portion);

                    if (bufferPlace > buf.Length)
                    {
                        return(todo);
                    }
                    else
                    {
                        left -= portion;
                    }
                }
            }

            return(todo);
        }