Question Wav data turned into a graph.

MeditatingLemur

New member
Joined
Jan 9, 2014
Messages
2
Programming Experience
1-3
Hi all,
I am currently coding a project to display a wav sound file as a graph.
I can read the data*
I can draw a graph.
But I'm struggling to find the data I want to make the graph look and feel like it is customised to the specific sound file.

*Public Function Reading_WAV_File_in_PCM_Format(ByVal WAVFile As String) As List(Of String) ' BinaryReader just makes it easier to read several bytes (='words') at a time.
If wavchosen = True Then
validated1 = True
Dim WAVStream As Stream = Nothing
Dim WAVBR As BinaryReader = Nothing
Dim WAVReturn As New List(Of String)
Try
WAVStream = File.Open(WAVFile, FileMode.Open, FileAccess.Read)
WAVBR = New BinaryReader(WAVStream)
' Start reading bytes
Dim WAVChunkID As String = UTF8Encoding.UTF8.GetString(BitConverter.GetBytes(WAVBR.ReadUInt32))
Dim WAVChunkSiWAVe As Long = WAVBR.ReadUInt32 + 8
Dim WAVFormat As String = UTF8Encoding.UTF8.GetString(BitConverter.GetBytes(WAVBR.ReadUInt32))


Dim WAVSubchunk1ID As String = UTF8Encoding.UTF8.GetString(BitConverter.GetBytes(WAVBR.ReadUInt32))
Dim WAVSubchunk1SiWAVe As Long = WAVBR.ReadUInt32
Dim WAVAudioFormat As Long = WAVBR.ReadUInt16
Dim WAVNumChannels As Long = WAVBR.ReadUInt16
Dim WAVSamplesPerSecond As Long = WAVBR.ReadUInt32
Dim WAVBytesPerSecond As Long = WAVBR.ReadUInt32
Dim WAVBlockAlign As Long = WAVBR.ReadUInt16
Dim WAVBitsPerSample As Long = WAVBR.ReadUInt16


' 16 bytes read after WAVSubchunk1SiWAVe -- if WAVSubchunk1SiWAVe says there's more data, then we
' need to read extra bytes. (I'm subtracting 17 to make sure WAVBR.ReadByte doesn't happen if unneeded)
For WAVA As Long = 0 To WAVSubchunk1SiWAVe - 17
WAVBR.ReadByte()
Next


' Now at Subchunk2, which contains the audiodata (all the digital samples taken from the sound)
Dim WAVSubchunk2ID As String = UTF8Encoding.UTF8.GetString(BitConverter.GetBytes(WAVBR.ReadUInt32))
Dim WAVSubchunk2SiWAVe As Long = WAVBR.ReadUInt32


' Calculations of extra info:
Dim WAVBytesPerSample As Long = WAVBitsPerSample / 8
Dim WAVNumberOfSamples As Long = WAVSubchunk2SiWAVe / WAVBytesPerSample / WAVNumChannels
Dim WAVAudioTrackLength As New TimeSpan(0, 0, WAVNumberOfSamples / WAVSamplesPerSecond)
Dim WAVBitrate As Long = WAVBytesPerSecond * 8 / 1000


' Build output
WAVReturn.Add(wavlocation)
WAVReturn.Add("Filetype: " & WAVChunkID & ", " & WAVFormat)
WAVReturn.Add("AudioFormat: " & IIf(WAVAudioFormat = 1, "PCM - Lossless", WAVAudioFormat.ToString & " - Compressed"))
WAVReturn.Add("Number of AudioChannels: " & WAVNumChannels & IIf(WAVNumChannels = 2, " (Stereo)", ""))
WAVReturn.Add("Number of Samples: " & WAVNumberOfSamples)
WAVReturn.Add("SampleRate: " & WAVSamplesPerSecond & "HWAV")
WAVReturn.Add("BitRate: " & WAVBitrate & "kbps")
WAVReturn.Add("TrackLength: " & WAVAudioTrackLength.ToString)


Catch ex As Exception
WAVReturn.Add("Error: " & ex.Message)
MsgBox("Fail")
Finally
WAVBR.Close()
WAVStream.Close()
WAVStream.Dispose()


End Try


Call GRAPHdata()
Return WAVReturn
End If
End Function.


If anyone could offer some advise or even so code (if they're that clever) it would be much appreciated.

Andrew

P.S. I can offer code to anyone in need of a similar project if they email me.
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,171
Location
Sydney, Australia
Programming Experience
10+
I'm struggling to find the data I want to make the graph look and feel like it is customised to the specific sound file.
You're going to have to elaborate a bit on what that means. What look and feel are you going for?
 

MeditatingLemur

New member
Joined
Jan 9, 2014
Messages
2
Programming Experience
1-3
You're going to have to elaborate a bit on what that means. What look and feel are you going for?
Well as I have all that data I'm a bit confused as to what data will, when fed into an array, will "move" in time to the music.

A simple waveform which scrolls once a second and is a colour on the RGB spectrum is far as advanced as I would like the graphic.
 
Top Bottom