Fabian_Russ
Newcomer
- Joined
- Sep 29, 2008
- Messages
- 23
Hello, for three days now, I have been working with DirectSound, and have ran into a pretty big issue.
I cannot figure out how to return a byte array from the SecondaryBuffer, I understand how to create the secondary buffer from a memory stream but not vice-versa, I need to either:
A: Read the SecondaryBuffer to a Memory stream.
B: Read the SecondaryBuffer to a Byte array.
Here is what I have so far (please let me know if there is anything I can improve):
-------------------------------------------------------------------------
Public Class DSound2
Public DSDevice As DirectSound.Device
Public DSBuffers As New List(Of DirectSound.SecondaryBuffer)
Public Sub Save(ByVal Path As String)
'Create directory if it does not exist.
If Not IO.Directory.Exists(Path.Remove(Path.LastIndexOf("\"))) Then
IO.Directory.CreateDirectory(Path.Remove(Path.LastIndexOf("\")))
End If
'Create file if it does not exist and close it.
If Not IO.File.Exists(Path) Then
IO.File.Create(Path).Close()
End If
'Declare storage for SecondaryBuffer
Dim StreamBytes As Byte() = New Byte(39999) {}
Dim StreamDat As New IO.MemoryStream(StreamBytes, 0, 40000, True, True)
'Loop through each SecondaryBuffer, returning data to StreamDat.
For Each File In DSBuffers
'File.Read seems to never return the correct data, ever.
'I know I am doing something wrong and it will take work to fix it but
'I thought this part would be easy, I've swapped pieces of code around many times and the best I could get was a byte array full of zeros.
File.Read(0, StreamDat, DirectSound.LockFlag.EntireBuffer, DirectSound.LockFlag.None)
'Transfer the data from the MemoryStream to the Byte Array.
StreamBytes = StreamDat.ToArray()
Next
End Sub
End Class
-------------------------------------------------------------------------
I would just like to convert the SecondaryStream object to Base64 data and write the combined DSBuffer objects to one single file.
It's getting the data back from SecondaryStream that is the issue though.
Any help/comments would very much be appreciated.
I will continue research to find a fix and will post back if I find one. Thanks.
I cannot figure out how to return a byte array from the SecondaryBuffer, I understand how to create the secondary buffer from a memory stream but not vice-versa, I need to either:
A: Read the SecondaryBuffer to a Memory stream.
B: Read the SecondaryBuffer to a Byte array.
Here is what I have so far (please let me know if there is anything I can improve):
-------------------------------------------------------------------------
Public Class DSound2
Public DSDevice As DirectSound.Device
Public DSBuffers As New List(Of DirectSound.SecondaryBuffer)
Public Sub Save(ByVal Path As String)
'Create directory if it does not exist.
If Not IO.Directory.Exists(Path.Remove(Path.LastIndexOf("\"))) Then
IO.Directory.CreateDirectory(Path.Remove(Path.LastIndexOf("\")))
End If
'Create file if it does not exist and close it.
If Not IO.File.Exists(Path) Then
IO.File.Create(Path).Close()
End If
'Declare storage for SecondaryBuffer
Dim StreamBytes As Byte() = New Byte(39999) {}
Dim StreamDat As New IO.MemoryStream(StreamBytes, 0, 40000, True, True)
'Loop through each SecondaryBuffer, returning data to StreamDat.
For Each File In DSBuffers
'File.Read seems to never return the correct data, ever.
'I know I am doing something wrong and it will take work to fix it but
'I thought this part would be easy, I've swapped pieces of code around many times and the best I could get was a byte array full of zeros.
File.Read(0, StreamDat, DirectSound.LockFlag.EntireBuffer, DirectSound.LockFlag.None)
'Transfer the data from the MemoryStream to the Byte Array.
StreamBytes = StreamDat.ToArray()
Next
End Sub
End Class
-------------------------------------------------------------------------
I would just like to convert the SecondaryStream object to Base64 data and write the combined DSBuffer objects to one single file.
It's getting the data back from SecondaryStream that is the issue though.
Any help/comments would very much be appreciated.
I will continue research to find a fix and will post back if I find one. Thanks.
Last edited: