load from memory into FMOD?

New to FreeBASIC? Post your questions here.
Post Reply
maurosebastian91
Posts: 30
Joined: Mar 21, 2021 18:22

load from memory into FMOD?

Post by maurosebastian91 »

Hello colleagues, good morning. I have come today to ask you a question, which I have not been able to solve even though I have tried in every possible way.

These days I am starting a small audio game with the FMOD library, and I was trying to load sounds from memory, previously copied to a matrix from a file, but since I don't know if the file is copied correctly to memory or not, I don't know why I can't get it to reproduce the sound.

This is what I have.

dim array (1 to 3635) as zstring ptr
Open "tono.ogg" For Binary As #1
Get #1, , array
Close #1

sonido_recarga = FSOUND_Sample_Load( 2, @array(1), FSOUND_2D, 0, 3635 )

Perhaps there are things that I do not fully understand about the language, but as much as I have changed it many times I have not been able to make it work.

Please could you help me with this?

That they go very well.
dodicat
Posts: 7983
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: load from memory into FMOD?

Post by dodicat »

Because you use a pointer, you get a warning and the file is either 32 bits load and save or 64 bits load and save.

Code: Select all



#include "file.bi"



dim array (1 to 3635) as zstring ptr

array(1)=strptr("hello")
array(1000)=strptr("hello again")
array(3635)=strptr("goodbye")


sub load(file as string,u() as zstring ptr)
   var  f=freefile
   if fileexists(file)=0 then print file;"  not found":sleep:end
    Open file For Binary Access Read As #f
    If Lof(f) > 0 Then
      Get #f, ,u()
    End If
    Close #f
    end sub

sub save(file as string,u() as zstring ptr)
    var h=freefile
    open file for binary access write as #h
    put #h, ,u()
    close #h
end sub

save( "tono.ogg",array())
erase array

'==============================================
'==============================================
'start afresh in a new array:


var size=filelen( "tono.ogg")\sizeof(zstring ptr)
print "size of new array ";size

dim getarray(1 to size) as zstring ptr

load( "tono.ogg",getarray())
print *getarray(1)
print *getarray(1000)
print *getarray(3635)
kill  "tono.ogg"
sleep
 
maurosebastian91
Posts: 30
Joined: Mar 21, 2021 18:22

Re: load from memory into FMOD?

Post by maurosebastian91 »

Thank you very much for answering, I am using the 32 bit version of FMOD.
I had good progress, at least I was able to make it copy the file into memory, although passing that array to the FMOD function compiles correctly, but when executing it it closes. surely because I am passing the wrong parameters on memory.
UEZ
Posts: 988
Joined: May 05, 2017 19:59
Location: Germany

Re: load from memory into FMOD?

Post by UEZ »

This works for me:

Code: Select all

#Include "file.bi"
#Include "fmod.bi"

Dim As String SoundFile = "Test.ogg"
Dim As Integer l = Filelen(SoundFile)
Dim As Byte Ptr pMem
pMem = Allocate(l)
Dim As Integer f = FreeFile
Open SoundFile For Binary As #f
Get #f, , *pMem, l
Close #f

FSOUND_Init(44100, 32, 0)
Dim As Any Ptr song = FSOUND_Stream_Open(pMem, FSOUND_LOADMEMORY, 0, l)
FSOUND_Stream_Play(FSOUND_FREE, song)
? "Press any key to exit"
Sleep
FSOUND_Stream_Stop(song)
FSOUND_Stream_Close(song)
FSOUND_Close()
Deallocate pMem
maurosebastian91
Posts: 30
Joined: Mar 21, 2021 18:22

Re: load from memory into FMOD?

Post by maurosebastian91 »

great companion, it works perfectly, thank you very much.

I just have a little doubt in the code, in this line:

Get #f, , *pMem, l

what is that asterisk for? I always see it but I never quite understand what it does.
MrSwiss
Posts: 3910
Joined: Jun 02, 2013 9:27
Location: Switzerland

Re: load from memory into FMOD?

Post by MrSwiss »

maurosebastian91 wrote:what is that asterisk for? I always see it but I never quite understand what it does.
* = dereference operator (of a PTR), to get/set the 'pointed to' data (instead of changing the PTR itself).

Aka: the code is A-OK. See also FB-doc: Operator List --> Pointer Operators
Post Reply