コード例 #1
0
        public unsafe void Write(int position, void *pBuffer, int length, DSBLOCK flags)
        {
            IntPtr pvAudioPtr1;
            int    dwAudioBytes1;
            IntPtr pvAudioPtr2;
            int    dwAudioBytes2;

            this.Lock(
                position,
                length,
                out pvAudioPtr1,
                out dwAudioBytes1,
                out pvAudioPtr2,
                out dwAudioBytes2,
                flags);
            try
            {
                int count1 = Math.Min(dwAudioBytes1, length);
                int count2 = length - count1;
                NativeHelper.CPBLK((void *)pvAudioPtr1, (void *)pBuffer, count1);
                if (count2 > 0)
                {
                    NativeHelper.CPBLK((void *)(pvAudioPtr1 + count1), (void *)((byte *)pBuffer + count1), count2);
                }
            }
            finally
            {
                this.Unlock(pvAudioPtr1, dwAudioBytes1, pvAudioPtr2, dwAudioBytes2);
            }
        }
コード例 #2
0
ファイル: DirectSound.cs プロジェクト: zxmak/ZXMAK2
 private bool OnBufferRequest(uint *pBuffer, int sampleCount)
 {
     uint[] source;
     if (!_playQueue.TryDequeue(out source))
     {
         var sample = _lastSample.HasValue ? _lastSample.Value : _zeroValue;
         // TODO: native optimization?
         for (var i = 0; i < sampleCount; i++)
         {
             pBuffer[i] = sample;
         }
         return(true);
     }
     try
     {
         fixed(uint *psrc = source)
         {
             NativeHelper.CPBLK(pBuffer, psrc, sampleCount * 4);
             //NativeMethods.CopyMemory(pBuffer, psrc, sampleCount * 4);
             _lastSample = pBuffer[sampleCount - 1];
         }
         return(true);
     }
     finally
     {
         _fillQueue.Enqueue(source);
         _frameEvent.Set();
     }
 }
コード例 #3
0
ファイル: DIJOYSTATE.cs プロジェクト: zxmak/ZXMAK2
        public unsafe byte[] GetButtons()
        {
            var offset = 8 * 4 + 4 * 4; // rgbButtons0 offset
            var length = sizeof(DIJOYSTATE) - offset;
            var button = new byte[length];

            fixed(void *pStruct = &this)
            fixed(void *pButton = button)
            {
                NativeHelper.CPBLK(pButton, (byte *)pStruct + offset, length);
            }
            return(button);
        }
コード例 #4
0
            public unsafe void SetStringAnsi(string value)
            {
                if (string.IsNullOrEmpty(value))
                {
                    fixed(void *pDst = &this)
                    {
                        *(byte *)pDst = (byte)0;
                    }

                    return;
                }
                var maxLength = Marshal.SizeOf(this);
                var length    = Math.Min(value.Length, maxLength);
                var pSrc      = Marshal.StringToHGlobalAnsi(value);

                fixed(void *pDst = &this)
                {
                    NativeHelper.CPBLK(pDst, (void *)pSrc, length);
                }

                Marshal.FreeHGlobal(pSrc);
            }