0
0

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
Next i

‘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..

  • You must to post comments
0
0

As I normaly code in c++, I thought that just writing buff, with no index, would be the right way to do a pointer, but writing just buff, gives me a syntax error :eek:(

buff(0) however crashes the app..

  • You must to post comments
0
0

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[0].
Change it as follows in fmod.bas
[code:68q95y8q]
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
[/code:68q95y8q]
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.

  • You must to post comments
0
0

It now uploades the sampledata perfectly fine, and returns true as intended..

Thanks alot for the vb support!!

  • You must to post comments
0
0

hehe,
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 :smile:

And if you are updating fmod.bas, it might be interesting to add the following declaration also :
[code:94s213ui]
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
[/code:94s213ui]
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)

  • You must to post comments
0
0

well, actually, you don’t have to change it to byref, if it’s byval you pass:
VarPtr(buff(0))
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. ๐Ÿ˜›

  • You must to post comments
0
0

Exact Janus, and i can add that ByRef must be used when we know that the value at this address will change (like pointers). Who say that we can’t use pointers with vb, uh ? ๐Ÿ˜‰

  • You must to post comments
0
0

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.

  • You must to post comments
0
0

VB.Net has full native pointer support. :smile:

  • You must to post comments
Showing 8 results
Your Answer

Please first to submit.