I updated a answer found at http://ift.tt/1rD5ilR from C# to VB but I get a strange result. The audio is faster than it should be and the 3 wav files (5 seconds, 1 second and 6 second) amount to a file of just over 6 seconds. All the files have the same waveformat (22050Hz Rate, mono, 32bit float).
In this project I am using NAudio.
My code:
Public Shared Sub Concatenate(outputFile As String, sourceFiles As IEnumerable(Of String))
Dim buffer As Byte() = New Byte(1023) {}
Dim waveFileWriter As WaveFileWriter = Nothing
Try
For Each sourceFile As String In sourceFiles
Using reader As New WaveFileReader(sourceFile)
If waveFileWriter Is Nothing Then
' first time in create new Writer
waveFileWriter = New WaveFileWriter(outputFile, reader.WaveFormat)
Else
If Not reader.WaveFormat.Equals(waveFileWriter.WaveFormat) Then
Throw New InvalidOperationException("Can't concatenate WAV Files that don't share the same format")
End If
End If
Dim read As Integer
While (reader.Read(buffer, 0, buffer.Length) > 0)
read = reader.Read(buffer, 0, buffer.Length)
waveFileWriter.Write(buffer, 0, read)
End While
End Using
Next
Finally
If waveFileWriter IsNot Nothing Then
waveFileWriter.Dispose()
End If
End Try
End Sub
The function will be called like this:
Dim m_oEnum As IEnumerable(Of String) = New List(Of String)() From {"c:\1.wav", "c:\2.wav", "c:\3.wav"}
Concatenate("c:\joined.wav", m_oEnum)
Can anyone help me with this? I have a susoiction that it may have something to do with the sample format being 32 bit float.
Aucun commentaire:
Enregistrer un commentaire