I need to play an array of doubles..
my solution to the problem is to make another array of the same length of the type integer, which i believe is 16bit in vb, and then copy every value from the array of doubles to the array of integers..
ReDim buff(0 To Waves(nr).length – 1) As Long
Dim i As Long
For i = 0 To Waves(Index).length – 1
buff(i) = Waves(Index).Data(i) * 16000 ‘Data from doubles is normalized to range from -1.0 to 1.0
‘After the conversion I set up the flags
Dim Flags As Long
Flags = FSOUND_LOOP_OFF Or FSOUND_16BITS Or FSOUND_MONO Or FSOUND_SIGNED Or FSOUND_2D Or FSOUND_LOADRAW Or FSOUND_LOADMEMORY
‘I then want to upload the data to the sample via the command FSOUND_Sample_Upload
FSOUND_Sample_Upload sample1, buff(0), Flags
‘But this action always make my computer crash (in a very ugly fashion)
What am i doing wrong??
Is it a wrong flag og maybe the buff(0) statement thats off course??
Hope someone is able to help me..
ps. FMod has been initialized using FSOUND_Init(44100, 32, 0), and it return no error..
- mndrk asked 16 years ago
well, actually, you don’t have to change it to byref, if it’s byval you pass:
You see, here’s how things work:
ByVal – Pass exactly what you say to pass
ByRef – Pass the address of what you say to pass
ByRef basically throws a VarPtr on there for you. 😛
I know VarPtr also works, but I think it’s best not to use this hidden command, as it is undocumented, unsupported and is removed in VB.Net
I don’t know if pointers are supported in VB.Net, but if not we will still have to use hacks using byref and byval.
I’ve found the problem, it is in the declaration of the function.
It said ByVal which would as brett said pass the value of buff.
Change it as follows in fmod.bas
Public Declare Function FSOUND_Sample_Upload Lib "fmod.dll" Alias "_FSOUND_Sample_Upload@12" (ByVal sptr As Long, ByRef srcdata As Long, ByVal mode As Long) As Byte
and it should work.
In Visual Basic you have to pass buff(0), which will pass the adress of the first number in the array, which is the same as the adress of buff itself.
It all started with some people saying vb is just for beginners and that you can’t actually do something with it.
Now I want to prove them wrong
And if you are updating fmod.bas, it might be interesting to add the following declaration also :
Public Declare Function FSOUND_Stream_OpenFile2 Lib "fmod.dll" Alias "_FSOUND_Stream_OpenFile@12" (ByRef Data As Byte, ByVal mode As FSOUND_MODES, ByVal memlength As Long) As Long
It is a slightly changed openfile that should be used when loading streams from memory (it takes a byte array instead of a string as parameter)
Please login first to submit.