0
0

First off i looked at all the topics i could find about Loading streams from memory.

I use visual basic and cant seem to figure out how to make this work.

[code:1s0zr83e]’Variables
Dim FileNumber As Integer
Dim TempHandle As Long
Dim TempSize As Long
Dim TempData() As Byte

‘Get Free File Slot
FileNumber = FreeFile

‘Open File
Open "C:\chimes.wav" For Binary As #FileNumber

'Check Length
TempSize = LOF(FileNumber)

'Resize Data
ReDim TempData(TempSize - 1)

'Get File Data
Get #FileNumber, , TempData

‘Close
Close #FileNumber

‘Open Stream
TempHandle = FSOUND_Stream_Open2(TempData(0), FSOUND_NORMAL Or FSOUND_LOADMEMORY, 0, TempSize)
‘TempHandle = FSOUND_Sample_Load(-1, VarPtr(TempData(0)), FSOUND_NORMAL Or FSOUND_LOADMEMORY, 0, TempSize)

MsgBox FSOUND_GetErrorString(FSOUND_GetError)

‘Try Play
Result = FSOUND_Stream_Play(-1, TempHandle)
‘Result = FSOUND_PlaySound(-1, TempHandle)
[/code:1s0zr83e]

The app crashes when stream is loaded.
When i try loading as sample i get empty handle.

Any Help ?

  • You must to post comments
0
0

[quote="Quantum":20mlh3uq]> FSOUND_LOADMEMORY = &H8000
Weird, but it works if you change it into decimal:

FSOUND_LOADMEMORY = 32768

Don’t ask me why…

> FSOUND_Close
And why are you closing FMOD immediately after starting playback?

Remove that line or you just won’t have enough time to hear anything.

P.S. You where right about ByRef. Dunno why it didn’t work for me the first time.[/quote:20mlh3uq]
I stripped down the code for show thats why the FSOUND_Close is right after. :)

Wierd solution, Thanks alot it works here now.

EDIT:
When It starts to play the file the app crashes again (but it acctually starts playing).
I get wrong mode parameter, the &H8000 = -32768 not 32768, so the parameter was right.

  • You must to post comments
0
0

> I get wrong mode parameter, the &H8000 = -32768
> not 32768, so the parameter was right.
Nop. fmod.h:

define FSOUND_LOADMEMORY 0x00008000

The correct one is unsigned.

Try removing FSOUND_NORMAL. It’s redundant because the PCM header provides that info. If that doesn’t help, the bug should be somewhere else. I tested your example on XP SP2 and Win2K as well.

  • You must to post comments
0
0

For safety’s sake:

ReDim TempData(0 To TempSize – 1)

TempHandle = FSound_Stream_Open2(ByRef TempData(0), FSOUND_NORMAL Or FSOUND_LOADMEMORY, 0, TempSize)

  • You must to post comments
0
0

Well safety is good, but didn’t solve my problem. :)

Anyone tried running to code to see if it works on other system?
I just cant find out whats wrong with it, tried diffrent files and no luck.

@Janus:
Long time no chat. :)

  • You must to post comments
0
0

Sorry to double post, but does anyone have any clue to what might be the problem here?

  • You must to post comments
0
0

TempData(0) is the first byte of the stream! It’s not the address of the stream! Use VarPtr(TempData(0)) instead.

  • You must to post comments
0
0

[code:3keg1si9]Public Declare Function FSOUND_Stream_Open2 Lib "fmod.dll" Alias "_FSOUND_Stream_Open@16" (ByRef Data As Byte, ByVal mode As FSOUND_MODES, ByVal offset As Long, ByVal length As Long) As Long[/code:3keg1si9]
The Data variable is refrenced as Byte, inputing the first byte value then should give the dll the pointer.

I tried changing it to long value, but with no luck.

  • You must to post comments
0
0

TempData(0) IS NOT A POINTER! If you don’t want to believe me, just use a debugger and check it yourself.

First, change the proto:

[code:5lq2rol3]Public Declare Function FSOUND_Stream_Open2 Lib "fmod.dll" Alias "_FSOUND_Stream_Open@16" (ByVal Data As Long, ByVal mode As FSOUND_MODES, ByVal offset As Long, ByVal length As Long) As Long[/code:5lq2rol3]

Then, add VarPtr.

Works perfectly for me.

BTW, you don’t have to use FMOD if you only want to play a wav.

  • You must to post comments
0
0

[quote="Quantum":lnsjupa5]TempData(0) IS NOT A POINTER! If you don’t want to believe me, just use a debugger and check it yourself.

First, change the proto:

[code:lnsjupa5]Public Declare Function FSOUND_Stream_Open2 Lib "fmod.dll" Alias "_FSOUND_Stream_Open@16" (ByVal Data As Long, ByVal mode As FSOUND_MODES, ByVal offset As Long, ByVal length As Long) As Long[/code:lnsjupa5]

Then, add VarPtr.

Works perfectly for me.

BTW, you don’t have to use FMOD if you only want to play a wav.[/quote:lnsjupa5]

:(, still doesn’t work for me.
I could try it on a diffrent computer but its supposed to work.

I am not using it just to play a wave, i am using it to play diffrent formats like ogg. I am creating a custom resource format and i want to be able to uncompress the data from the resource file and play directly form memory.

Here is a package of the module i try tu run, its just triggered from a empty form. [url:lnsjupa5]http://masterquests.ekenkrona.com/dump/FModTest.zip[/url:lnsjupa5]

Thanks for the help btw:)

I know tempdata(0) is not a pointer, but when passed as byref.

  • You must to post comments
0
0

> FSOUND_LOADMEMORY = &H8000
Weird, but it works if you change it into decimal:

FSOUND_LOADMEMORY = 32768

Don’t ask me why…

> FSOUND_Close
And why are you closing FMOD immediately after starting playback?

Remove that line or you just won’t have enough time to hear anything.

P.S. You where right about ByRef. Dunno why it didn’t work for me the first time.

  • You must to post comments
Showing 10 results
Your Answer

Please first to submit.