5
Ноябрь
2009
Функция возвращает массив данных из WAV файла
Функция возвращает массив данных из WAV файла
Option Explicit Enum LEN_FORMAT frmSeconds = 0 frmSamples = 1 End Enum Type RIFF_HEAD riffFmt As String * 4 lenOfFileData As Long End Type Type WAVE_HEAD waveFmt As String * 8 lenOfThunk As Long format As Integer channels As Integer samplesPerSecond As Long avgBytesPerSecond As Long blockAlign As Integer bitsPerSample As Integer End Type Type DATA_HEAD dataStr As String * 4 lenOfThunk As Long End Type ' =================================================================================================== ' Функция возвращает массив данных из WAV файла Public Function ReadWaveData(ByVal fileName As String, Optional howMany As Long) As Variant On Error GoTo ERRH Dim freeNum As Long Dim size As Long Dim bits As Byte freeNum = FreeFile Open fileName For Binary As #freeNum Get #freeNum, 41, size Get #freeNum, 35, bits If bits = 8 Then Dim arrByte() As Byte Else Dim arrInteger() As Integer End If If howMany < 0 Then If bits = 8 Then ReDim arrByte(size - 1) Else ReDim arrInteger(Int(size / 2) - 1) End If Else If howMany > size Or howMany = 0 Then howMany = size If bits = 8 Then ReDim arrByte(howMany - 1) Else ReDim arrInteger(howMany - 1) End If End If If bits = 8 Then Get #freeNum, 45, arrByte Else Get #freeNum, 45, arrInteger End If Close #freeNum If bits = 8 Then ReadWaveData = arrByte Else ReadWaveData = arrInteger End If Exit Function ERRH: ReadWaveData = False End Function