Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21096

[RESOLVED] How can I read a binary file fast?

$
0
0
I have written code to read a .WAV file with 72,000,000 16 bit samples. My program takes 10.5 minutes to read this file using VB6 IDE in the XP emulation. Audacity, a free program, takes 5 seconds to read the same file also running in XP emulation. That is 126 times as fast as my code. How can I make mine read faster?

Variables beginning bol are Boolean
Variables beginning gbol are global Boolean
Variables beginning lng are Long
Variables beginning glng are global Long
Variables beginning int are integer
Variables beginning gint are global Integer
Variables beginning dbl are double
Variables beginning gdbl are global double
Variables beginning byt are Byte
Variables beginning gbyt are global Byte

Sorry but I can’t find how to format code.

Private Sub mnuFileOpenFile_Click()
frmWaitForLoad.Show ‘frmWaitForLoad just displays a message to wait
' Read data
gintMaxSampleChannel1 = -10000
gintMinSampleChannel1 = 10000
gintMaxSampleChannel2 = -10000
gintMinSampleChannel2 = 10000
bolContinueLines = True
lngSampleNr = 0
While bolContinueLines = True
glngFile1Position = glngFile1Position + 1
Get #gintFile1Num, glngFile1Position, bytChrIn
lngChr1 = bytChrIn
glngFile1Position = glngFile1Position + 1
Get #gintFile1Num, glngFile1Position, bytChrIn
lngChr2 = bytChrIn
lngTemp = lngChr1 + 256 * lngChr2
'Use 2's complement
If lngTemp > 32767 Then
lngTemp = lngTemp - 65536
End If
'Find Min and Max
If lngTemp > gintMaxSampleChannel1 Then
gintMaxSampleChannel1 = lngTemp
End If
If lngTemp < gintMinSampleChannel1 Then
gintMinSampleChannel1 = lngTemp
End If

'Place in Array
gintChannel1(lngSampleNr) = lngTemp

If lngSampleNr > glngNrSamplesPerChannel - 2 Then
bolContinueLines = False
Else
lngSampleNr = lngSampleNr + 1
End If
Wend

Viewing all articles
Browse latest Browse all 21096

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>