I wanted to ask, how to make the sound visible with fmod and VB!

Can I do something like this? And How?


  • You must to post comments

Look at the example code for VB, it shows a spectrum analyzer.
If you want wave data, you need to create a DSP Callback

  • You must to post comments

I’m not sure what nci is assuming; but you do not need a DSP callback in VB to display wave data during playback or when seeking manually.

In one application, the media is opened in stream mode, which exposes a sample handle. This sample is updated whenever the stream position changes. You only have to retrieve and process a chunk of samples equivalent to the granularity of the picturebox (e.g., 50 ms worth).

Essentially what you do is poll the media in ‘frames’ (where a frame is defined by you). Each time a new frame is reached, lock the sample, copy the data to a pcm byte buffer, unlock the sample, and then re-draw the picture box. In other words, you present a segment (frame) of samples at the same time that segment (frame) starts to play. The time needed to play a frame is usually sufficient to handle the array and drawing updates (e.g., a WinXP P4 machine will support 30 ms frames, no problem).



  • You must to post comments

it’s much easier in a dsp callback :)

  • You must to post comments

nci, post some code?

  • You must to post comments

Well, actually, I’m not sure what is easier in VB :) I am used to BCX where
I can use pointers, in VB, I have to copy the memory, but, here is some code


‘The DSP callback
Public Function ScopeCallback(ByVal originalbuffer As Long, ByVal newbuffer As Long, ByVal length As Long, ByVal param As Long) As Long
On Error Resume Next

'Set DSP
lngScopeBuffer = newbuffer 'Store the pointer here
ScopeCallback = newbuffer  'Return the buffer

End Function

‘This function is called to fill an array with the sample data
Public Function GetScope(ByRef Scope() As Integer) As Boolean ‘Use Single for an FPU mixer
On Error Resume Next
Dim nrOfVals As Long

'Test for error
If lngScopeBuffer = 0 Then GetScope = False

'Get number of values
nrOfVals = UBound(Scope) + 1

'copy memory
CopyMemory Scope(0), ByVal lngScopeBuffer, nrOfVals * 2 '4 for single

GetScope = True

End Function

‘Code to plot the values

    If GetScope(intScopeData) = False Then Exit Sub 'Array of integers (size of bufferlength)

    MoveToEx picSpec.hdc, 0, (picSpec.Height / 2), CurPoint

    picSpec.ForeColor = lngScopeColor
    For intVisX = 0 To FSOUND_DSP_GetBufferLength / 16 - 1
        intScope = (intScopeData(intVisX * 16))
        LineTo picSpec.hdc, intVisX * (picSpec.ScaleWidth / (FSOUND_DSP_GetBufferLength / 16)), (picSpec.Height / 2) + (intScope * (picSpec.Height / 50000))
    Next intVisX


As far as I know, you can’t get the right audio data, just the left. This is
because VB can’t incrament pointers? If there is a way, let me know :)

If you want more detailed code, goto http://xmedia.sphosting.com and
download XMP Developer’s edition 3.94 from the development section.

  • You must to post comments

I dont know how VB might increment pointers, but you can always increment the array position, and use a SafeArray:

Private Type SAFEARRAY1D
cDims As Integer
fFeatures As Integer
cbElements As Long
cLocks As Long
pvData As Long
cElements As Long
lLbound As Long
End Type

Dim lpBuffer() As Integer

Private Declare Function VarPtrArray Lib "msvbvm60" Alias "VarPtr" (Ptr() As Any) As Long

Private Sub CreatePointer(pData As Long, BufSamples As Long)
If pData <> 0 Then
SA.cDims = 1
SA.cbElements = PCM.nBitsPerSample / 8
SA.cElements = BufSamples * PCM.nChannels
SA.pvData = pData
CopyMemory ByVal VarPtrArray(lpBuffer), VarPtr(SA), 4&
End If
End Sub

Private Sub PlotValues()
Dim J As Long

For J = LBound(lpBuffer) To UBound(lpBuffer)


End Sub

Private Sub ClearPointer()
CopyMemory ByVal VarPtrArray(lpBuffer), 0&, 4
End Sub


  • You must to post comments

Thanks for the info. I got wave plotting via dsp now, which is cool because i can drag the form and the sound doesn’t interrupt. What I’d really like is to write to the signal .. 😮 thank you too brett 😀

  • You must to post comments
Showing 7 results
Your Answer

Please first to submit.