Advertisement
Java_Volume1 Sound/MP3 #90044

Reading .wav files and outputting wave sample

This code displays the waves (graphically) of a .wav file, just like in Windows' Sound Recorder

AI

Riepilogo AI: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Codice sorgente
original-source
Private Sub Command1_Click()
  Dim LastX, LastY, CurX, CurY As Byte
  CommonDialog1.ShowOpen
  Form1.Caption = CommonDialog1.FileName & " - Graphical Wave"
  If CommonDialog1.CancelError = True Or CommonDialog1.FileName = "" Then Exit Sub
'If the user pressed cancel or didn't select anything then exit this sub
  On Error Resume Next
  Picture1.Width = FileLen(CommonDialog1.FileName)
'Makes the invisible picturebox the width of the size of the .wav file
  Open CommonDialog1.FileName For Binary As #1
  Get #1, 44, LastY
'Gets the 44th byte of the .wav file (that is where the sound information that we are
'interested in starts)
  LastX = 0
  For i = 45 To FileLen(CommonDialog1.FileName)
'Loops through each byte (after 44) of the file
    Get #1, i, CurY
    Picture1.Line (LastX, LastY + 22)-(i, CurY + 22), 0
'Draws a line in the invisible picturebox using the data we read from the file
    LastX = i
    LastY = CurY
  Next i
  Close #1
  StretchBlt Picture2.hdc, 0, 0, Picture2.ScaleWidth, Picture2.ScaleHeight, Picture1.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, vbSrcCopy
  Picture2.Refresh
'This just copies the area of picture1 into picture2, so that you can see the whole Wave
End Sub
Private Sub Form_Load()
  Form1.ScaleMode = vbPixels
  Picture1.AutoRedraw = True
  Picture1.ScaleMode = vbPixels
  Picture1.Visible = False
  Picture1.Height = 300
  Picture1.BackColor = vbWhite
  Picture2.AutoRedraw = True
  Picture2.ScaleMode = vbPixels
  Command1.Caption = "Load .wav"
  CommonDialog1.Filter = "Wave Files (.wav) | *.wav"
End Sub
Private Sub Form_Resize()
  Picture2.Move 0, Command1.Height, Form1.ScaleWidth, Form1.ScaleHeight
  Command1.Move 0, 0, Form1.ScaleWidth, Command1.Height
  'Stretches the visible picturebox and the commandbutton to fit the form
End Sub
Commenti originali (3)
Recuperato da Wayback Machine