Here is a simple snippet wich will write the data to a wav file, as this question is frequently asked :

Private Type RIFF_HEADER
RIFF As Long
riffBlockSize As Long
riffBlockType As Long
End Type

Private Type WAVE_HEADER
dataBlockType As Long
dataBlockSize As Long
End Type

Private Type WAVE_FORMAT
wfBlockType As Long
wfBlockSize As Long
wFormatTag As Integer
nChannels As Integer
nSamplesPerSec As Long
nAvgBytesPerSec As Long
nBlockAlign As Integer
wBitsPerSample As Integer
End Type

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal length As Long)

Private Sub Write_WAV(ByVal m_inputFile As String, ByVal m_outputFile As String)
‘ variables
Dim m_sample As Long ‘ sample pointer
Dim m_sampleLen As Long
Dim m_samplesNeeded As Long
Dim m_sampleProp As Long ‘ sample properties
Dim m_frequency As Long
Dim m_position As Long
Dim m_pcmData() As Byte ‘ buffer to hold data
Dim m_FIO As Integer

‘ Structure
Dim m_structWAVEHdr As WAVE_HEADER
Dim m_structWAVEFmt As WAVE_FORMAT

m_FIO = FreeFile
m_sample = FSOUND_Sample_Load(FSOUND_FREE, m_inputFile, FSOUND_NORMAL, 0)
m_sampleLen = FSOUND_Sample_GetLength(m_sample) * 4  '  convert sample to bytes * sizeof(long)

' Prepare the Wave Header
m_sampleProp = FSOUND_Sample_GetMode(m_sample)
m_structWAVEFmt.wFormatTag = 1
m_structWAVEFmt.nChannels = IIf(m_sampleProp And FSOUND_MONO, 1, 2)
Call FSOUND_Sample_GetDefaults(m_sample, m_frequency, 0, 0, 0)
m_structWAVEFmt.nSamplesPerSec = m_frequency
m_structWAVEFmt.wBitsPerSample = IIf(m_sampleProp And FSOUND_8BITS, 8, 16)
m_structWAVEFmt.nBlockAlign = m_structWAVEFmt.nChannels * m_structWAVEFmt.wBitsPerSample / 8
m_structWAVEFmt.nAvgBytesPerSec = m_structWAVEFmt.nSamplesPerSec * m_structWAVEFmt.nBlockAlign
m_structWAVEFmt.wfBlockType = &H20746D66
m_structWAVEFmt.wfBlockSize = 16

m_structRIFF.RIFF = &H46464952
m_structRIFF.riffBlockSize = 0
m_structRIFF.riffBlockType = &H45564157

m_structWAVEHdr.dataBlockType = &H61746164
m_structWAVEHdr.dataBlockSize = 0

Open m_outputFile For Binary Lock Read Write As m_FIO

' Write the WAV Header
Put m_FIO, , m_structRIFF
Put m_FIO, , m_structWAVEFmt
Put m_FIO, , m_structWAVEHdr

m_position = 0
' Increase this to your need (don't forget to update FSOUND_SetBufferSize too)
m_samplesNeeded = 16384
While m_position < m_sampleLen
    Dim m_ptr1 As Long
    Dim m_ptr2 As Long
    Dim m_len1 As Long
    Dim m_len2 As Long

    Call FSOUND_Sample_Lock(m_sample, m_position, m_samplesNeeded, m_ptr1, m_ptr2, m_len1, m_len2)
    ' Alloc a new buffer of chunk data
    ReDim Preserve m_pcmData(0 To m_len1 - 1) As Byte

    ' copy the address pointer to the allocated buf
    Call CopyMemory(m_pcmData(0), ByVal m_ptr1, m_len1)

    ' write the buf
    Put m_FIO, , m_pcmData

    ' update the offset position
    m_position = m_position + m_len1

    ' Use a progressbar or whathever you want ^_^
    'Label1(13).Caption = pos

    ' without this, the cpu is used at 100 %
    Call Sleep(1)
    Call FSOUND_Sample_Unlock(m_sample, m_ptr1, m_ptr2, m_len1, m_len2)

    ' let windows do it's job

    ' Write the end of the WAVE header
    m_structRIFF.riffBlockSize = m_position + 44 - 8
    m_structWAVEHdr.dataBlockSize = m_position
    Put m_FIO, 5, m_structRIFF.riffBlockSize
    Put m_FIO, 41, m_structWAVEHdr.dataBlockSize

    ' And close the output file
    Close m_FIO

    ' Free the sample
    FSOUND_Sample_Free (m_sample)
    Erase m_pcmData        

    MsgBox "Encoding Finished !", vbInformation

End Sub


  • You must to post comments

For a different approach in building WAV headers (and some explanations):

The link above is my “cheat sheet” in forming new WAV headers, but to learn the proper terminology such as is used in this thread, the best “spec sheet” on WAV headers i could find is
http://ccrma.stanford.edu/courses/422/p … aveFormat/

  • You must to post comments

[url=http://www.unlockyourfone.com:28u8p6mo]Unlock phones[/url:28u8p6mo] [url=http://www.matatapipe.com:28u8p6mo]music[/url:28u8p6mo] [url=http://www.watchpremiershiptv.com:28u8p6mo]soccer tv[/url:28u8p6mo] [url=http://www.macdof.com/order/index.html:28u8p6mo]Cheap mp3s[/url:28u8p6mo] [url=http://www.ebayrevive.com:28u8p6mo]get back on ebay even after suspension[/url:28u8p6mo]
[url=http://www.moneyreadingemails.com:28u8p6mo]Money reading emails[/url:28u8p6mo]
[url=http://www.ebonyandbare.com:28u8p6mo]Male entertainers[/url:28u8p6mo]
[url=http://www.cutswing.com:28u8p6mo]Improve your golf score in 2 weeks[/url:28u8p6mo]
[url=http://www.quitit4ever.com:28u8p6mo]Stop smoking within a week[/url:28u8p6mo]
[url=http://www.paidnomoneydown.com:28u8p6mo]Amazing paypal loophole a must for buyers and sellers[/url:28u8p6mo]
[url=http://www.rpoints.com/?ruid=55719:28u8p6mo]Get £5 for absolutely free[/url:28u8p6mo]
[url=http://tinyurl.com/a6mm5:28u8p6mo]Get £4 for joining ebay and bidding absolutely free[/url:28u8p6mo]

  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.