Capture Voice using DirectSound
-
Hi, I a trying to capture the voice using direct sound, but it is not working,here is my code can anyone help me, I will be very thankful to him. private void CaptureThread() { MemoryStream inputStream = new MemoryStream(intervalSize); while (button1.Text == "Stop") { bool val=bufferNotifyEvent.WaitOne(); int currentPos; int readPos; captureBuffer.GetCurrentPosition(out currentPos, out readPos); inputStream.Position = 0; captureBuffer.Read(0, inputStream, intervalSize, LockFlag.None); outputBuffer.Write(0, inputStream, intervalSize , LockFlag.None); outputBuffer.Play(0,BufferPlayFlags.Looping); } Stop(); } the above code is the main thread that run to capture the voice, and some initializations are below private void Form1_Load(object sender, System.EventArgs e) { WaveFormat waveFormat; CaptureBufferDescription capBufDesc; BufferPositionNotify[] notifyPositions; bitsPerSample = 8; // 8 bits per sample const int samplesPerSecond = 11025; // 11 KHz const double interval = 1/45f; // Seconds intervalSize = (int) (interval * samplesPerSecond * bitsPerSample / 8); int samplesPerInterval = intervalSize * 8 / bitsPerSample; int bufferSize = intervalSize * 2; captureDevice = new Capture(); waveFormat = new WaveFormat(); waveFormat.BitsPerSample = bitsPerSample; waveFormat.SamplesPerSecond = samplesPerSecond; waveFormat.Channels = 1; waveFormat.AverageBytesPerSecond = bitsPerSample * samplesPerSecond / 8; waveFormat.BlockAlign = (short)(bitsPerSample / 8); waveFormat.FormatTag = WaveFormatTag.Pcm; capBufDesc = new CaptureBufferDescription(); capBufDesc.Format = waveFormat; capBufDesc.BufferBytes = bufferSize; captureBuffer = new CaptureBuffer(capBufDesc, captureDevice); bufferNotify = new Notify(captureBuffer); bufferNotifyEvent = new AutoResetEvent(false); notifyPositions = new BufferPositionNotify[2]; notifyPositions[0] = new BufferPositionNotify(); notifyPositions[0].EventNotifyHandle = bufferNotifyEvent.Handle; notifyPositions[0].Offset = intervalSize - (bitsPerSample / 8); notifyPositions[1] = new BufferPositionNotify(); notifyPositions[1].EventNotifyHandle = bufferNotifyEvent.Handle; notifyPositions[1].Offset = bufferSize - (bitsPerSample / 8); bufferNotify.SetNotificationPositions(notifyPositions); BufferDescription outputBufferDescription; outputDevice = new Device(); outputDevice.SetCooperativeLevel(this, CooperativeLevel.Normal); outputBufferDescription = new BufferDescription(waveFormat); outpu