Re: Sound in Euphoria Programs for Beginners

new topic     » goto parent     » topic index » view thread      » older message » newer message

Assuming you have a .wav file called "shot.wav" (change that to whatever your .wav is called) this would play that every time you pressed the ENTER key:

include std/machine.e  --for allocate_string 
include std/dll.e  --for open_dll 
include std/get.e   
 
constant SND_ASYNC = #1, NULL = 0 
 
function link_c_func(atom dll, sequence name, sequence args, atom result) 
-- dynamically link a C routine as an Euphoria function 
    integer handle 
 
    handle = define_c_func(dll, name, args, result) 
    if handle = -1 then 
        puts(1,"Couldn't find PlaySound\n") 
    else 
        return handle 
    end if 
end function 
 
atom winmm = open_dll("winmm.dll")  --PlaySound is located in this dll 
    if winmm = 0 then 
        puts(1,"Couldn't open winmm.dll\n") 
    end if 
 
atom PlaySound = link_c_func(winmm, "PlaySound", {C_POINTER,C_INT,C_DOUBLE},C_INT) 
 
atom Shot = allocate_string("shot.wav") 
 
while 1 do 
	if getc(0) then 
		c_func(PlaySound,{Shot,NULL,SND_ASYNC}) 
	end if 
end while 

Not being a professional (or even semi-professional) programmer, this probably isn't best practice, but it'll get the job done.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu