Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Dim Byt1() As Byte = IO.File.ReadAllBytes("h.wav")
Dim Byt2() As Byte = IO.File.ReadAllBytes("e.wav")
Join(Byt1, Byt2)
Byt1 = IO.File.ReadAllBytes("temp.wav")
Byt2 = IO.File.ReadAllBytes("l.wav")
Join(Byt1, Byt2)
Byt1 = IO.File.ReadAllBytes("temp.wav")
Byt2 = IO.File.ReadAllBytes("ow.wav")
Join(Byt1, Byt2)
Dim snd As New System.Media.SoundPlayer("temp.wav")
snd.Play()
End Sub
Private Sub Join(ByRef byt1() As Byte, byt2() As Byte)
Dim Lgth As Integer
Dim SaveHeader(43) As Byte
'Save the header
System.Array.Copy(Byt1, 0, SaveHeader, 0, 43)
Dim FinalData(byt1.Length - 44) As Byte
'Save the data from the first file
System.Array.Copy(Byt1, 44, FinalData, 0, Byt1.Length - 44)
'Save the data from the second file
ReDim Preserve FinalData(byt1.Length + byt2.Length - 44)
System.Array.Copy(byt2, 44, FinalData, byt1.Length - 44, byt2.Length - 44)
'save length of new data
Lgth = FinalData.Length
'create array to hold final output
Dim Output() As Byte
ReDim Output(FinalData.Length + 43)
'add header
System.Array.Copy(SaveHeader, Output, 43)
'add data
System.Array.Copy(FinalData, 0, Output, 44, FinalData.Length)
'adjust data length
Dim bytes() As Byte = BitConverter.GetBytes(Lgth)
System.Array.Copy(bytes, 0, Output, 40, 4)
ByteArrayToFile("temp.wav", Output)
End Sub
' <summary>
' Function to save byte array to a file
' </summary>
' <param name="_FileName">File name to save byte array</param>
' <param name="_ByteArray">Byte array to save to external file</param>
' <returns>Return true if byte array save successfully, if not return false</returns>
Public Sub ByteArrayToFile(ByVal _FileName As String, ByVal _ByteArray() As Byte)
Try
'Dim myInt As Int32
'myint = BitConverter.ToInt32(_ByteArray, 40)
'MsgBox("Length of file " & BitConverter.ToString(BitConverter.GetBytes(_ByteArray.Length)) & ". Length stored in header " & BitConverter.ToString(BitConverter.GetBytes(myInt)))
'' Open file for readin
Dim _FileStream As New System.IO.FileStream(_FileName, System.IO.FileMode.OpenOrCreate, System.IO.FileAccess.Write)
' Writes a block of bytes to this stream using data from a byte array.
_FileStream.Write(_ByteArray, 0, _ByteArray.Length)
' close file stream
_FileStream.Close()
Catch _Exception As Exception
' Error
Console.WriteLine("Exception caught in process: {0}", _Exception.ToString())
End Try
' error occured, return false
End Sub