示例#1
0
        private bool CreateCaptureBuffer()
        {
            uint dsErr = DSERR.DS_OK;

            #region 创建默认音频流格式

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

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

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

            #endregion

            IntPtr pdscb;
            Guid   iid_dscb8;
            dsErr = this.dsc8.CreateCaptureBuffer(ref this.dsbd, 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
            {
                LibUtils.PrintLog("CreateCaptureBuffer失败, DSERROR = {0}", dsErr);
                return(false);
            }

            return(true);
        }
示例#2
0
        private bool CreateSecondaryBuffer()
        {
            uint dsErr = DSERR.DS_OK;

            #region 创建默认音频流格式

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

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

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

            #endregion

            IntPtr pdsb;
            dsErr = this.ds8.CreateSoundBuffer(ref this.dsbd, out pdsb, IntPtr.Zero);
            if (dsErr != DSERR.DS_OK)
            {
                LibUtils.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);
        }