Ejemplo n.º 1
0
        private bool CreateCaptureBuffer(out uint dsErr)
        {
            dsErr = DSERR.DS_OK;

            #region 创建默认音频流格式

            this.wfx = new tWAVEFORMATEX()
            {
                nChannels       = DSLibConsts.Channels,
                nSamplesPerSec  = DSLibConsts.SamplesPerSec,
                wBitsPerSample  = DSLibConsts.BitsPerSample,
                nBlockAlign     = DSLibConsts.BlockAlign,
                nAvgBytesPerSec = DSLibConsts.Bps,
                cbSize          = 0,
                wFormatTag      = DSLibNatives.WAVE_FORMAT_PCM
            };

            this.pwfx_free = DSLibUtils.StructureToPtr(this.wfx);

            this.bufferDesc = new _DSCBUFFERDESC()
            {
                dwFlags       = 0,
                dwSize        = Marshal.SizeOf(typeof(_DSCBUFFERDESC)),
                dwReserved    = 0,
                dwFXCount     = 0,
                dwBufferBytes = DSLibConsts.BufferSize,
                lpwfxFormat   = this.pwfx_free,
                lpDSCFXDesc   = IntPtr.Zero
            };

            this.pBufferDesc_free = DSLibUtils.StructureToPtr(this.bufferDesc);

            #endregion

            IntPtr pdscb;
            Guid   iid_dscb8;
            dsErr = this.dsc8.CreateCaptureBuffer(this.pBufferDesc_free, out pdscb, IntPtr.Zero); //TestInvoke2(this.free_bufferDesc, out ppDSCBuff);
            if (dsErr == DSERR.DS_OK)
            {
                // 获取IDirectSoundCaptureBuffer8接口实例
                iid_dscb8 = new Guid(IID.IID_IDirectSoundCaptureBuffer8);
                Marshal.QueryInterface(pdscb, ref iid_dscb8, out this.pdscb8);
                Marshal.Release(pdscb);
                this.dscb8 = Marshal.GetObjectForIUnknown(this.pdscb8) as IDirectSoundCaptureBuffer8;
            }
            else
            {
                DSLibUtils.PrintLog("CreateCaptureBuffer失败, DSERROR = {0}", dsErr);
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        private bool CreateSecondaryBuffer(out uint dsErr)
        {
            dsErr = DSERR.DS_OK;

            #region 创建默认音频流格式

            this.wfx = new tWAVEFORMATEX()
            {
                nChannels       = DSLibConsts.Channels,
                nSamplesPerSec  = DSLibConsts.SamplesPerSec,
                wBitsPerSample  = DSLibConsts.BitsPerSample,
                nBlockAlign     = DSLibConsts.BlockAlign,
                nAvgBytesPerSec = DSLibConsts.Bps,
                cbSize          = 0,
                wFormatTag      = DSLibNatives.WAVE_FORMAT_PCM
            };

            this.pwfx_free = DSLibUtils.StructureToPtr(this.wfx);

            this.dsbd = new _DSBUFFERDESC()
            {
                dwSize          = Marshal.SizeOf(typeof(_DSBUFFERDESC)),
                dwFlags         = (int)DSBCAPS.DSBCAPS_CTRLPOSITIONNOTIFY | (int)DSBCAPS.DSBCAPS_GETCURRENTPOSITION2 | (int)DSBCAPS.DSBCAPS_GLOBALFOCUS,
                lpwfxFormat     = this.pwfx_free,
                guid3DAlgorithm = new _GUID(),
                dwBufferBytes   = DSLibConsts.BufferSize,
                dwReserved      = 0
            };

            #endregion

            IntPtr pdsb;
            dsErr = this.ds8.CreateSoundBuffer(ref this.dsbd, out pdsb, IntPtr.Zero);
            if (dsErr != DSERR.DS_OK)
            {
                DSLibUtils.PrintLog("CreateSoundBuffer失败, DSERR = {0}", dsErr);
                return(false);
            }

            Guid iid_dsb8 = new Guid(IID.IID_IDirectSoundBuffer8);
            Marshal.QueryInterface(pdsb, ref iid_dsb8, out this.pdsb8);
            Marshal.Release(pdsb);
            this.dsb8 = Marshal.GetObjectForIUnknown(this.pdsb8) as IDirectSoundBuffer8;

            return(true);
        }