эту ошибку вроде можно проигнорировать.
1я кнопка начинает получать звук, вторая- стоп и воспроизвести этот захваченный звук. Но ничего не воспроизводится.
может кто поправить меня в этом:
-
- Dim WFmt As New Microsoft.DirectX.DirectSound.WaveFormat
- Dim Capt As Microsoft.DirectX.DirectSound.Capture
- Dim CaptBuf As Microsoft.DirectX.DirectSound.CaptureBuffer
- Dim desc As New Microsoft.DirectX.DirectSound.CaptureBufferDescription
- Dim cdc As New Microsoft.DirectX.DirectSound.CaptureDevicesCollection
- Dim dGuid As System.Guid
- Dim descPlay As New Microsoft.DirectX.DirectSound.BufferDescription
- Dim strm As New System.IO.MemoryStream
-
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- Dim channels As Short
- Dim bitsPerSample As Short
- Dim samplesPerSecond As Integer
- channels = 2
- bitsPerSample = 16
- samplesPerSecond = 22050
-
- WFmt.BlockAlign = channels * (bitsPerSample / 8)
- WFmt.AverageBytesPerSecond = WFmt.BlockAlign * samplesPerSecond
- WFmt.BitsPerSample = bitsPerSample
- WFmt.Channels = channels
- WFmt.FormatTag = Microsoft.DirectX.DirectSound.WaveFormatTag.Pcm
- WFmt.SamplesPerSecond = samplesPerSecond
-
- desc.Format = WFmt
- desc.BufferBytes = 2 * (WFmt.AverageBytesPerSecond / 5)
-
- descPlay.Format = WFmt
- descPlay.BufferBytes = 2 * (WFmt.AverageBytesPerSecond / 5)
- descPlay.ControlPositionNotify = True
- descPlay.ControlFrequency = True
- descPlay.ControlPan = True
- descPlay.ControlVolume = True
-
- dGuid = cdc.Item(1).DriverGuid
- Capt = New Microsoft.DirectX.DirectSound.Capture(dGuid)
- CaptBuf = New Microsoft.DirectX.DirectSound.CaptureBuffer(desc, Capt)
- End Sub
-
- Private Sub rec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rec.Click
- Me.Text = "recording"
-
- CaptBuf.Start(True)
- End Sub
-
- Private Sub stopRec_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles stopRec.Click
- Me.Text = "Form1"
-
- Dim y, g As Integer
- CaptBuf.Stop()
- CaptBuf.GetCurrentPosition(g, y)
- CaptBuf.Read(0, strm, y, Microsoft.DirectX.DirectSound.LockFlag.None)
-
- Dim devCol As New Microsoft.DirectX.DirectSound.DevicesCollection
- Dim dev As New Microsoft.DirectX.DirectSound.Device(devCol.Item(1).DriverGuid)
- Dim bufPlay As New Microsoft.DirectX.DirectSound.Buffer(descPlay, dev)
- dev.SetCooperativeLevel(Me, Microsoft.DirectX.DirectSound.CooperativeLevel.Normal)
- bufPlay.Write(0, strm, strm.Length, Microsoft.DirectX.DirectSound.LockFlag.None)
- bufPlay.Play(0, Microsoft.DirectX.DirectSound.BufferPlayFlags.Looping)
- End Sub
Ответить
|