Sorry, the Forum is closed :(

Unfortunately, the forum is now closed.

Please read the following post for further details.

We apologize for the inconvenience.
The SharpDX team.
Welcome, Guest
Username: Password: Remember me
Welcome to the general discussions!
  • Page:
  • 1

TOPIC: DirectSound record & play in vb.net - help

DirectSound record & play in vb.net - help 2 years 2 weeks ago #368

Hello all

I'm trying to make a progam in vb.net to record from mic into a buffer, then play the buffer. The recording part I got right, but when I try to play an unknown error occurs (Module: [Unknown], ApiCode: [Unknown/Unknown], Message: Unknown). This a portion of the code I'm using:
  1. Private Sub recordingloop()
  2. Dim dirs As New SharpDX.DirectSound.DirectSound()
  3. Dim ptr As New IntPtr
  4. Dim a As New SharpDX.DirectSound.SoundBuffer(ptr)
  5. Dim frmat As New SharpDX.Multimedia.WaveFormat(25000, 16, 1)
  6. Dim buff(50000) As Byte
  7. Dim ds As SharpDX.DataStream
  8. ds = New SharpDX.DataStream(50000, 1, 1)
  9. Dim ds3 As SharpDX.DataStream
  10. ds3 = New SharpDX.DataStream(50000, 1, 1)
  11. Dim flags As New SharpDX.DirectSound.LockFlags
  12. Dim pflags As New SharpDX.DirectSound.PlayFlags
  13. Dim dsp As SharpDX.DirectSound.DirectSoundBase
  14.  
  15.  
  16.  
  17.  
  18. Dim buffdesc As New SharpDX.DirectSound.SoundBufferDescription()
  19. buffdesc.Format = frmat
  20. buffdesc.BufferBytes = 50000
  21. buffdesc.Flags = BufferFlags.None
  22.  
  23.  
  24.  
  25. Dim ttt As New SharpDX.DirectSound.PrimarySoundBuffer(dirs, buffdesc)
  26. dsp = New SharpDX.DirectSound.DirectSoundBase(ttt.NativePointer)
  27.  
  28.  
  29. Do While 1
  30.  
  31. If mappBuffer.CurrentCapturePosition >= 50000 Then
  32.  
  33. ds = mappBuffer.Lock(0, 50000, flags, ds3)
  34.  
  35.  
  36. ds.Read(buff, 0, 50000)
  37. mappBuffer.Unlock(ds, ds3)
  38.  
  39.  
  40. PictureBox1.CreateGraphics.Clear(Color.White)
  41.  
  42. For i = 0 To 1024 Step 4
  43. 'Just a simple confirmation that I'm recording ok ;)
  44. PictureBox1.CreateGraphics.DrawLine(Pens.Black, New Drawing.Point(i / 4, buff(i) / 2), New Drawing.Point(i / 4, buff(i) / 2 + 1))
  45. Application.DoEvents()
  46. Next
  47.  
  48.  
  49. Button1.Text = ptr
  50.  
  51. ttt.Write(buff, 0, 50000, 0, flags)
  52. ttt.CurrentPosition = 0
  53. ress = ttt.Play(0, 0) 'Error happens here
  54.  
  55.  
  56.  
  57. End If
  58. Loop
  59.  
  60.  
  61.  
  62. End Sub

Any Idea where I messed it up? thanks
The administrator has disabled public write access.

Re: DirectSound record & play in vb.net - help 2 years 2 weeks ago #370


  • Posts:426
  • artiom's Avatar
  • artiom
  • Moderator
  • OFFLINE
Try this:
1. Enable DirectX debugging (in Control Panel - need to have DirectX SDK installed, if I remember correctly).
2. In project properties, enable unmanaged code debugging.
3. Run the app with debugger attached and look into the Output window - it should show the detailed error
Based on this you can figure out what is going wrong there.
The administrator has disabled public write access.

Re: DirectSound record & play in vb.net - help 2 years 2 weeks ago #371

Hi

thanks for the tip. But I'm still having the same issue.
With the unmanaged debugger, I get this message
"An unhandled exception of type 'SharpDX.SharpDXException' occurred in SharpDX.dll

Additional information: HRESULT: [0x88780046], Module: [Unknown], ApiCode: [Unknown/Unknown], Message: Unknown
"
My guess is that i'm missing something in the primarysoundbuffer, some initialization maybe.
The administrator has disabled public write access.

Re: DirectSound record & play in vb.net - help 2 years 2 weeks ago #372


  • Posts:426
  • artiom's Avatar
  • artiom
  • Moderator
  • OFFLINE
"SharpDX.SharpDXException" usually occurs after the error in unmanaged code (DirectX runtime).
By enabling DirectX debugging you should see an message before this one (with SharpDXException).
The administrator has disabled public write access.

Re: DirectSound record & play in vb.net - help 2 years 2 weeks ago #374


  • Posts:843 Thank you received: 1
  • xoofx's Avatar
  • xoofx
  • Administrator
  • OFFLINE
You should tell us where does actually the error occurs (which line?)

Also you should leverage as much as possible on an existing/working C++ sample if you can (or close enough), as It is really easy to mess up things with DirectSound Initialization.
The administrator has disabled public write access.

Re: DirectSound record & play in vb.net - help 2 years 2 weeks ago #376

Hi

the error occurs on the .play line, but also whenever I try to mess with the primarybuffer for example when I try to read the frequency. ttt.Frequency

The DirectX from the control panel can enable debugging for Direct3D but there's nothing for DirectSound.

I'm now googling how to enable debugging on directsound.

thank you guys for putting me on the right track.
The administrator has disabled public write access.
  • Page:
  • 1
Time to create page: 0.206 seconds