コード例 #1
0
ファイル: DirectSoundOut.cs プロジェクト: zouhunter/SAEA
        private void InitializeDirectSound()
        {
            object lockObject = this.m_LockObject;

            lock (lockObject)
            {
                this.directSound = null;
                DirectSoundOut.DirectSoundCreate(ref this.device, out this.directSound, IntPtr.Zero);
                if (this.directSound != null)
                {
                    this.directSound.SetCooperativeLevel(DirectSoundOut.GetDesktopWindow(), DirectSoundOut.DirectSoundCooperativeLevel.DSSCL_PRIORITY);
                    DirectSoundOut.BufferDescription bufferDescription = new DirectSoundOut.BufferDescription();
                    bufferDescription.dwSize        = Marshal.SizeOf(bufferDescription);
                    bufferDescription.dwBufferBytes = 0u;
                    bufferDescription.dwFlags       = DirectSoundOut.DirectSoundBufferCaps.DSBCAPS_PRIMARYBUFFER;
                    bufferDescription.dwReserved    = 0;
                    bufferDescription.lpwfxFormat   = IntPtr.Zero;
                    bufferDescription.guidAlgo      = Guid.Empty;
                    object obj;
                    this.directSound.CreateSoundBuffer(bufferDescription, out obj, IntPtr.Zero);
                    this.primarySoundBuffer = (DirectSoundOut.IDirectSoundBuffer)obj;
                    this.primarySoundBuffer.Play(0u, 0u, DirectSoundOut.DirectSoundPlayFlags.DSBPLAY_LOOPING);
                    this.samplesFrameSize = this.MsToBytes(this.desiredLatency);
                    DirectSoundOut.BufferDescription bufferDescription2 = new DirectSoundOut.BufferDescription();
                    bufferDescription2.dwSize        = Marshal.SizeOf(bufferDescription2);
                    bufferDescription2.dwBufferBytes = (uint)(this.samplesFrameSize * 2);
                    bufferDescription2.dwFlags       = (DirectSoundOut.DirectSoundBufferCaps.DSBCAPS_CTRLVOLUME | DirectSoundOut.DirectSoundBufferCaps.DSBCAPS_CTRLPOSITIONNOTIFY | DirectSoundOut.DirectSoundBufferCaps.DSBCAPS_STICKYFOCUS | DirectSoundOut.DirectSoundBufferCaps.DSBCAPS_GLOBALFOCUS | DirectSoundOut.DirectSoundBufferCaps.DSBCAPS_GETCURRENTPOSITION2);
                    bufferDescription2.dwReserved    = 0;
                    GCHandle gCHandle = GCHandle.Alloc(this.waveFormat, GCHandleType.Pinned);
                    bufferDescription2.lpwfxFormat = gCHandle.AddrOfPinnedObject();
                    bufferDescription2.guidAlgo    = Guid.Empty;
                    this.directSound.CreateSoundBuffer(bufferDescription2, out obj, IntPtr.Zero);
                    this.secondaryBuffer = (DirectSoundOut.IDirectSoundBuffer)obj;
                    gCHandle.Free();
                    DirectSoundOut.BufferCaps bufferCaps = new DirectSoundOut.BufferCaps();
                    bufferCaps.dwSize = Marshal.SizeOf(bufferCaps);
                    this.secondaryBuffer.GetCaps(bufferCaps);
                    this.nextSamplesWriteIndex = 0;
                    this.samplesTotalSize      = bufferCaps.dwBufferBytes;
                    this.samples = new byte[this.samplesTotalSize];
                    DirectSoundOut.IDirectSoundNotify arg_26F_0 = (DirectSoundOut.IDirectSoundNotify)obj;
                    this.frameEventWaitHandle1 = new EventWaitHandle(false, EventResetMode.AutoReset);
                    this.frameEventWaitHandle2 = new EventWaitHandle(false, EventResetMode.AutoReset);
                    this.endEventWaitHandle    = new EventWaitHandle(false, EventResetMode.AutoReset);
                    DirectSoundOut.DirectSoundBufferPositionNotify[] array = new DirectSoundOut.DirectSoundBufferPositionNotify[3];
                    array[0]              = default(DirectSoundOut.DirectSoundBufferPositionNotify);
                    array[0].dwOffset     = 0u;
                    array[0].hEventNotify = this.frameEventWaitHandle1.SafeWaitHandle.DangerousGetHandle();
                    array[1]              = default(DirectSoundOut.DirectSoundBufferPositionNotify);
                    array[1].dwOffset     = (uint)this.samplesFrameSize;
                    array[1].hEventNotify = this.frameEventWaitHandle2.SafeWaitHandle.DangerousGetHandle();
                    array[2]              = default(DirectSoundOut.DirectSoundBufferPositionNotify);
                    array[2].dwOffset     = 4294967295u;
                    array[2].hEventNotify = this.endEventWaitHandle.SafeWaitHandle.DangerousGetHandle();
                    arg_26F_0.SetNotificationPositions(3u, array);
                }
            }
        }
コード例 #2
0
ファイル: DirectSoundOut.cs プロジェクト: zouhunter/SAEA
 private static extern void DirectSoundCreate(ref Guid GUID, [MarshalAs(UnmanagedType.Interface)] out DirectSoundOut.IDirectSound directSound, IntPtr pUnkOuter);