Click here to Skip to main content
15,941,755 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I want to extract a vibration data of sound files in the form of an integer or any Understandable form like: 0.0111,1.00... and also make sound by entering the value that was extract.

What I have tried:

I haven't try any thing yet because I don't know where to start.(Noob)
Posted
Updated 30-Nov-16 12:07pm
Comments
Jochen Arndt 24-Nov-16 10:04am    
Do you mean some kind of vibration analysis using existing audio files?

If it is that or something similar it is quite complex (mathematical).
And you won't find much for VB.Net.
molali 24-Nov-16 12:45pm    
Thanks for reply.
I want to make a voice and sound recognition Engine, But I have little knowledge of sound. But the wav or mp3 is encrypted or Encoded to their format which I can't understand. What I need is the raw signal of the Audio in the form of integer something like -2,0,1.. The motion of frequency so I can compare it with other.

To process sound files they must be first converted to a raw (uncompressed) format. With Windows this is usually the WAV format (see WAV - Wikipedia[^]). This step is rather simple because there are a many programs that can do that (executables and also free sources that can be implemented in own programs).

Once you have a WAV file you can load the samples into memory and start processing the samples. This usually requires good mathematical knowledge (e.g. about the Fast Fourier transform - Wikipedia[^] and the Nyquist–Shannon sampling theorem - Wikipedia[^] ), even when not implementing the code based on mathematical formulas but using some existing free code.

Note that most code for audio processing (or more general: signal processing) is written in C/C++, for mathematical software like MATLAB, or design software like LabVIEW. You might find some C# sources but chances to find example code in VB.NET are rather small.

Detecting and isolating periodic vibration data should be no problem when knowing which methods must be used. But this is beyond my knowledge.

Overall it is an extensive task that requires learning the basics of audio/signal processing and the related mathematics.
 
Share this answer
 
Comments
molali 30-Nov-16 17:57pm    
Thanks I was studying on https://en.wikipedia.org/wiki/WAV and http://soundfile.sapp.org/doc/WaveFormat/ and I was finally understand and able to extract the frequency data which was Known as "Sample".
I Finally Found The Solution, It is known as "Sample" not a "Frequency"(Sorry for that). Here is the Function to read/Extract and create wav file, For those who need.
Reference Page: Microsoft WAVE soundfile format[^]

Call Example:
VB
'This will save as txt
 Getwav("Test.wav","Sample.txt")
'and
 MsgBox("SampleRate:" & Getwav("Test.wav",Nothing,24))


Code:
VB
'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


for making wav file from sample.

Call example:
VB
mkwav("Sample.txt", "Sample.wav")


Code:
VB
'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
 
Share this answer
 
v10
Comments
Member 11503692 25-Feb-21 2:58am    
I greet
I'm a beginner and I want to try something similar, but I don't know
how to resolve this line: Dim Data As String = RNW.RED_DATA (pt)
so how to create - RNW.RED_DATA
Thanks for advice.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900