26 May '13 - 01:36 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Reply  |  Print  
Author Topic: bassmod with asm resource  (Read 3281 times)
Ehtyar
Posts: 13


« on: 13 Feb '06 - 06:42 »
Reply with quoteQuote

Hi all, im using masm to compile a chiptune player, with an embedded xm. At the moment im using a really old mod playing lib and would like to upgrade to bassmod.
Unfortunately, i cannot seem to find much help on playing embedded files without the use of the bass_playstreamfile, which i don't believe is available in bassmod. My current code is shown below, if anyone could offer any help, i;d really appreciate it. Thanks Smiley
Note: i can play the file if i use an external file if i simply set pMusic to "file.xm" so it's not a logical error. And i assume most of you would guess this anyway, but for those who don't i have only included the code relevant to my problem.

nMusicSize     DWORD      ?
pMusic         LPVOID     ?
    push esi
    INVOKE FindResource, hInstance, IDM_KEYGEN, RT_RCDATA
    push eax
    INVOKE SizeofResource, hInstance, eax
    mov nMusicSize, eax
    pop eax
    INVOKE LoadResource, hInstance, eax
    INVOKE LockResource, eax
    mov esi, eax
    mov eax, nMusicSize
    add eax, SIZEOF nMusicSize
    INVOKE GlobalAlloc, GPTR, eax
    mov pMusic, eax
    mov ecx, nMusicSize
    mov dword ptr [eax], ecx
    add eax, SIZEOF nMusicSize
    mov edi, eax
    rep movsb
    pop esi
    invoke BASSMOD_Init, -1, 44100, 0
    invoke BASSMOD_MusicFree
    invoke BASSMOD_MusicLoad, 0, ADDR pMusic, 0, 0, BASS_MUSIC_LOOP OR BASS_MUSIC_POSRESET OR BASS_MUSIC_RAMPS
    invoke BASSMOD_MusicPlay
Logged
Sebastian Andersson
Posts: 372


« Reply #1 on: 13 Feb '06 - 12:33 »
Reply with quoteQuote

You have to set "mem" (the first parameter) to TRUE which will let BASS know that the source is a memory location.

    invoke BASSMOD_MusicLoad, TRUE, ADDR pMusic, 0, 0, BASS_MUSIC_LOOP OR BASS_MUSIC_POSRESET OR BASS_MUSIC_RAMPS

Also, why are you calling BASSMOD_MusicFree just after BASSMOD_Init?
« Last Edit: 13 Feb '06 - 12:36 by Sebastian Andersson » Logged
Ehtyar
Posts: 13


« Reply #2 on: 13 Feb '06 - 19:48 »
Reply with quoteQuote

I had tried setting mem to true before and it made no difference. Also, i think the free after init was a typo, i removed it a while back. My code has not changed other than to remove the free, but the music will still not play, even with mem set to true Sad

*edit*

I have also noticed that even if you include bassmod.dll, the program will still require an external copy. Is there any way to compile it into the executable without packing it?
« Last Edit: 13 Feb '06 - 23:00 by Ehtyar » Logged
Sebastian Andersson
Posts: 372


« Reply #3 on: 13 Feb '06 - 23:32 »
Reply with quoteQuote

I had tried setting mem to true before and it made no difference. Also, i think the free after init was a typo, i removed it a while back. My code has not changed other than to remove the free, but the music will still not play, even with mem set to true Sad

*edit*

I have also noticed that even if you include bassmod.dll, the program will still require an external copy. Is there any way to compile it into the executable without packing it?

I've wrapped up an example using MASM for you to have a look at. You don't have to perform that memory allocation/copy stuff, you just use the pointer returned by LockResource.

Regarding including the DLL; I remember seeing some discussion about this - search the forum and I'm sure you'll find something.
Logged
Ehtyar
Posts: 13


« Reply #4 on: 14 Feb '06 - 00:58 »
Reply with quoteQuote

OK, first of all THANK YOU SOOO MUCH FOR THAT. As you can probably tell im no genius with asm, and probably would have taken me years to figure that out, if ever.
I also searched the forums, as you suggested, for info on including the dll internally, and i found two subjects on doing it in C, nither of which had definitive answers (even if they had i know nothing about C) and one with something about including a .pas from the delphi directory  Huh. If you knew the thread where you saw that conversation, i would really appreciate the address, but if not, thanks so much for help above, i really appreciate it Cheesy
Logged
Ehtyar
Posts: 13


« Reply #5 on: 14 Feb '06 - 03:38 »
Reply with quoteQuote

Just realized that i was only searching for bassmod. Searching for bass returned a few more results, but nothing concrete, other than extracting the dll at runtime, which is only shown in C, and not something im am particularly fond of doing. I'd like to be able to use LoadResource on the dll from the resource, as we do with the mod or xm itself. I am wondering if this is possible, as there didnt seem to be any solid answer on this.

*edit*

OK, did some more research, and it seems i have no choice but to extract the dll at runtime. Now im faced with the challenge of finding out how. Sebastian, i realise this is asking a bit much, but if you could maybe give me some reeealy simple code again, dosnt even have to be complete code like the last one, just something for me to work off, because all my attempts have crashed on init. Anyway, if you can you can, and you can't you can't, but thanks for before anyway Smiley
In fact, if i get this working, i will edit the player that comes with bassmod, to include the dll, and post it here. Hopefully that will help some others, if i can manage to get the extraction working.
« Last Edit: 14 Feb '06 - 08:54 by Ehtyar » Logged
Sebastian Andersson
Posts: 372


« Reply #6 on: 14 Feb '06 - 11:06 »
Reply with quoteQuote

I've updated the memplay example with dynamic BASSMOD extraction/loading. It's not your only choice though, you can always use MemoryModule, compile it to a LIB file and link it with MASM.
Logged
Ehtyar
Posts: 13


« Reply #7 on: 18 Feb '06 - 01:51 »
Reply with quoteQuote

So sorry for the delay, had a school assignment i'd left till the last minute :S
Anyway, THANK YOU SOOO MUCH SEBASTIAN your code works beautifully. Took me a while to port it and work out what i didnt need, but ultimately everything is working Smiley
As promised, i will edit the included asm player to include this feature, with all the api. I can't post it now, becuase im late for work, but it should be up by tomorrow. Thanks again sebastian, you are a god Cheesy
Logged
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.18 | SMF © 2013, Simple Machines