Hi there!

I’m tryin’ to get the FMOD_Sample_Lock()/Unlock() – Code working in order to get the individual sample values. But before I get to think about Code to work with this values, I’m hanging now far away from this step for hours. 😥

The problem is that the “CopyMemory” Function causes an “Access violation” when I try to copy more than approx. 5,000 bytes or so.

My Code:
Private Sub cmdWave_Click()
Dim lenBytes As Long
Dim ptr1, ptr2, len1, len2 As Long
Dim WaveValues() As Integer
Dim blabla As Boolean

lenBytes = FSOUND_Sample_GetLength(lngSampleHdl) * 4

If FSOUND_Sample_Lock(ByVal lngSampleHdl, 0, lenBytes, ptr1, ptr2, len1, len2) = 1 Then
    ReDim WaveValues(0 To lenBytes - 1)
    CopyMemory WaveValues(0), ptr1, lenBytes
    blabla = FSOUND_Sample_Unlock(ByVal lngSampleHdl, ByVal ptr1, ByVal ptr2, ByVal len1, ByVal len2)
End If

End Sub

The line
lenBytes = FSOUND_Sample_GetLength(lngSampleHdl) * 4
delivers an amount of ~34,712,064 bytes.

Any suggestions?

thx Mike!

  • You must to post comments

Remove all the ByVal keywords.

  • You must to post comments

OK .. I’ve removed them all. But this doesn’t work too. :( There must be any other Error. :roll:


  • You must to post comments

I didn’t take attention to the size returned by FSOUND_Sample_GetLength, it can be that it is too high, try by locking a chunk of data and update the position, like this :

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


  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.