private void timer_Tick(object sender, System.EventArgs e)
        {
            FMOD.RESULT result;

            if (recording)
            {
                uint recordpos = 0;

                result = system.getRecordPosition(selected, ref recordpos);
                ERRCHECK(result);

                if (recordpos != lastrecordpos)
                {
                    IntPtr ptr1 = IntPtr.Zero, ptr2 = IntPtr.Zero;
                    int    blocklength;
                    uint   len1 = 0, len2 = 0;

                    blocklength = (int)recordpos - (int)lastrecordpos;
                    if (blocklength < 0)
                    {
                        blocklength += (int)soundlength;
                    }

                    /*
                     *  Lock the sound to get access to the raw data.
                     */
                    sound.@lock(lastrecordpos * 4, (uint)blocklength * 4, ref ptr1, ref ptr2, ref len1, ref len2); /* *4 = stereo 16bit.  1 sample = 4 bytes. */

                    /*
                     *  Write it to disk.
                     */
                    if (ptr1 != IntPtr.Zero && len1 > 0)
                    {
                        byte[] buf = new byte[len1];

                        Marshal.Copy(ptr1, buf, 0, (int)len1);

                        datalength += (int)len1;

                        fs.Write(buf, 0, (int)len1);
                    }
                    if (ptr2 != IntPtr.Zero && len2 > 0)
                    {
                        byte[] buf = new byte[len2];

                        Marshal.Copy(ptr2, buf, 0, (int)len2);

                        datalength += (int)len2;

                        fs.Write(buf, 0, (int)len2);
                    }

                    /*
                     *  Unlock the sound to allow FMOD to use it again.
                     */
                    sound.unlock(ptr1, ptr2, len1, len2);
                }

                lastrecordpos = recordpos;

                statusBar.Text = "Record buffer pos = " + recordpos + " Record time = " + datalength / 44100 / 4 / 60 + ":" + (datalength / 44100 / 4) % 60;
            }

            if (system != null)
            {
                system.update();
            }
        }