0
0

I have been trying to get this to work for a long time now, and I haven’t had any luck doing so. What I am trying to do is to load a file (MP3, WAV, OGG, whatever) from disk into memory. Then I am trying to load it into FMOD as a sample with FSOUND_LOADMEMORY. I haven’t been able to get this to work as FSOUND_Sample_Load always returns 0.

This is my code:
[code:mxmri3es]
Dim lStrm As Long
Dim b() As Byte

Private Sub Command1_Click()
Open App.Path & "\snd.wav" For Binary As #1
ReDim b(LOF(1) – 1) ‘-1 because starts at b(0)
Get #1, 1, b
Close #1

lStrm = FSOUND_Sample_Load(FSOUND_FREE, VarPtr(b(0)), FSOUND_LOADMEMORY, 0, UBound(b) + 1)

Debug.Print UBound(b), lStrm

End Sub
[/code:mxmri3es]

The debug output is the correct size of the file and a zero for lStrm.

Could someone tell me how to do it so it works? I have tried many things, changed the FSOUND_Sample_Load declaration in fmod.bas etc. but nothing works.

  • You must to post comments
0
0

i have “re-compile” the chm help file from FMOD v3.73 for use with VB6 in combination to a own tlb File.

Could it be that the “Development-Crew” works at the same front – then i could go to the next Pub;-)

  • You must to post comments
0
0

