flat assembler
Message board for the users of flat assembler.

Index > Windows > How to play wave sounds from a resource

Author
Thread Post new topic Reply to topic
Lightning Stalker



Joined: 14 Aug 2008
Posts: 14
Lightning Stalker
     There was some discussion a while back about how to play a sound from a resource. If anyone is still interested, I translated a C procedure from MSDN into fasm.

Code:
SND_ASYNC        equ 1h
SND_NODEFAULT    equ 2h
SND_MEMORY       equ 4h

; Play a sound resource
proc    PlayResource, lpName

        push    ecx
        call    @F                   ; push "WAVE",0
        db "WAVE",0                  ; ...
@@:
        push    [lpName]
        push    0
        call    [FindResource]
        test    eax, eax
        jz      .done

        invoke  LoadResource, 0, eax
        test    eax, eax
        jz      .done
        mov     ecx, eax

        invoke  LockResource, eax
        test    eax, eax
        jz      .done

        invoke  sndPlaySound, eax, ( SND_ASYNC + SND_NODEFAULT + SND_MEMORY )

        invoke  FreeResource, ecx

  .done:
        pop     ecx
        ret

endp

...

  import WINMM.DLL,\
         sndPlaySound,'sndPlaySoundA'
    


     You just pass in a resource ID. The resource type must be WAVE. You can change it to something else, but WAVE is the fairly accepted standard. It's been all debugged and tested, so it should work straight away. Feel free to ask any questions.

     It would've been easier if there was some equates and includes for winmm. I had to download MASM32 and grep through the includes which aren't very well organized. So it's not like there's an easy way to translate them to fasm.
Post 26 Oct 2008, 10:27
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 764
Location: Massachusetts, USA
bitshifter
You may want to take a look at PlaySound also.
It takes care of the finding/locking/loading/playing/freeing for you all in one function call.
Post 26 Oct 2008, 12:44
View user's profile Send private message Reply with quote
Lightning Stalker



Joined: 14 Aug 2008
Posts: 14
Lightning Stalker
     Ahh, thank you. The above then becomes-

Code:
SND_ASYNC       equ 1h
SND_RESOURCE    equ 40004h

        invoke  PlaySound, sound, 0, ( SND_RESOURCE + SND_ASYNC )

  import WINMM.DLL,\
         PlaySound,'PlaySoundA',\
    
Post 27 Oct 2008, 06:55
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.