Beispiel #1
0
        unsafe protected override void OnDispose()
        {
            DirectSoundWorld.criticalSection.Enter();

            if (captureBuffer != null)
            {
                IDirectSoundCaptureBuffer.Release(captureBuffer);
                captureBuffer = null;
            }

            if (soundCapture != null)
            {
                IDirectSoundCapture8.Release(soundCapture);
                soundCapture = null;
            }

            DirectSoundWorld.criticalSection.Leave();

            base.OnDispose();
        }
Beispiel #2
0
        unsafe public DirectCaptureSound(SoundMode mode, int channels, int frequency, int bufferSize)
        {
            SoundMode newMode = mode | SoundMode.Loop | SoundMode.Software;

            int hr;

            if (DirectSoundWorld.Instance.recordDriverIndex == -1)
            {
                DirectSoundWorld.Warning("Recording failed. No active device.");
                return;
            }
            GUID deviceGuid = DirectSoundWorld.Instance.recordDriverGuids[
                DirectSoundWorld.Instance.recordDriverIndex];

            //soundCapture
            void */*IDirectSoundCapture8*/ tempSoundCapture;

            hr = DSound.DirectSoundCaptureCreate(&deviceGuid, out tempSoundCapture, null);
            if (Wrapper.FAILED(hr))
            {
                DirectSoundWorld.Warning("DirectSoundCaptureCreate", hr);
                return;
            }
            soundCapture = (IDirectSoundCapture8 *)tempSoundCapture;

            //waveFormat
            waveFormat = (WAVEFORMATEX *)NativeUtils.Alloc(NativeMemoryAllocationType.SoundAndVideo,
                                                           sizeof(WAVEFORMATEX));
            NativeUtils.ZeroMemory((IntPtr)waveFormat, sizeof(WAVEFORMATEX));
            waveFormat->wFormatTag      = DSound.WAVE_FORMAT_PCM;
            waveFormat->nChannels       = (ushort)channels;
            waveFormat->nSamplesPerSec  = (uint)frequency;
            waveFormat->wBitsPerSample  = 16;
            waveFormat->nBlockAlign     = (ushort)((waveFormat->nChannels * waveFormat->wBitsPerSample) / 8);
            waveFormat->nAvgBytesPerSec = waveFormat->nSamplesPerSec * waveFormat->nBlockAlign;

            //captureBuffer

            DSCBUFFERDESC bufferDesc = new DSCBUFFERDESC();

            //ZeroMemory( &bufferDesc, sizeof( DSCBUFFERDESC ) );
            bufferDesc.dwSize        = (uint)sizeof(DSCBUFFERDESC);
            bufferDesc.dwBufferBytes = (uint)bufferSize;
            bufferDesc.lpwfxFormat   = waveFormat;

            void */*IDirectSoundCaptureBuffer*/ tempCaptureBuffer;

            hr = IDirectSoundCapture8.CreateCaptureBuffer(soundCapture,
                                                          ref bufferDesc, out tempCaptureBuffer, null);
            if (Wrapper.FAILED(hr))
            {
                DirectSoundWorld.Warning("CreateCaptureBuffer", hr);
                IDirectSoundCapture8.Release(soundCapture);
                soundCapture = null;
                return;
            }
            captureBuffer = (IDirectSoundCaptureBuffer *)tempCaptureBuffer;

            //get bufferSize
            DSCBCAPS bufferCaps = new DSCBCAPS();

            //ZeroMemory( &bufferCaps, sizeof( DSCBCAPS ) );
            bufferCaps.dwSize = (uint)sizeof(DSCBCAPS);
            IDirectSoundCaptureBuffer.GetCaps(captureBuffer, ref bufferCaps);
            this.bufferSize = (int)bufferCaps.dwBufferBytes;

            Init(null, newMode, 100000.0f, channels, frequency);
        }