Or does loading & playing from memory just not work in visual basic 6? :(

  • You must to post comments
0
0

[quote:w28snlf4]fmod will work, just make sure your 2 values you are passing to fmod ARE the actual pointer / address of the data, and the length is correct.[/quote:w28snlf4]

So how do I pass the pointer to, in this case, the b() array?

  • You must to post comments
0
0

First of all, the declaration of FSOUND_Sample_Load in VB is:
[code:1hjzzk8z]Public Declare Function FSOUND_Sample_Load Lib "fmod.dll" Alias "_FSOUND_Sample_Load@20" (ByVal Index As Long, ByVal name As String, ByVal mode As FSOUND_MODES, ByVal offset As Long, ByVal length As Long) As Long[/code:1hjzzk8z]
As you notice, it expects a string, so it will just convert the pointer to your data to a string before passing it to the function.
So instead of passing a pointer to your data located at position 123, you will actually pass a pointer to a string that contains “123”.

What you need to do is something similar as the FSOUND_Stream_Open2 declaration, actually adding an Alias to the FSOUND_Sample_Load function that takes other arguments.

Here is the declaration of an FSOUND_Sample_Load2 function that can load from memory.
[code:1hjzzk8z]Public Declare Function FSOUND_Sample_Load2 Lib "fmod.dll" Alias "_FSOUND_Sample_Load@20" (ByVal Index As Long, ByRef memdata As Byte, ByVal mode As FSOUND_MODES, ByVal offset As Long, ByVal length As Long) As Long[/code:1hjzzk8z]
Note that the second argument is now passed ByRef (by reference) instead of Byval, and now wants a byte instead of a String.
If you now pass the first byte of your array, Visual Basic will pass the pointer to that byte, which is what you want.

So the code you should use is:
[code:1hjzzk8z]lStrm = FSOUND_Sample_Load2(FSOUND_FREE, b(0), FSOUND_LOADMEMORY, 0, UBound(b) + 1)[/code:1hjzzk8z]

  • You must to post comments
0
0

Thanks for the help, Adion, but It still won’t work.

I tried changing my code to what you suggested and that would just hang my program when i tried to load the sound with fmod. I had to shut the program down with the task manager.

I discovered that I used an old version of fmod (3.71) so I updated the code to 3.73 and now it’s just like before, the FSOUND_Sample_Load2 function returns zero.

Here’s my code now:
[code:33wunq6c]
Option Explicit

Private Declare Function FSOUND_Sample_Load2 Lib "fmod.dll" Alias "_FSOUND_Sample_Load@20" (ByVal index As Long, ByRef memdata As Byte, ByVal mode As FSOUND_MODES, ByVal offset As Long, ByVal length As Long) As Long
Dim lStrm As Long
Dim lchnl As Long
Dim b() As Byte

Private Sub Command1_Click()

Open App.Path & "\snd.mp3" For Binary As #1
ReDim b(LOF(1))
Get #1, 1, b
Close #1

lStrm = FSOUND_Sample_Load2(FSOUND_FREE, b(0), FSOUND_LOADMEMORY, 0, UBound(b) + 1)

Debug.Print UBound(b), lStrm

End Sub

Private Sub Form_Load()
Call FSOUND_Init(44100, 16, 0)
End Sub

Private Sub Form_Unload(Cancel As Integer)
Call FSOUND_Close
End Sub
[/code:33wunq6c]

Any ideas?

  • You must to post comments
0
0

The problem was LOF()

[code:hibici7o]
Private Sub Command1_Click()
Dim J As Long
Dim strFileName As String

Erase b
strFileName = App.Path & "\snd.mp3"

Open strFileName For Binary As #1
J = FileLen(strFileName)
If J > 0 Then
ReDim b(J)
Else
ReDim b(0)
End If
Get #1, 1, b
Close #1

lStrm = FSOUND_Sample_Load2(fsound_free, b(0), FSOUND_LOADMEMORY, 0, 0)
Me.Caption = UBound(b)

End Sub
[/code:hibici7o]

  • You must to post comments
0
0

Hi…

seems not to solve the problem. If i run my example, the only result from FSOUND_Sample_Load2 = 0.

Btw.: Which sense make: ReDim b(0) ?

My opinion is: No File = No Play…why do you dimension with 0 if the file can not play…is it not better to leave the sub?

HAL2004

P.S.: If anyone has FULL Sourcecode …post it here…”not bit by bit”
😕

[quote="dafhi":2n17v14a]The problem was LOF()

[code:2n17v14a]
Private Sub Command1_Click()
Dim J As Long
Dim strFileName As String

Erase b
strFileName = App.Path & "\snd.mp3"

Open strFileName For Binary As #1
J = FileLen(strFileName)
If J > 0 Then
ReDim b(J)
Else
ReDim b(0)
End If
Get #1, 1, b
Close #1

lStrm = FSOUND_Sample_Load2(fsound_free, b(0), FSOUND_LOADMEMORY, 0, 0)
Me.Caption = UBound(b)

End Sub
[/code:2n17v14a][/quote:2n17v14a]

  • You must to post comments
0
0

[code:2vzu1oqz]
Option Explicit

Dim lStrm As Long
Dim lchnl As Long

Private Sub Command1_Click()
Dim J As Long
Dim strFileName As String
Dim SampleINFO As FSOUND_MODES

strFileName = "file.mp3"
SampleINFO = 338  'got this value using FSOUND_Sample_GetMode on 16bit stereo wav

lStrm = FSOUND_Sample_Load(FSOUND_FREE, strFileName, SampleINFO, 0, 0)
lchnl = FSOUND_PlaySound(0, lStrm)

End Sub

Private Sub Form_Load()
Call FSOUND_Init(44100, 16, 0)
End Sub

Private Sub Form_Unload(Cancel As Integer)
FSOUND_Close
End Sub
[/code:2vzu1oqz]

  • You must to post comments
0
0

Ehh..SUPER…and what is with: FSOUND_LOADMEMORY?

we mean the same prob?

[quote="dafhi":2v0zxx1y][code:2v0zxx1y]
Option Explicit

Dim lStrm As Long
Dim lchnl As Long

Private Sub Command1_Click()
Dim J As Long
Dim strFileName As String
Dim SampleINFO As FSOUND_MODES

strFileName = "file.mp3"
SampleINFO = 338  'got this value using FSOUND_Sample_GetMode on 16bit stereo wav

lStrm = FSOUND_Sample_Load(FSOUND_FREE, strFileName, SampleINFO, 0, 0)
lchnl = FSOUND_PlaySound(0, lStrm)

End Sub

Private Sub Form_Load()
Call FSOUND_Init(44100, 16, 0)
End Sub

Private Sub Form_Unload(Cancel As Integer)
FSOUND_Close
End Sub
[/code:2v0zxx1y][/quote:2v0zxx1y]

  • You must to post comments
0
0

Hi…

i am too lazzy ..tired… to explain..it`s not my native language..but i have a running…complete solution….next days i could send some sources to public…my solution run under Vb6..”FSOUND_LOADMEMORY”, too;-).

  • You must to post comments
Showing 10 results
Your Answer

Please first to submit.