Page 1 of 1

Oldskool Music Engine - [Resolved]

Posted: Wed Aug 05, 2009 12:11 pm
by AndyC
Hi All.

I've recently got back into coding after a long time off and have found a .dll by Slippy for the Oldskool Music Engine. OSME.

See below for his vc and Freebasic source and examples.
http://www.vectronixhq.de/?page_id=27
http://www.vectronixhq.de/?page_id=29

It replays many oldskool tunes, sndh, fc, ym etc. all of which I have many of and would like to play them.

I've tried it in Freebasic with his libraries but when calling the .dll in PB it plays but instantly crashes. If you debug it you can hear the tune playing though until you quit the debugger.


I've unpacked the original .dll (UPX3 packed) just to make sure the functions were actually correct, and they are.
Download it from above links.

Well I believe I have the syntax correct (new to this) when calling the functions in the .dll but I was hoping someone would tell me what i'm doing wrong.
Here's what i've got so far.
:?

Code: Select all

;save as osmreplayer.pbi

#OSM=0 

Declare INIT_OSMEngine()
Declare playOSMEMusicFile(filename.s, length.l, trackId.l)
Declare playOSMEMusicMem(pMusic.l,trackId.l)
Declare stopOSMEMusic()
Declare pauseOSMEMusic()
Declare resumeOSMEMusic()
Declare getOSMEChannelVU(i.l)
Declare setOSMEVolume(vol.l)


Procedure INIT_OSMEngine()
   Protected *DLL.l
  *DLL = OpenLibrary(#OSM,"osmengine.dll")
  If *DLL=0
    MessageRequester("Error", "Can't load OsmEngine", 0)
    End
  Else
    ProcedureReturn *DLL
  EndIf
EndProcedure

Procedure playOSMEMusicFile(filename.s,length.l,trackId.l)
  ProcedureReturn CallFunction(#OSM,"playOSMEMusicFile", filename, length, trackId)
EndProcedure

Procedure playOSMEMusicMem(pMusic.l,trackId.l)
  ProcedureReturn  CallFunction(#OSM,"playOSMEMusicMem", pMusic, trackId)
EndProcedure

Procedure stopOSMEMusic()
  ProcedureReturn  CallFunction(#OSM,"stopOSMEMusic")
EndProcedure

Procedure pauseOSMEMusic()
  ProcedureReturn  CallFunction(#OSM,"pauseOSMEMusic")
EndProcedure

Procedure resumeOSMEMusic()
  ProcedureReturn  CallFunction(#OSM,"resumeOSMEMusic")
EndProcedure

Procedure getOSMEChannelVU(i.l)
  ProcedureReturn  CallFunction(#OSM,"getOSMEChannelVU",i)
EndProcedure

Procedure setOSMEVolume(vol.l)
  ProcedureReturn  CallFunction(#OSM,"setOSMEVolume",vol)
EndProcedure


Code: Select all


IncludeFile "osmereplayer.pbi"

INIT_OSMEngine()

;playOSMEMusicMem(?music,?musend-?music,1)

*Buffer=AllocateMemory(7000)

playOSMEMusicFile("farewell_lil_ssd.sndh", *Buffer,1) ;change tune for your fave .fc, sndh, or .ym tune

MessageRequester("O.S.M.E Rulez", "Press Ok")

stopOSMEMusic()
End

If you debug the code then you'll find it crashes immediately after the play command ! :(

I've tried this with PB 4.10 to 4.31 with the same results so any ideas, suggestions, corrections would be great.

I'm sure someone here could port it to PB. :wink:

Re: Oldskool Music Engine - can't get it to work...

Posted: Wed Aug 05, 2009 12:54 pm
by traumatic
This will be most likely due to the wrong calling convention (CDECL/STDCALL).

Did you try CallCFunction()?

(BTW: Using prototypes is much more fun :))

Posted: Wed Aug 05, 2009 2:11 pm
by AndyC
That's exactly what it it was - :D :D

I used the "CallCFunction" syntax and it's now playing beautifully.

This noob thanks you.

btw. Here's the corrected code I had made a few errors with.


Code: Select all

;save as osmreplayer.pbi

#OSM=0 

Declare INIT_OSMEngine()
Declare playOSMEMusicFile(filename.s, trackId.l)
Declare playOSMEMusicMem(pMusic.l, length.l, trackId.l)
Declare stopOSMEMusic()
Declare pauseOSMEMusic()
Declare resumeOSMEMusic()
Declare getOSMEChannelVU(i.l)
Declare setOSMEVolume(vol.l)


Procedure INIT_OSMEngine()
   Protected *DLL.l
  *DLL = OpenLibrary(#OSM,"osmengine.dll")
  If *DLL=0
    MessageRequester("Error", "Can't load OsmEngine", 0)
    End
  Else
    ProcedureReturn *DLL
  EndIf
EndProcedure

Procedure playOSMEMusicFile(filename.s,  trackId.l)
  ProcedureReturn CallCFunction(#OSM,"playOSMEMusicFile", filename, trackId)
EndProcedure

Procedure playOSMEMusicMem(pMusic.l, length.l, trackId.l)
  ProcedureReturn  CallCFunction(#OSM,"playOSMEMusicMem", pMusic, length, trackId)
EndProcedure

Procedure stopOSMEMusic()
  ProcedureReturn  CallCFunction(#OSM,"stopOSMEMusic")
EndProcedure

Procedure pauseOSMEMusic()
  ProcedureReturn  CallcFunction(#OSM,"pauseOSMEMusic")
EndProcedure

Procedure resumeOSMEMusic()
  ProcedureReturn  CallCFunction(#OSM,"resumeOSMEMusic")
EndProcedure

Procedure getOSMEChannelVU(i.l)
  ProcedureReturn  CallCFunction(#OSM,"getOSMEChannelVU",i)
EndProcedure

Procedure setOSMEVolume(vol.l)
  ProcedureReturn  CallCFunction(#OSM,"setOSMEVolume",vol)
EndProcedure

Code: Select all

IncludeFile "osmereplayer.pbi"

INIT_OSMEngine()

Flen=?musend-?music
playOSMEMusicMem(?music,Flen,1)

MessageRequester("O.S.M.E Rulez", "Press Ok")

stopOSMEMusic()
End

music:IncludeBinary "farewell.sndh"
musend:
Now to code some remakes of my old ST demos...