molali
Я наконец нашел решение, оно известно как" образец", а не"частота" (извините за это). Вот функция для чтения/извлечения и создания wav-файла, для тех, кому это нужно.
справочная страница: Формат звукового файла Microsoft WAVE[^]
Пример Вызова:
'This will save as txt
Getwav("Test.wav","Sample.txt")
'and
MsgBox("SampleRate:" & Getwav("Test.wav",Nothing,24))
Код:
'GetSample
Public Shared Function Getwav(Pt As String, Optional Opt As String = Nothing, Optional File_Offset As Integer = 44)
'Checking File
If File.Exists(Pt) = False Then
Return Nothing
End If
Try
'Reading File
Dim Byt() As Byte = File.ReadAllBytes(Pt)
Dim Mem As New MemoryStream(Byt)
Dim bin As New BinaryReader(Mem)
Dim Sample As New List(Of Integer)
Dim ChunkID As String = Nothing
bin.BaseStream.Position = 4
Dim ChunkSize As Integer = bin.ReadInt32
Dim Format As String = Nothing
Dim Subchunk1ID As String = Nothing
bin.BaseStream.Position = 16
Dim Subchunk1Size As Integer = bin.ReadInt32
Dim AudioFormat As Integer = bin.ReadInt16
Dim NumChannels As Integer = bin.ReadInt16
Dim SampleRate As Integer = bin.ReadInt32
Dim ByteRate As Integer = bin.ReadInt32
Dim BlockAlign As Integer = bin.ReadInt16
Dim BitsPerSample As Integer = bin.ReadInt16
Dim Subchunk2ID As String = Nothing
bin.BaseStream.Position = 40
Dim Subchunk2Size As Integer = bin.ReadInt32
bin.BaseStream.Position = 0
For i = 1 To 4
ChunkID &= bin.ReadChar
Next
bin.BaseStream.Position = 8
For i = 1 To 4
Format &= bin.ReadChar
Next
bin.BaseStream.Position = 12
For i = 1 To 4
Subchunk1ID &= bin.ReadChar
Next
bin.BaseStream.Position = 36
For i = 1 To 4
Subchunk2ID &= bin.ReadChar
Next
If File_Offset = 44 Then
bin.BaseStream.Position = 44
If Opt = Nothing = False Then
If File.Exists(Opt) Then
File.Delete(Opt)
End If
Dim wrt As New StreamWriter(Opt)
For i = 1 To Subchunk2Size / 2
wrt.WriteLine(bin.ReadInt16)
Next
wrt.Close()
Else
For i = 1 To Subchunk2Size / 2
Sample.Add(bin.ReadInt16)
Next
Return Sample
End If
End If
If File_Offset = 0 Then
Return ChunkID
End If
If File_Offset = 4 Then
Return ChunkSize
End If
If File_Offset = 8 Then
Return Format
End If
If File_Offset = 12 Then
Return Subchunk1ID
End If
If File_Offset = 16 Then
Return Subchunk1Size
End If
If File_Offset = 20 Then
Return AudioFormat
End If
If File_Offset = 22 Then
Return NumChannels
End If
If File_Offset = 24 Then
Return SampleRate
End If
If File_Offset = 28 Then
Return ByteRate
End If
If File_Offset = 32 Then
Return BlockAlign
End If
If File_Offset = 34 Then
Return BitsPerSample
End If
If File_Offset = 36 Then
Return Subchunk2ID
End If
If File_Offset = 40 Then
Return Subchunk2Size
End If
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Return Nothing
End Function
для создания wav-файла из образца.
Пример вызова:
mkwav("Sample.txt", "Sample.wav")
Код:
'Make wav
Public Shared Sub mkwav(pt As String, OPt As String,
Optional NumChannels As Integer = 1,
Optional SampleRate As Integer = 11025,
Optional BitsPerSample As Integer = 8)
'Checking Files
If File.Exists(pt) = False Then
Exit Sub
End If
'Creating Wav File
Dim Fdata As New List(Of Byte)
Try
Dim ChunkID As Integer = 1179011410
Dim ChunkSize As Integer = 0
Dim Format As Integer = 1163280727
Dim Subchunk1ID As Integer = 544501094
Dim Subchunk1Size As Integer = 16
Dim AudioFormat As Integer = 1
Dim ByteRate As Integer = 0
Dim BlockAlign As Integer = 0
Dim Subchunk2ID As Integer = 1635017060
Dim Subchunk2Size As Integer = 0
Dim NumSamples As Integer = 0
'Reading Sample
Dim Data As String = RNW.RED_DATA(pt)
Dim Ray() As String = Data.Split(Environment.NewLine.ToCharArray,
StringSplitOptions.RemoveEmptyEntries)
'Calculating Sizes
NumSamples = (Ray.Count * 2) + 1
Subchunk2Size = (NumSamples * NumChannels * BitsPerSample) / 8
ChunkSize = 4 + (8 + Subchunk1Size) + (8 + Subchunk2Size)
ByteRate = (SampleRate * NumChannels * BitsPerSample) / 8
BlockAlign = (NumChannels * BitsPerSample) / 8
'Adding to Fdata
Dim Count As Integer = 0
For Each B In BitConverter.GetBytes(ChunkID)
Fdata.Add(B)
Next
For Each B In BitConverter.GetBytes(ChunkSize)
Fdata.Add(B)
Next
For Each B In BitConverter.GetBytes(Format)
Fdata.Add(B)
Next
For Each B In BitConverter.GetBytes(Subchunk1ID)
Fdata.Add(B)
Next
For Each B In BitConverter.GetBytes(Subchunk1Size)
Fdata.Add(B)
Next
For Each B In BitConverter.GetBytes(AudioFormat)
If Count = 2 Then
Exit For
End If
Fdata.Add(B)
Count += 1
Next
Count = 0
For Each B In BitConverter.GetBytes(NumChannels)
If Count = 2 Then
Exit For
End If
Fdata.Add(B)
Count += 1
Next
For Each B In BitConverter.GetBytes(SampleRate)
Fdata.Add(B)
Next
For Each B In BitConverter.GetBytes(ByteRate)
Fdata.Add(B)
Next
Count = 0
For Each B In BitConverter.GetBytes(BlockAlign)
If Count = 2 Then
Exit For
End If
Fdata.Add(B)
Count += 1
Next
Count = 0
For Each B In BitConverter.GetBytes(BitsPerSample)
If Count = 2 Then
Exit For
End If
Fdata.Add(B)
Count += 1
Next
For Each B In BitConverter.GetBytes(Subchunk2ID)
Fdata.Add(B)
Next
For Each B In BitConverter.GetBytes(Subchunk2Size)
Fdata.Add(B)
Next
For Each S In Ray
If S = Nothing = False Then
Count = 0
For Each B In BitConverter.GetBytes(CInt(S))
If Count = 2 Then
Exit For
End If
Fdata.Add(B)
Count += 1
Next
End If
Next
Dim wrt As New FileStream(OPt, FileMode.Create)
For Each B In Fdata
wrt.WriteByte(B)
Next
wrt.Close()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub