Exemple #1
0
        public override short SampleLoad(SAMPLOAD sload, int type)
        {
            SAMPLE s = sload.sample;

            int  handle;
            uint t, length, loopstart, loopend;

            if (type == (int)SharpMikCommon.MDDecodeTypes.MD_HARDWARE)
            {
                return(0);
            }

            /* Find empty slot to put sample address in */
            for (handle = 0; handle < SharpMikCommon.MAXSAMPLEHANDLES; handle++)
            {
                if (m_Samples[handle] == null)
                {
                    break;
                }
            }

            if (handle == SharpMikCommon.MAXSAMPLEHANDLES)
            {
                // Throw an exception so it reaches all the way up to the loader to show the load failed.
                throw new Exception("Out of handles");
            }

            /* Reality check for loop settings */
            if (s.loopend > s.length)
            {
                s.loopend = s.length;
            }

            if (s.loopstart >= s.loopend)
            {
                int flags = s.flags;
                flags &= ~SharpMikCommon.SF_LOOP;

                s.flags = (ushort)flags;
            }

            length    = s.length;
            loopstart = s.loopstart;
            loopend   = s.loopend;

            SampleLoader.SL_SampleSigned(sload);
            SampleLoader.SL_Sample8to16(sload);

            uint len = ((length + 20) << 1);

            m_Samples[handle] = new short[len];

            /* read sample into buffer */
            if (SampleLoader.SL_Load(m_Samples[handle], sload, length))
            {
                return(-1);
            }

            /* Unclick sample */
            if ((s.flags & SharpMikCommon.SF_LOOP) == SharpMikCommon.SF_LOOP)
            {
                if ((s.flags & SharpMikCommon.SF_BIDI) == SharpMikCommon.SF_BIDI)
                {
                    for (t = 0; t < 16; t++)
                    {
                        m_Samples[handle][loopend + t] = m_Samples[handle][(loopend - t) - 1];
                    }
                }
                else
                {
                    for (t = 0; t < 16; t++)
                    {
                        m_Samples[handle][loopend + t] = m_Samples[handle][t + loopstart];
                    }
                }
            }
            else
            {
                for (t = 0; t < 16; t++)
                {
                    m_Samples[handle][t + length] = 0;
                }
            }

            return((short)handle);
        }
        public short SampleLoad(SAMPLOAD sload, int type)
        {
            SAMPLE s = sload.sample;

            int  handle;
            uint t, length, loopstart, loopend;

            if (type == (int)SharpMikCommon.MDDecodeTypes.MD_HARDWARE)
            {
                return(0);
            }

            /* Find empty slot to put sample address in */
            for (handle = 0; handle < m_Samples.Count; handle++)
            {
                if (m_Samples[handle] == null)
                {
                    break;
                }
            }


            if (handle == m_Samples.Count)
            {
                m_Samples.Add(null);
            }

            /* Reality check for loop settings */
            if (s.loopend > s.length)
            {
                s.loopend = s.length;
            }

            if (s.loopstart >= s.loopend)
            {
                int flags = s.flags;
                flags &= ~SharpMikCommon.SF_LOOP;

                s.flags = (ushort)flags;
            }

            length    = s.length;
            loopstart = s.loopstart;
            loopend   = s.loopend;

            SampleLoader.SL_SampleSigned(sload);
            SampleLoader.SL_Sample8to16(sload);

            uint len = ((length + 20) << 1);

            m_Samples[handle] = new short[len];

            /* read sample into buffer */
            if (SampleLoader.SL_Load(m_Samples[handle], sload, length))
            {
                return(-1);
            }

            /* Unclick sample */
            if ((s.flags & SharpMikCommon.SF_LOOP) == SharpMikCommon.SF_LOOP)
            {
                if ((s.flags & SharpMikCommon.SF_BIDI) == SharpMikCommon.SF_BIDI)
                {
                    for (t = 0; t < 16; t++)
                    {
                        m_Samples[handle][loopend + t] = m_Samples[handle][(loopend - t) - 1];
                    }
                }
                else
                {
                    for (t = 0; t < 16; t++)
                    {
                        m_Samples[handle][loopend + t] = m_Samples[handle][t + loopstart];
                    }
                }
            }
            else
            {
                for (t = 0; t < 16; t++)
                {
                    m_Samples[handle][t + length] = 0;
                }
            }

            return((short)handle);
        }